> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bunny.build/llms.txt
> Use this file to discover all available pages before exploring further.

# GET /validate-cpf-cnpj

> Validate Brazilian CPF and CNPJ tax IDs using the official check-digit algorithm. Returns validity, document type, and formatted number.

## Endpoint

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

## Authentication

| Header      | Required | Value                    |
| ----------- | -------- | ------------------------ |
| `X-API-Key` | Yes      | Your 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

| Parameter  | Type   | Required | Description                                                                                |
| ---------- | ------ | -------- | ------------------------------------------------------------------------------------------ |
| `document` | string | Yes      | CPF (e.g. `529.982.247-25`) or CNPJ (e.g. `11.222.333/0001-81`). Formatted or digits only. |

## Response

### 200 OK

| Field       | Type    | Description                                              |
| ----------- | ------- | -------------------------------------------------------- |
| `document`  | string  | The document digits with non-numeric characters stripped |
| `type`      | string  | `cpf` or `cnpj`                                          |
| `valid`     | boolean | `true` if the document passes checksum validation        |
| `formatted` | string  | The document formatted with standard punctuation         |

**Example (CPF)**

```json theme={null}
{
  "document": "52998224725",
  "type": "cpf",
  "valid": true,
  "formatted": "529.982.247-25"
}
```

**Example (CNPJ)**

```json theme={null}
{
  "document": "11222333000181",
  "type": "cnpj",
  "valid": true,
  "formatted": "11.222.333/0001-81"
}
```

### 401 Unauthorized

```json theme={null}
{
  "detail": "Missing API key. Include X-API-Key header."
}
```

### 402 Payment Required

```json theme={null}
{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}
```

### 422 Unprocessable Entity

Unrecognized document format.

```json theme={null}
{
  "detail": "Could not determine document type (CPF or CNPJ)"
}
```

### 429 Too Many Requests

```json theme={null}
{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}
```

## cURL example

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