# API key errors

Preview: opening soon. Error names here describe the planned key gate; route errors appear in the [reference](/docs/api).

API key refusals are JSON (`application/json`) with an HTTP status and a machine readable `code`. Read `code`; `message` is for people and its words may change. A refusal from the key gate looks like this:

```json
{
  "error": "ApiKeyRefused",
  "code": "invalid_key",
  "message": "This API key is not valid. It may be revoked or expired",
  "context": {},
  "path": "/v1/shops/00000000-0000-4000-8000-000000000001/bookings",
  "method": "GET"
}
```

A refusal from the route itself, such as `scope_missing` or `read_only_key`, has the same fields with another `error` name. `scope_missing` names the area the key lacks in `context.area`. A route that is not open answers 404 with `{"detail": "Not Found"}`, exactly like an address that does not exist. Every answer to a key carries `Cache-Control: no-store`.

| Status | Code                        | What to do                                                                                                   |
| ------ | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| 400    | `key_misplaced`             | Send one key only in the bearer header. Remove it from the URL and body.                                     |
| 401    | `invalid_key`               | Check the secret and whether it has expired or been revoked.                                                 |
| 403    | `scope_missing`             | Check the route's area and the person's current access. A key cannot widen either.                           |
| 403    | `read_only_key`             | Remove the write. Phase one keys can only read.                                                              |
| 403    | `ip_not_allowed`            | Call from a saved IP range or update the allowlist in Settings.                                              |
| 403    | `key_from_browser`          | Move the call to a server without a browser `Origin` header.                                                 |
| 403    | `api_keys_off`              | The shop's owner switched API keys off. Keys work again when it is switched back on.                         |
| 404    | Route or record unavailable | Check the generated reference, shop ID, and record ID. Closed routes also answer 404.                        |
| 413    | `body_too_large`            | Send a smaller request body.                                                                                 |
| 429    | `too_many_requests`         | Too many calls in a minute, or too many invalid keys from one address. Wait `Retry-After` seconds.           |
| 429    | `daily_quota`               | The key or the shop reached its daily limit. It resets at midnight, shop time; honor `Retry-After`.          |
| 429    | `customer_budget`           | The key read its daily number of customer records. Honor `Retry-After`; see [limits](/docs/api-keys/limits). |

Do not log the bearer value or the full request URL while debugging. The status and `code` are enough for a support report.
