# POST /v1/geocode

> Resolve a US street address to a coordinate, and say how far to trust it.

Source: https://docs.invariant-ai.com/api/geocode

`POST https://api.invariant-ai.com/v1/geocode`

Geocode turns a one-line US street address into a latitude and longitude. The answer says how the point was placed, so you know whether it sits on the property or only on the right street.

```bash
curl -s https://api.invariant-ai.com/v1/geocode \
  -H "X-API-Key: $INVARIANT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"address": "1600 Pennsylvania Ave NW, Washington, DC 20500"}'
```

```json
{
  "lat": 38.897675,
  "lng": -77.036546,
  "accuracy": 1.0,
  "accuracy_type": "rooftop",
  "match_type": "address_point",
  "normalized_address": "1600 Pennsylvania Ave NW, Washington, DC 20500",
  "provider": "address_point",
  "source": "National Address Database"
}
```

Pass `lat` and `lng` to [`POST /v1/fetch`](https://docs.invariant-ai.com/api/fetch) for data at the location.
To check a parcel number or county acreage, follow the [parcel lookup by address](https://docs.invariant-ai.com/lookup-parcel-by-address). For a FEMA map check, see [flood zone lookup by address](https://docs.invariant-ai.com/check-flood-zone-by-address).

## Request

| Field | Type |  |
| --- | --- | --- |
| `address` | string, 1 to 256 characters | House number, street, city, state and ZIP on one line. A ZIP, or a city and state, is required. |

## Response

| Field | Meaning |
| --- | --- |
| `lat`, `lng` | WGS84, six decimals. |
| `accuracy_type` | **Read this before trusting the point.** `rooftop`: an authoritative address point for this address, placed by the county or state that maintains it. `range_interpolation`: estimated along the street from its address range; in rural areas it can be hundreds of metres to about 3 km off, enough to land on a neighbouring property. |
| `accuracy` | 0 to 1. `1.0` is the exact street and ZIP at an address point. `0.9`: the same street with its words in another order, or the address point carries a different ZIP. `0.8`: a directional was corrected (you sent `W`, the address is `E`). `0.6`: a street-range estimate. |
| `match_type` | `address_point` (one point), `building_centroid` (the centre of several unit points sharing the address), or `street_range`. |
| `normalized_address` | The address as matched, USPS style. Compare it with what you sent: a corrected directional or ZIP shows here. |
| `provider` | `address_point` or `census`. |
| `source` | The dataset behind the coordinate, for example `National Address Database` or `City of New York`. |

## How an address is placed

1. **Street.** The US Census Geocoder matches the address to a street segment and gives a first estimate along it.
2. **Address point.** We look for the published address point with the same house number on the same street within 3 km of that estimate. Address points come from the US DOT National Address Database and county and city open data, read from [Overture Maps](https://docs.overturemaps.org/guides/addresses/). A match comes back as `rooftop`.
3. **No address point.** The Census estimate comes back as `range_interpolation`.
4. **Census has no match** (a private road, a new subdivision, a street missing from Census ranges): we search the address points inside the ZIP, or inside the city when there is no ZIP. A single match comes back as `rooftop`. If the same address appears in two places, we refuse rather than guess.

## Refusals

A vague address is refused instead of being answered with the centre of a town or ZIP, because a centre point describes arbitrary land near the middle of that area.

| HTTP | `error` | When |
| --- | --- | --- |
| 404 | `address_too_coarse` | No house number (`Muncie, IN`, `Main St, Springfield, IL`, a ZIP alone, house number `0`), no ZIP and no city and state (`100 Main Street`), or the ZIP or city exists but holds no such property. |
| 404 | `address_not_found` | Neither the street nor the place could be found. |
| 422 | `address_form_unsupported` | A PO box. It is a mail destination, not a place. |

## Errors

| HTTP | `error` | Retry | When |
| --- | --- | --- | --- |
| 400 | `invalid_request` | no | Body missing `address`, empty, over 256 characters, or with unknown keys. |
| 401 | `auth_missing`, `auth_invalid` | no | See [Authentication](https://docs.invariant-ai.com/authentication). |
| 429 | `geocode_busy` | yes | Too many geocodes in flight. Honour `Retry-After`. |
| 502 | `geocode_upstream_error` | yes | The street geocoder failed and the address could not be placed another way. Honour `Retry-After`. |
| 504 | `geocode_timeout` | yes | No answer within 12 s. Honour `Retry-After`. |

Error bodies carry `detail.retryable` (`true` or `false`) next to `detail.error`.

## Notes

- Answers are cached for 30 days. The same address with different spacing or capitals is the same request.
- Geocode is free and counts toward your key's request limits like any other call.
- Coverage is the 50 states and DC. Address points are densest where counties publish them; elsewhere you get the Census street estimate, labelled as such.
