# Errors

> The error format, HTTP status codes and every error code with what to do about it.

Every error has the same JSON body:

```json
{
  "error_id": "err_262f371ad0",
  "code": "invalid_request",
  "message": "document_id: Field required"
}
```

- Branch on `code`; it is stable. `message` is for people and may change.
- Include `error_id` when you contact support.
- `429` responses have a `Retry-After` header in seconds.

## What to retry

| Status | Retry? |
|---|---|
| `400`, `401`, `403`, `404`, `409`, `413`, `415`, `422` | No. Fix the request first. |
| `402` | After adding credit. |
| `429` | Yes, after `Retry-After` seconds. |
| `500`, `502`, `503`, `504` | Yes, with exponential backoff. Use an `Idempotency-Key` when creating extractions. |

## Error codes

### Authentication and access

| Code | Status | Meaning |
|---|---|---|
| `unauthorized` | 401 | The key is missing, wrong or revoked. Send `Authorization: Bearer <key>`. |
| `insufficient_scope` | 403 | The key lacks the scope this call needs. |
| `mode_mismatch` | 403 | A test key asked for live data or the other way around. |
| `insufficient_credits` | 402 | The balance is used up; live extractions and suggestions are blocked. |

### Requests

| Code | Status | Meaning |
|---|---|---|
| `invalid_request` | 400, 422 | A parameter or body field is missing or invalid; `message` names it. |
| `invalid_metadata` | 400 | `metadata` breaks a limit (20 keys, 40-character keys, 500-character string values) or `test_outcome` is unknown. |
| `invalid_cursor` | 400 | The `cursor` is not one returned by this list. |
| `idempotency_conflict` | 409 | The `Idempotency-Key` was used for a different request. |
| `not_found` | 404 | No such endpoint. |
| `method_not_allowed` | 405 | The endpoint does not support this HTTP method. |

### Limits

| Code | Status | Meaning |
|---|---|---|
| `rate_limited` | 429 | Too many requests per minute for this key. Wait `Retry-After` seconds. |
| `concurrency_limit` | 429 | Too many extractions are open at once. Wait for some to finish. |
| `key_limit_reached` | 409 | The account has the maximum number of API keys. Revoke one first. |
| `webhook_limit_reached` | 409 | The account has the maximum number of webhook endpoints. |

### Documents

| Code | Status | Meaning |
|---|---|---|
| `upload_too_large` | 413 | The file is larger than the upload limit. |
| `unsupported_media_type` | 415 | The file type is not supported, or its content does not match its extension. See [supported formats](/docs/limits.md#file-formats). |
| `malformed_document` | 422 | The file could not be read. |
| `encrypted_document` | 422 | The file is password protected. |
| `document_limit_exceeded` | 422 | The document has too many pages, sheets or cells. |
| `document_not_found` | 404 | No such document in this mode, or it was deleted. |
| `document_in_use` | 409 | A run on the document is still in progress; delete it when the run ends. |

### Schemas

| Code | Status | Meaning |
|---|---|---|
| `invalid_schema` | 422 | The JSON Schema breaks a [rule](/docs/schemas.md#rules); `message` names it. |
| `schema_not_found` | 404 | No such schema. |
| `schema_version_not_found` | 404 | The schema has no such version. |
| `schema_conflict` | 409 | `base_version` is older than the latest version. Reload and try again. |
| `template_not_found` | 404 | No such template. |

### Extractions

| Code | Status | Meaning |
|---|---|---|
| `job_not_found` | 404 | No such extraction in this mode. |
| `job_not_completed` | 409 | The job has no result: it is still running (wait), or it failed or was cancelled (see `last_error`). |
| `result_requires_pagination` | 413 | The result is very large; use `/result/manifest`, `/result/collections` or `/result/export`. |
| `not_available_in_test_mode` | 404 | This route exists only for live jobs. |
| `test_mode_unsupported` | 400 | The feature (schema suggestions) needs a live key. |

### Webhooks

| Code | Status | Meaning |
|---|---|---|
| `invalid_webhook_url` | 400 | Not an absolute URL, or a live URL that is not public `https`. |
| `invalid_webhook_events` | 400 | An unknown event type. |
| `webhook_not_found` | 404 | No such endpoint. |
| `webhook_delivery_not_found` | 404 | No such delivery. |
| `webhook_disabled` | 409 | Enable the endpoint before resending. |

## Errors inside jobs

A job that fails after it started has `status: "failed"` and a readable `last_error`
instead of an HTTP error. Common causes are a model provider outage (retry later),
`job_time_limit_exceeded` or model input limits for very large documents (split the
document or narrow the schema).
