ViaCep API

Beginner's Pick Geocoding / No Auth Required Beginner HTTPS
Free to Use
67 C
Measured Score 0 50 100 Speed 8/30 Consistency 20/20 Security 20/20 Browser access 15/15 Transparency 4/15 TESTED 2026-09-21

Overview

ViaCep is a free Brazilian zip code (CEP) API that returns address data including street, neighborhood, city, and state for any valid Brazilian postal code. No authentication is required, making it ideal for beginners building forms or address validation for Brazil. Responses are available in JSON or XML format.

Beginner Tip

Just replace the CEP in the URL with any valid 8-digit Brazilian zip code. Use the JSON format endpoint (/json/) for easiest parsing in modern apps.

Measurement Record

What actually happened when we called this API from our own infrastructure. Every value below was recorded by the request, not copied from the provider's documentation.

Request
GET https://viacep.com.br/ws/01310-100/json/
Result
HTTP 200 · application/json · 313 bytes
Response time
410 ms (median of 3) · fastest 398 ms
Transport
TLSv1.3 · TLS_AES_256_GCM_SHA384 · certificate issued by Sectigo Limited
Browser CORS
Allowed — Access-Control-Allow-Origin: *
Served by
nginx/1.22.0
Answered
6 of 8 weekly checks (75%, since 2026-07-31)
Recorded
2026-09-21

Fields Returned

Top-level fields present in the response we captured, with the type and value we actually received.

Field Type Value received
cep string 01310-100
logradouro string Avenida Paulista
complemento string de 612 a 1510 - lado par
unidade string
bairro string Bela Vista
localidade string São Paulo
uf string SP
estado string São Paulo
regiao string Sudeste
ibge string 3550308
gia string 1004
ddd string 11
siafi string 7107

Captured Response

Captured from a real request to https://viacep.com.br/ws/01310-100/json/ on 2026-09-21. Long arrays and nested objects are truncated to keep the shape readable.

JSON Response · Captured
{
  "cep": "01310-100",
  "logradouro": "Avenida Paulista",
  "complemento": "de 612 a 1510 - lado par",
  "unidade": "",
  "bairro": "Bela Vista",
  "localidade": "São Paulo",
  "uf": "SP",
  "estado": "São Paulo",
  "regiao": "Sudeste",
  "ibge": "3550308",
  "gia": "1004",
  "ddd": "11",
  "siafi": "7107"
}

Field Reference

cep The Brazilian postal code in XXXXX-XXX format.
logradouro Street name associated with the postal code.
bairro Neighborhood or district name.
localidade City name for the postal code.
uf Two-letter Brazilian state abbreviation, e.g. SP for São Paulo.
ibge IBGE code, a numeric identifier for the municipality.

Implementation Example

Calls a real endpoint of this API. Replace any placeholder credentials with your own key.

Request
const url = "https://viacep.com.br/ws/01310-100/json/";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

How This API Fails

We deliberately sent this API a broken request and recorded exactly what came back on 2026-09-21. Knowing the shape of an error before you hit it makes error handling much easier to write.

HTTP 400 Requesting a path that does not exist text/html

Returned an HTML error page rather than JSON — worth knowing if your client assumes every response can be parsed as JSON.

Common Errors & Troubleshooting

Generated guidance based on this API's documentation, not observed by us. Treat it as a starting point and check against the provider's own error reference.

400 Bad Request The CEP contains non-numeric characters or is not 8 digits long.
✓ Strip dashes and spaces from the CEP before passing it to the URL. Only digits, optionally with a hyphen (XXXXX-XXX), are accepted.
erro: true in response The CEP number is syntactically valid but does not exist in the database.
✓ Check the CEP on a postal directory and confirm it is a real Brazilian zip code.
Empty or timeout response Network issue or the API is temporarily unavailable.
✓ ViaCep is free and has no SLA; implement retry logic with exponential backoff for production use.

Measured Score Breakdown

Live HTTP request to the API endpoint

Speed 8/30
Consistency 20/20
Security 20/20
Browser access 15/15
Transparency 4/15
Endpoint Response Time 410ms

Fully tested on Sep 21, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS UNKNOWN
Category Geocoding
Difficulty Beginner
Endpoint last called: 2026-09-21

Related Tags

Similar APIs

View All →