CPFHub.io
Start for free

Node.js via HTTP

In Node.js 18+ you don't need a package: native fetch makes the request in a few lines, in JavaScript or TypeScript. A CPF is Brazil's individual taxpayer ID.

ℹ

The official Node.js SDK is in the works. Until then, use the HTTP call below.

Lookup

TypeScript
const cpf = '12345678909'

const res = await fetch(`https://api.cpfhub.io/cpf/${cpf}`, {
  headers: { 'x-api-key': process.env.CPFHUB_API_KEY! },
  signal: AbortSignal.timeout(10_000),
})
const body = await res.json()

if (res.ok) {
  console.log(body.data.name)      // "Fulano de Tal"
  console.log(body.data.birthDate) // "15/06/1990"
} else if (res.status === 404) {
  // CPF not found in the database (does not use a credit)
} else {
  // error comes as text ("...") or as an object ({ message: "..." })
  const message = typeof body.error === 'string' ? body.error : body.error?.message
  throw new Error(`Error ${res.status}: ${message}`)
}

Success response (200):

JSON
{
  "success": true,
  "data": {
    "cpf": "12345678909",
    "name": "Fulano de Tal",
    "nameUpper": "FULANO DE TAL",
    "gender": "M",
    "birthDate": "15/06/1990",
    "day": 15,
    "month": 6,
    "year": 1990
  }
}

Errors

StatusMeaning
400CPF without 11 digits
401Missing or invalid API key
403Credits exhausted or inactive account
404CPF not found in the database (does not use a credit)
422Incorrect check digit
429Requests-per-minute limit: wait the number of seconds in the Retry-After header

See the full list in Error Codes.

Next steps