# Errors

> The error format, the codes, what to do about them and which requests to retry.

An error comes in the OpenAI envelope — the way your SDK understands it. Include `request_id` when contacting support; it also
comes in the `x-request-id` header of every response.

```json
{"error": {"message": "...", "type": "...", "code": "...", "param": "...", "request_id": "req_..."}}
```

The `param` field is present only when the error concerns a specific parameter.

## Error codes

| HTTP | code | What it means |
| --- | --- | --- |
| 400 | `invalid_request` | Malformed request body (no `model`, broken JSON) — check the parameters. A provider rejection the gateway could not classify uses the same code; the HTTP status is then the provider's (4xx). |
| 400 | `unsupported_parameter` | A request parameter is not supported — its name is in the param field. Remove it and retry. For video models with a conditions table this is the answer to `size` (`param: "size"`) — set the resolution with `resolution` or `mode`. See [Request parameters](https://llmbox.cc/en/docs/params). |
| 400 | `unsupported_video_options` | A video model with a conditions table has no price for the combination of resolution (`mode`), audio, length and operation (text to video, image to video or video to video). The message lists the supported values — pick one of them. See [Video](https://llmbox.cc/en/docs/videos). |
| 400 | `invalid_resolution` | `resolution` (or `mode`) of a video model with a conditions table is not a string. |
| 400 | `invalid_effort` | The effort level is not a string or not one of `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. See [Request parameters](https://llmbox.cc/en/docs/params#effort-level). |
| 400 | `unsupported_effort` | The model does not offer this effort level — the allowed values are in the model catalog. |
| 400 | `unsupported_value`, `invalid_value` | The model's provider rejected a parameter value; the parameter name is in the param field when it could be determined. |
| 400 | `context_length_exceeded` | The request does not fit the model's context window. The message starts with “Prompt is too long:”. |
| 400 | `content_policy_violation` | The model's content policy rejected the request — change the prompt. |
| 400 | `invalid_image` | The model rejected the reference image — try a different one. |
| 401 | `invalid_api_key` | Key missing, not found or revoked — check the Authorization header. |
| 402 | `insufficient_quota` | The free balance does not cover the request reserve. The message names the reserve and the amount missing, for example: "Insufficient balance: this request reserves $0.41 (input estimate + maximum output), $0.36 more is needed. Reduce max_tokens or top up." Lower `max_tokens` (`n` for images, the length for video) or top up your account. With a zero balance the response comes right after the key check, before the request body is read. If the remainder is held by requests in progress, retry once they finish. |
| 403 | `spend_limit_exceeded` | This key hit its spend limit, or the request reserve would exceed it (the message names the excess) — raise the limit, lower `max_tokens` or create a new key. |
| 404 | `model_not_found` | The model does not exist, is disabled, is not available to your account or does not fit the endpoint (an image model on chat) — check GET /v1/models with your key. |
| 404 | `not_found` | Unknown endpoint, video job not found or the video is not ready yet. |
| 413 | `invalid_request` | The request body exceeds the limit — see [Limits](https://llmbox.cc/en/docs/limits). |
| 415 | `invalid_request` | The body was not sent as JSON: the `Content-Type: application/json` header is missing or names another type — for example `application/x-www-form-urlencoded`, which `curl -d` sets by default. Add the header. |
| 422 | `generation_failed` | The model returned no image. Retry the request or rephrase the prompt. |
| 429 | `rate_limit_exceeded` | The requests-per-minute limit of the key or account is exhausted (without a key — of the IP address), too many concurrent requests on your account, or the model is overloaded at the provider. Retry after the pause in the `Retry-After` header. |
| 500 | — | Internal gateway error (`type: server_error`, no `code`). Retry; if it persists, contact support with the `request_id`. |
| 502 | `upstream_unavailable` | The model is temporarily unavailable — retry later. |
| 503 | `server_restarting` | The server is restarting and the request was cut off before a response — retry the request. |
| 503 | `service_unavailable` | Service under maintenance, temporarily unavailable, or its database is temporarily unreachable — retry after `Retry-After` (when the header is present) or later. |
| 503 | `overloaded` | The server is handling too many heavy media requests at once: image generations and video jobs with a body over 5 MiB. Retry after the pause in `Retry-After` (5 seconds). See [Limits](https://llmbox.cc/en/docs/limits). |
| 503 | `video_disabled` | Intake of new video generations is turned off (`POST /v1/videos`; polling and download keep working) — retry later. |
| 503 | `video_options_unavailable` | The selected video options are unavailable right now — choose other options; retrying with the same options may not help for a while. |
| 503 | `effort_options_unavailable` | There is no available provider for the selected effort level right now; retry later or choose another level. |
| 503 | — | The model is temporarily unavailable (`type: server_error`, no `code`) — retry later or pick another model. |
| 504 | `upstream_timeout` | The provider did not answer a request without streaming within 10 minutes. The request is not retried: generation may have started; nothing is charged. Retry the request, and use `stream: true` for long answers. See [Limits](https://llmbox.cc/en/docs/limits). |

## Retries

Retrying makes sense for 429, 500, 502, 503, 504 and 422. Other errors will not go
away on retry — fix the request, key or balance first.

- On `429` wait for the pause in the `Retry-After` header; without it, use
  exponential backoff (1, 2, 4… seconds). The OpenAI SDK does this
  itself.
- An error that arrives as an event mid-stream is also a reason to retry the
  whole request (see [Streaming](https://llmbox.cc/en/docs/streaming)).

## Errors in a stream

Once the response has started (HTTP 200), an error arrives as an event in the
endpoint's format, and no `[DONE]` follows it. The gateway does not forward the
provider's error — it sends its own event with one of these codes:

| code | What it means |
| --- | --- |
| `upstream_interrupted` | The provider cut the response off or sent an error. If part of the response already arrived, the message says so ("The partial output above was delivered"). Retry the request. |
| `upstream_timeout` | The provider did not deliver the response in time: no first fragment within 10 minutes, a pause of more than five minutes after it, or a stream longer than an hour — see [Streaming](https://llmbox.cc/en/docs/streaming). If part of the response already arrived, the message says so. Retry the request. |
| `server_restarting` | The server is restarting ("The server is restarting. Please retry the request."). Retry the request. |

The event carries no amounts and no provider name. Event shapes are in [Streaming](https://llmbox.cc/en/docs/streaming).

> Stuck? Message us on Telegram — [@llmbox_support_bot](https://t.me/llmbox_support_bot) — with the `request_id` from the response.
