Skip to main content

Endpoint

GET https://api.bunny.build/api/v1/validate-cpf-cnpj?document=529.982.247-25

Authentication

HeaderRequiredValue
X-API-KeyYesYour API key (bun_...)

Overview

Validate Brazilian tax IDs, CPF (individuals) and CNPJ (companies), in one endpoint. Bunny runs the official check-digit algorithm and returns whether the document is mathematically valid, the document type, and the formatted number.

Use cases

  • Validate CPF and CNPJ fields on registration and checkout forms
  • Prevent typos and transposed digits from entering your database
  • KYC and identity verification flows
  • Enforce correct formatting before sending to payment processors

Details

Accepts formatted (529.982.247-25) or raw (52998224725) input. Both work. The validation is algorithmic (check-digit), not a lookup against a government database.

Query parameters

ParameterTypeRequiredDescription
documentstringYesCPF (e.g. 529.982.247-25) or CNPJ (e.g. 11.222.333/0001-81). Formatted or digits only.

Response

200 OK

FieldTypeDescription
documentstringThe document digits with non-numeric characters stripped
typestringcpf or cnpj
validbooleantrue if the document passes checksum validation
formattedstringThe document formatted with standard punctuation
Example (CPF)
{
  "document": "52998224725",
  "type": "cpf",
  "valid": true,
  "formatted": "529.982.247-25"
}
Example (CNPJ)
{
  "document": "11222333000181",
  "type": "cnpj",
  "valid": true,
  "formatted": "11.222.333/0001-81"
}

401 Unauthorized

{
  "detail": "Missing API key. Include X-API-Key header."
}

402 Payment Required

{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}

422 Unprocessable Entity

Unrecognized document format.
{
  "detail": "Could not determine document type (CPF or CNPJ)"
}

429 Too Many Requests

{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}

cURL example

curl "https://api.bunny.build/api/v1/validate-cpf-cnpj?document=529.982.247-25" \
  -H "X-API-Key: bun_your_api_key"