# Errors

The error format, every error code with its HTTP status, and what your code should do for each: retry, fix the request or stop.

Errors use standard HTTP status codes and one JSON shape:

```json
{
  "error": {
    "code": "invalid_request",
    "message": "Input should be less than or equal to 90",
    "field": "latitude",
    "request_id": "req_6e985a89a166b73ea220",
    "retryable": false
  }
}
```

Program against `code`, which is stable. `message` is for people and may change. `field` names the input at fault, or is `null` when no single field is. A few errors carry extra fields beside these (`choices`, `supported`, `maintenance`).

| Status | Codes | What to do |
|---|---|---|
| 400 | `invalid_request` | The body is not valid JSON, the `Idempotency-Key` is too long, or the key was sent in the URL. Fix the request |
| 401 | `invalid_key`, `expired_key` | Check or rotate the key. Do not retry in a loop |
| 402 | `payment_required` | Your plan's payment is overdue past its grace period. Pay it in the dashboard; sandbox keys keep working |
| 403 | `account_suspended` | The account is not active. Contact support |
| 403 | `plan_upgrade_required` | The plan does not include AI readings or PDF and audio jobs on live keys. Choose a plan that does; sandbox keys can still test them |
| 403 | `plan_family_not_included` | The capability is outside your [plan](https://96astroapi.com/docs/plans.md). The error names the family and the cheapest plans that have it. Not charged; sandbox keys can still test it |
| 403 | `key_scope_denied` | The capability is outside the key's [scopes](https://96astroapi.com/docs/key-restrictions.md#scopes). Widen the scopes in the dashboard or use another key |
| 403 | `ip_not_allowed` | The request did not come from the key's [IP allow-list](https://96astroapi.com/docs/key-restrictions.md#ip-allow-lists). Call from an allowed address or edit the list |
| 403 | `origin_not_allowed` | A [publishable key](https://96astroapi.com/docs/key-restrictions.md#publishable-keys) was used from a website (or without a browser origin) that the key does not allow |
| 403 | `publishable_key_not_allowed` | Publishable keys cannot create PDF or audio jobs, poll jobs or use [conversations](https://96astroapi.com/docs/ai-streaming-and-chat.md#conversations). Use a secret key from your server |
| 404 | `not_found` | There is no such capability, job or file, or it is not yours |
| 406 | `not_acceptable` | You sent `Accept: text/event-stream` to a capability that does not [stream](https://96astroapi.com/docs/ai-streaming-and-chat.md). Remove the header |
| 409 | `idempotency_conflict` | See [below](#idempotency-conflicts) |
| 409 | `conversation_full` | A [conversation](https://96astroapi.com/docs/ai-streaming-and-chat.md#conversations) holds at most 200 messages. Start a new one |
| 410 | `link_expired` | A download link has expired. Poll the job for a fresh link |
| 410 | `file_expired` | The file is no longer kept. Create a new job |
| 413 | `payload_too_large` | Reduce the request size |
| 422 | `invalid_request`, `ambiguous_local_time`, `unsupported_option`, `unsupported_language` | Fix the input. `field` names the problem. `ambiguous_local_time` says to send `utc_offset` to choose, and lists the possible offsets in `choices` when the clocks went back; `unsupported_language` adds `supported`, the languages that capability does take |
| 429 | `rate_limited` | Wait for `Retry-After` seconds, then retry |
| 429 | `quota_exhausted` | No credits left, or a sandbox daily limit was reached. Top up, upgrade or wait for renewal. Retrying will not help |
| 429 | `spend_cap_reached` | Your opt-in overage has reached the monthly spending cap you set (or this call would pass it). Raise the cap or buy a top-up in Billing, or wait for the next period. Retrying will not help |
| 429 | `project_budget_exceeded` | The key's [project](https://96astroapi.com/docs/teams-and-projects.md) has used its monthly credit budget (or this call would pass it). An owner or admin can raise the budget under Projects; it resets on the 1st of the month (UTC). Retrying will not help |
| 499 | `client_disconnected` | Appears only in your usage log, never in a response: you closed a streamed AI reading before it finished (see [what a stream costs](https://96astroapi.com/docs/ai-streaming-and-chat.md#what-a-stream-costs)) |
| 500 | `computation_failed` | Safe to retry with the same idempotency key |
| 501 | `not_yet_available` | Reserved for a capability that is listed but not enabled. None is in this state now |
| 502 / 503 | `unavailable` | Retry with exponential backoff and jitter |
| 503 | `maintenance` | Announced maintenance on the API or on one family. `retryable` is `true`, `Retry-After` says when to retry, and `error.maintenance` has the `scope` and `ends_at` |
| 503 | `temporarily_unavailable` | The capability (or its family) has been switched off for now. It is not retryable in a loop: try again later and check the [status page](https://96astroapi.com/status) |
| 504 | `deadline_exceeded` | The calculation took too long. Retry with backoff |

**You are never charged for an error.** Failed calls do not use credits.

## Idempotency conflicts

`409 idempotency_conflict` has several causes; the `message` says which:

- the same `Idempotency-Key` was used with a **different body**: use a new key;
- a request with that key is **still in progress**: `retryable` is `true`, so retry shortly with the same key;
- the key is more than **24 hours** old, or its original response is no longer kept: use a new key.

## Retrying safely

Retry only when `retryable` is `true`. Use exponential backoff with jitter, and send an [idempotency key](https://96astroapi.com/docs/idempotency.md) on every request, so a retry after a network timeout can never charge twice.
