# CEP lookup and search in the API

> Look up a CEP's address via the API, even without a key, search CEPs by address, prefix, state or IBGE code and find companies by CEP or CEP range.

> **Tip:** Concepts on this page: [CEPs, streets and IBGE codes](https://cnpja.com/en-us/docs/data/postal-codes).

The API returns the address, type and status of each [CEP](https://cnpja.com/en-us/docs/glossary#cep) as registered in the Correios National Address Directory ([DNE](https://cnpja.com/en-us/docs/glossary#dne)), in [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d), when the CEP is known, and in [Search CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes), when only part of the address is known. Lookup CEP also accepts [public access](https://cnpja.com/en-us/docs/api/public-access), without an API key. What a CEP is, its types and its status are in [CEPs, streets and IBGE codes](https://cnpja.com/en-us/docs/data/postal-codes).

## Request

| Operation | Use | API key |
|---|---|---|
| [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d) | Address, type and status of a known CEP | Optional |
| [Search CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes) | CEPs found by address, prefix, type, status, state or municipality, in pages | Required |

### Lookup CEP

Send the CEP's 8 digits in the path, with no hyphen and with leading zeros:

```http
GET /v2/postal-codes/01452922 HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

| Parameter | Location | Format |
|---|---|---|
| `code` | Path | CEP with exactly 8 characters, such as `01452922` |

- The operation has no query parameters. With a key, unrecognized names in the URL are ignored; without a key, any parameter makes the request return `401` `API_KEY_MISSING`, as explained in [Public access](https://cnpja.com/en-us/docs/api/public-access).
- The CEP must be exactly 8 digits. Any other value, such as a CEP with a hyphen, without its leading zeros, with punctuation or with letters, is rejected with `400` and not charged: strip the punctuation and restore the leading zeros before sending.

### Search CEP

Send the filters as query parameters. All of them are optional, and each filter added narrows the results:

```http
GET /v2/postal-codes?search=faria%20lima&state.in=SP&status.code.in=ACTIVE&limit=20 HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

| Parameter | Function | Format |
|---|---|---|
| `search` | Free text looked up in the CEP, name, street, number, district, city and state | At least 1 character |
| `type.code.in` | CEP types to include | `LOCALITY`, `STREET`, `LARGE_RECIPIENT`, `OPERATIONAL_UNIT`, `COMMUNITY_PO_BOX` |
| `status.code.in` | Statuses to include | `ACTIVE`, `DEACTIVATED` |
| `state.in` | States to include | Abbreviations, such as `SP,RJ` |
| `municipality.in` | Municipalities to include | 7-digit [IBGE codes](https://cnpja.com/en-us/docs/glossary#código-ibge--ibge-code), such as `3550308` |
| `sort` | Field used to sort records | `relevance` (default), `code`, `state`, `city`, `municipality` |
| `order` | Sort direction | `ASC`, `DESC`. When omitted, `DESC` for `relevance` and `ASC` for the others |
| `limit` | Records per page | From `1` to `1000`, default `10` |
| `cursor` | Reading the next page | The `nextCursor` of the previous response, with no other parameter |

- Multi-value filters accept comma-separated values or the repeated parameter. Different filters are combined with AND.
- `search` only returns records containing all the given words, in any order, and follows the [text matching rules](https://cnpja.com/en-us/docs/data/search-matching#text-matching) of the CNPJ search. It also matches the abbreviated forms of names registered in the DNE.
- `search` finds CEPs by their first digits, from 3 digits on: `search=01452` returns the CEPs starting with `01452`.
- The extra details (`details`) are not part of the text search.
- With the default `sort=relevance`, records come in ascending CEP order, and with a multi-word `search`, records containing the words as an exact phrase come first, each group following CEP order. The other values sort by the response field of the same name, and ties follow ascending CEP.
- `sort=city` compares names by character code, without ignoring case or accents: uppercase letters come before lowercase ones, and accented letters come after both, so `Águas de Lindóia` comes after `Zortéa`.

The full rules for filters, text, sorting and paging are in [CNPJ search](https://cnpja.com/en-us/docs/api/cnpj-search) and in [Search filters](https://cnpja.com/en-us/docs/api/reference#description/search-filters), [Sorting](https://cnpja.com/en-us/docs/api/reference#description/sorting) and [Pagination](https://cnpja.com/en-us/docs/api/reference#description/pagination), in the Reference.

## Response fields

Lookup CEP returns one record, trimmed below:

```json
{
  "updatedAt": "2026-01-27T03:00:00.000Z",
  "code": "01452922",
  "type": { "code": "LARGE_RECIPIENT", "label": "Grande Usuário" },
  "status": { "code": "ACTIVE", "label": "Ativo" },
  "name": "Edifício Barão de Iguatemi",
  "street": "Avenida Brigadeiro Faria Lima",
  "number": "2369",
  "details": null,
  "district": "Jardim Paulistano",
  "city": "São Paulo",
  "state": "SP",
  "municipality": "3550308"
}
```

| Field | Content |
|---|---|
| `updatedAt` | Last update of the record from Correios data |
| `code` | CEP, with 8 digits |
| `type` | CEP type, with `code` and `label`, described in [Codes and values](#codes-and-values) |
| `status` | Status of the CEP in the DNE, with `code` and `label` |
| `name` | Name of the large recipient, operational unit or community PO box, or `null` for the other types |
| `street` | Name of the [street](https://cnpja.com/en-us/docs/glossary#logradouro--street), or `null` for `LOCALITY` |
| `number` | Number on the street, when available, or `null` |
| `details` | Extra details of the street, which can delimit a stretch, as in `até 610 - lado par`, or `null` |
| `district` | Name of the neighborhood or district, or `null` |
| `city` | Name of the municipality. For a district's CEP, the name of the municipality the district belongs to |
| `state` | [State](https://cnpja.com/en-us/docs/glossary#uf) abbreviation |
| `municipality` | Municipality [IBGE code](https://cnpja.com/en-us/docs/data/postal-codes#ibge-code), with 7 digits |

`municipality` holds the same code as `address.municipality` in the addresses of establishments and of state and SUFRAMA registrations, and municipality filters take this code, not the name: `municipality.in` in Search CEP, and `address.municipality.in` or `address.municipality.nin` in Search CNPJ. To get the code from the name, search for the municipality's name in Search CEP with `state.in`, check `city` in the record returned and read `municipality`.

Search CEP returns a page, with each item of `records` in the same format as Lookup CEP. Illustrative excerpt:

```json
{
  "total": 250,
  "limit": 20,
  "nextCursor": "9ed11ce29dc14f9c78304c1a403e9f85",
  "records": [
    {
      "code": "01452922",
      "type": { "code": "LARGE_RECIPIENT", "label": "Grande Usuário" },
      "status": { "code": "ACTIVE", "label": "Ativo" },
      "name": "Edifício Barão de Iguatemi",
      "street": "Avenida Brigadeiro Faria Lima",
      "city": "São Paulo",
      "state": "SP",
      "municipality": "3550308"
    }
  ]
}
```

The page carries the records in `records`, the number of records found in `total`, the page size in `limit` and the cursor of the next page in `nextCursor`, which is `null` on the last page. The page format and the cursor rules are in [Response format](https://cnpja.com/en-us/docs/api/responses).

## Finding companies by CEP

In [Search CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments), the CEP and the municipality of the address work as filters:

| Filter | Function |
|---|---|
| `address.postalCode.in` | One or more CEPs |
| `address.postalCode.gte` and `address.postalCode.lte` | A range of CEPs, such as `01000000` to `05999999`, with both bounds included |
| `address.municipality.in` and `address.municipality.nin` | Municipalities to include or exclude, by IBGE code |
| `address.state.in` | States to include |

```http
GET /v2/establishments?address.postalCode.in=01452922&status.code.in=ACTIVE HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

- The search compares the CEP registered in the CNPJ registry at the Receita Federal, not the DNE. To cover a whole area, use a CEP range or the municipality, as explained in [Correios CEP and Receita CEP](https://cnpja.com/en-us/docs/data/postal-codes#divergence).
- The reverse also works: the `address.postalCode` of an establishment, or of a CPF's registrations, can be sent to Lookup CEP.
- The other filters, the result count and paging are in [CNPJ search](https://cnpja.com/en-us/docs/api/cnpj-search).
- Coordinates, map and street view of an establishment's address are in [Location and maps](https://cnpja.com/en-us/docs/api/location).

## Codes and values

Base your logic on `code`. The `label` is for display only and changes with the language, as explained in [Response format](https://cnpja.com/en-us/docs/api/responses).

### CEP types

| `type.code` | `label` in pt-BR and en-US | What it covers | Filled fields |
|---|---|---|---|
| `LOCALITY` | Localidade, Locality | A whole locality. When active, it is the general CEP of a locality without street-level CEPs | Only `city`, `state` and `municipality`; the other address fields are null |
| `STREET` | Logradouro, Street | A street or a stretch of it, which `details` can delimit | `street` and, when available, `district` and `details`; `name` and `number` are null |
| `LARGE_RECIPIENT` | Grande Usuário, Large Recipient | A single recipient, such as a building or a company | `name`, `street` and, when available, `number` and `district`; `details` describes the street stretch, not the recipient |
| `OPERATIONAL_UNIT` | Unidade Operacional, Operational Unit | A Correios unit | Same as `LARGE_RECIPIENT` |
| `COMMUNITY_PO_BOX` | Caixa Postal Comunitária, Community PO Box | A PO box for community use | `name`, `street` and, when available, `number` and `district`; `details` is null |

### Statuses

| `status.code` | `label` in pt-BR and en-US | Meaning |
|---|---|---|
| `ACTIVE` | Ativo, Active | CEP in use in the DNE |
| `DEACTIVATED` | Desativado, Deactivated | CEP ending in `000` with the same 5-digit prefix as street-level CEPs, which matches no street or recipient |

Deactivated CEPs are always of type `LOCALITY` and carry only `city`, `state` and `municipality`. Lookup CEP also returns deactivated CEPs. In Search CEP, send `status.code.in=ACTIVE` to get only the CEPs in use.

## Sources and updates

- Lookup CEP and Search CEP serve cached data only: they make no live queries and do not accept `maxAge`.
- `updatedAt` gives when the record was last updated from the Correios DNE.
- A new CEP can only be found after the DNE edition that includes it, as explained in [DNE updates](https://cnpja.com/en-us/docs/data/postal-codes#dne-updates).

## Billing

Lookup CEP and Search CEP consume cached queries only, including on `404` responses and on searches with no results, and public access is not charged. The consumption of each operation is in the Metering Rules, under [Consumption in the API](https://cnpja.com/en-us/legal/metering#api).

## Frequent errors

| Status | Code | Cause | Action |
|---|---|---|---|
| `400` | `REQUEST_VALIDATION_FAILED` | CEP without exactly 8 digits, filter, `sort` or `order` with an invalid value, unknown parameter name in Search CEP or `cursor` sent with other parameters | Fix what `errors` points to and send the CEP with 8 digits |
| `400` | `PAGE_CURSOR_INVALID` | The `cursor` has expired or is unknown | Restart the search from the first page |
| `401` | `API_KEY_MISSING` | Search CEP without a key, or Lookup CEP without a key and with query parameters | Send an API key or remove the parameters from the public request |
| `402` | `CACHED_QUERY_QUOTA_EXCEEDED`, `LIVE_QUERY_QUOTA_EXCEEDED` or `OVERAGE_BUDGET_EXCEEDED` | The organization's quota or overage budget is used up. What each code means is in [Error codes](https://cnpja.com/en-us/docs/api/limits-and-errors#error-codes) | Follow one of the ways out in [Quota used up](https://cnpja.com/en-us/docs/billing/quota-exhausted#ways-out) |
| `404` | `POSTAL_CODE_NOT_FOUND` | No record has the CEP | Check the digits and do not retry right away, since with a key the `404` is charged. To find CEPs with the same prefix, send the first digits as `search` to Search CEP |
| `429` | `RATE_LIMIT_EXCEEDED` or `CONCURRENCY_LIMIT_EXCEEDED` | Requests above the usage limits, the plan's with a key and the IP address's under public access | Reduce the pace or the parallelism, or use an API key |

A search with no matches returns `200` with empty `records`, never `404`. The other errors are in [Limits and errors](https://cnpja.com/en-us/docs/api/limits-and-errors).

## Use cases

- **Address autofill:** in a sign-up form, look up the CEP typed in and fill in street, district, city and state. At low volume, the lookup can use public access.
- **CEP finder:** offer a search box backed by Search CEP, `search` and a small `limit` for users who do not know their CEP. A small `limit` keeps consumption low, as set out in the [Metering Rules](https://cnpja.com/en-us/legal/metering#api).
- **Support for record checks:** check that the CEP provided exists and is active (`ACTIVE`) and compare the address provided with the DNE address.
- **Municipality normalization:** store `municipality` with the address to identify the municipality by its IBGE code in reports and tax documents.
- **CEPs by municipality:** go through the CEPs of a state grouped by municipality, ordered by IBGE code and then by CEP, with `state.in` and `sort=municipality`.
- **Companies by area:** search for companies by CEP, CEP range or municipality in Search CNPJ.
- **Recipients with their own CEP:** find the buildings and companies with an exclusive CEP in an area with `type.code.in=LARGE_RECIPIENT` and `municipality.in`.

## In the app

In the **CEP** app, **Search postal codes** uses the same filters as Search CEP, and each CEP's record shows the Lookup CEP data with the establishments registered at the CEP. See [Search CEPs by address](https://cnpja.com/en-us/docs/postal-codes/search) and [CEP record and companies](https://cnpja.com/en-us/docs/postal-codes/record).

## Notes

- Store the CEP as text, never as a number, to keep the leading zeros, as explained in [Identifiers as text](https://cnpja.com/en-us/docs/data/format#identifiers).
- Lookup CEP does not return coordinates. Coordinates exist only for an establishment's address, as described in [Location and maps](https://cnpja.com/en-us/docs/api/location).
- Search CEP filters accept only the `in` operator. Street, district and city are found through `search`.
- All parameters are in [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d) and [Search CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes), in the Reference.
