# Errors

> Request errors use HTTP status codes and one JSON shape. Source failures are not errors.

Source: https://docs.invariant-ai.com/errors

## Error shape

```json
{
  "detail": {
    "error": "coord_out_of_bounds",
    "message": "(51.5, -0.12) is outside the US envelope: lat [18.0, 72.0], lng [-180.0, -65.0]."
  }
}
```

`detail.error` is a stable code to branch on; `detail.message` is for people.

A malformed body returns `invalid_request` with one entry in `detail.problems` per problem. `loc` is the path to the bad value:

```json
{
  "detail": {
    "error": "invalid_request",
    "message": "Request body is not valid.",
    "problems": [
      {
        "loc": [
          "body",
          "lat"
        ],
        "msg": "Input should be a valid number, unable to parse string as a number"
      },
      {
        "loc": [
          "body",
          "fields"
        ],
        "msg": "Field required"
      }
    ]
  }
}
```

## Codes

| HTTP | `error` | When |
| --- | --- | --- |
| 400 | `invalid_request` | Body is not valid JSON for the endpoint: missing `fields`, wrong types, unknown keys. `detail.problems` lists each problem. |
| 400 | `coord_out_of_bounds` | Coordinate outside lat 18 to 72, lng -180 to -65. |
| 400 | `fields_unknown` | A field name is not in [`GET /v1/meta/fields`](https://docs.invariant-ai.com/api/meta-fields). `detail.unknown` lists them. |
| 400 | `auth_conflict` | Two different keys on one request. |
| 401 | `auth_missing` | No API key. |
| 401 | `auth_invalid` | Key not recognised or revoked. |
| 409 | `too_many_keys` | The email already has 5 active keys. |
| 429 | `rate_limited` | Too many keys created from one network. Honour `Retry-After`. |
| 503 | `auth_unavailable` | Key service briefly unavailable. Retry. |

## Source failures are not errors

If a source is slow or down, the request still returns `200`. The affected field has `status: "failed"` and appears in `partial_failures`. See [Responses](https://docs.invariant-ai.com/responses).

## Request IDs

Every response has an `X-Request-ID` header. Send your own to correlate with your logs; include it when you contact us.
