# Errors

Every error has one shape, inside a stream too (`data: {"error": ...}`):

```json
{
  "error": {
    "type": "billing_error",
    "code": "insufficient_balance",
    "message": "The balance does not cover this request: about 40 tokens are needed, 12 are available.",
    "param": null,
    "request_id": "req_01JE...",
    "doc_url": "https://unitool.ai/developers/errors#insufficient_balance",
    "details": { "required_tokens": 40, "available_tokens": 12 }
  }
}
```

- `code` is stable: build your handling on it. `message` is written for people and may change.
- `type` matches the OpenAI types, so the OpenAI SDKs raise the usual exceptions.
- `param` names the parameter at fault, when that is known.
- `request_id` is the request id: look it up in `GET /v1/requests/{id}` and quote it to support.
- `doc_url` points to the code's entry on this page.

On `/v1/messages` errors use Anthropic's envelope `{"type":"error","error":{"type","message"},"request_id"}` with the same `type` values and HTTP statuses as below (402 is `billing_error`, 413 `request_too_large`, overload is 503, not 529); `code`, `param` and `details` are absent there. A mid-stream error arrives as `event: error`. More in [Anthropic API](/developers/messages#errors).

Retry only 429, 500, 502, 503 and 504, after the `Retry-After` pause. The OpenAI SDKs do this themselves.

## 400 Bad request

### invalid_json

HTTP 400 · `invalid_request_error` · do not retry. The body is not JSON or cannot be read. Check `Content-Type: application/json` and escaping.

### missing_parameter

HTTP 400 · `invalid_request_error` · do not retry. A required parameter is missing, its name is in `param`. For example an empty `messages` or a required `input` field of a generation.

### invalid_parameter

HTTP 400 · `invalid_request_error` · do not retry. A value of the wrong type or out of range, the name is in `param`. A request the model rejected as a whole answers the same (check messages, attachments, `tools` and `response_format`), and so does a request with too many files by link: more than 4 in chat, more than 10 links and `data:` URLs in a generation.

### unsupported_parameter

HTTP 400 · `invalid_request_error` · do not retry. The parameter is not supported by the API or by this model: `provider`, `plugins`, `web_search_options`, an unknown field, `temperature` for a model without it, an image for a model without vision. Remove the parameter named in `param`.

### context_length_exceeded

HTTP 400 · `invalid_request_error` · do not retry. The input is larger than the model's context. Trim the history or pick a model with a larger `context_length`.

### use_chat_endpoint

HTTP 400 · `invalid_request_error` · do not retry. A text model was sent to `/v1/generations`. Call it through `POST /v1/chat/completions`.

### unsupported_model

HTTP 400 · `invalid_request_error` · do not retry. The model is not served on this path: `/v1/messages` is for Claude models only. Call the model through `POST /v1/chat/completions`. The code shows in the receipt; in the Anthropic envelope the `message` names the reason.

### model_not_supported

HTTP 400 · `invalid_request_error` · do not retry. The model cannot be called through this OpenAI-compatible path: it has no fitting mode. Use `POST /v1/generations` with the mode's schema, see [Images and speech](/developers/images-audio).

### content_policy_violation

HTTP 400 · `invalid_request_error` · do not retry. An answer of `/v1/images/*` and `/v1/audio/speech`: moderation rejected the request or the result. Tokens are returned; the generation id is in `error.unitool.generation_id`.

### invalid_content_type

HTTP 400 · `invalid_request_error` · do not retry. `/v1/images/edits` takes `multipart/form-data` only.

### invalid_multipart

HTTP 400 · `invalid_request_error` · do not retry. The `multipart/form-data` body could not be parsed.

### response_too_large

HTTP 400 · `invalid_request_error` · do not retry. The images are over 32 MiB together, too much for `b64_json`. The generation is ready and paid: read it by `error.unitool.generation_id` and download it by `url`.

### not_available_in_test_mode

HTTP 400 · `invalid_request_error` · do not retry with a test key. This path does not work with a `ut_test_` key: it has no test answer. Use a live key. What works with a test key: [Test keys](/developers/authentication#test-keys).

### file_too_large

HTTP 400 · `invalid_request_error` · do not retry. The file is over the limit: images 20 MiB, audio and video 100 MiB, documents 50 MiB. In chat: the files by link do not fit into 10 MB together with the rest of the request.

### unsupported_file_type

HTTP 400 · `invalid_request_error` · do not retry. The file format does not fit the field or the model.

### file_download_failed

HTTP 400 · `invalid_request_error` · do not retry without a fix. The file link did not download: it answered an error or an empty body, timed out, or is not a public https address on the default port.

### file_unreadable

HTTP 400 · `invalid_request_error` · do not retry. The file is damaged or cannot be read: the model could not open the attachment, or a video's duration could not be measured.

### file_not_found

HTTP 400 · `invalid_request_error` · do not retry. No file with this `file_ref`, or its upload has not finished.

### file_expired

HTTP 400 · `invalid_request_error` · do not retry. The file's retention period is over. Upload it again.

### request_too_large

HTTP 413 · `invalid_request_error` · do not retry. The request body is over 10 MB. Pass large files by link or through `/v1/uploads`.

## 401 Key

### invalid_api_key

HTTP 401 · `authentication_error` · do not retry. The key is missing, mistyped or deleted. Check the `Authorization: Bearer ut_live_...` header.

### api_key_revoked

HTTP 401 · `authentication_error` · do not retry. The key was revoked. Create a new one in your [account](/settings?p=api).

## 402 Payment

### insufficient_balance

HTTP 402 · `billing_error` · do not retry until you top up or shrink the request. The free balance does not cover the request's hold. When `max_tokens` is the reason, `details.affordable_max_tokens` says how much output the balance pays for now. `details` also has `required_tokens` and `available_tokens`. More in [Billing](/developers/billing).

### key_spend_limit_reached

HTTP 402 · `billing_error` · do not retry until the limit resets. The request does not fit into the key's spend limit. Raise the limit in your account or wait for the reset. `details.affordable_max_tokens` works as for `insufficient_balance`.

### price_exceeds_limit

HTTP 402 · `billing_error` · do not retry. The generation costs more than `max_cost_tokens`. `details.required_tokens` has the real price. Nothing was charged.

## 403 Access

### api_access_not_enabled

HTTP 403 · `permission_error` · do not retry. The API is not open for the account: a closed beta, or access is switched off.

### payment_required

HTTP 403 · `permission_error` · do not retry. API access opens after the first payment on the account.

### account_suspended

HTTP 403 · `permission_error` · do not retry. API access of the account is suspended. Contact [support](/support).

### ip_not_allowed

HTTP 403 · `permission_error` · do not retry. The key allows only some IP addresses and the request came from another one; the address we saw is in `details.ip`. Edit the list in your account.

### test_key_not_supported

HTTP 403 · do not retry. The MCP answer to a test key: MCP calls are real and billed. Use a live key with the `mcp` scope.

### key_limit_not_supported

HTTP 403 · do not retry. The MCP answer to an API key with a spend limit: MCP spend is not counted against key limits, so such a key is not let in. Use a separate key with the `mcp` scope and no limit for MCP. Comes as `{"error": "...", "code": "key_limit_not_supported"}`.

### insufficient_scope

HTTP 403 · `permission_error` · do not retry. The key lacks the scope for this endpoint; the message names it. The scopes are listed in [Authentication](/developers/authentication#scopes).

## 404 and 410 Not found

### model_not_found

HTTP 404 · `not_found_error` · do not retry. No such model or mode, or the model has left the API. The list: `GET /v1/models`.

### model_retired

HTTP 410 · `not_found_error` · do not retry. The model left the API after `details.sunset_at`. If it has a replacement, its id is in `details.replacement` and in the message. The `Deprecation` and `Sunset` headers warn ahead of time, see [Models](/developers/models#retiring-models).

### file_link_expired

HTTP 404 · `not_found_error` · do not retry this link. The result file link is wrong, expired (links live one hour) or its file was deleted. Read the generation again (`GET /v1/generations/{id}`) for a fresh link.

### generation_not_found

HTTP 404 · `not_found_error` · do not retry. Your account has no generation with this id.

### request_not_found

HTTP 404 · `not_found_error` · may be retried later. No receipt with this id: the request is someone else's, the id is wrong, or the request is still running.

### unsupported_endpoint

HTTP 404 · `not_found_error` · do not retry. The API has no such path or method, for example `/v1/embeddings`.

## 409, 416 and 422 Conflict

### not_cancellable

HTTP 409 · `conflict_error` · do not retry. The generation has reached the model or finished and can no longer be cancelled.

### generation_not_finished

HTTP 409 · `conflict_error` · retry when the generation ends. A `DELETE` of a running generation: cancel it or wait for it to end.

### generation_canceled

HTTP 409 · `conflict_error` · do not retry. An answer of `/v1/images/*` and `/v1/audio/speech`: the generation was canceled before it started; nothing was charged.

### range_not_satisfiable

HTTP 416 · `invalid_request_error` · do not retry. The requested `Range` lies outside the file.

### idempotency_key_reused

HTTP 422 · `conflict_error` · do not retry. The same `Idempotency-Key` was already used with another request body. A new request needs a new key.

## 429 Too many

### rate_limit_exceeded

HTTP 429 · `rate_limit_error` · retry after `Retry-After`. The per-minute request limit of the key or the account is exceeded, or two files by link are already downloading for the account's generations. Current values are in the `x-ratelimit-*` headers and `GET /v1/key`.

### concurrency_limit_exceeded

HTTP 429 · `rate_limit_error` · retry after `Retry-After`. Too many requests of the account run at once. Wait for some of them to finish. Chat requests with files run one at a time per account: that refusal carries `details.lane: "files"`.

### balance_held

HTTP 429 · `rate_limit_error` · retry after `Retry-After`. The money is there but held by running requests. The hold is released when they finish. Smaller `max_tokens` makes this rarer.

## 5xx Failures

### internal_error

HTTP 500 · `api_error` · may be retried once or twice. Our failure. The request is not charged unless its receipt says otherwise.

### upstream_error

HTTP 502 · `api_error` · may be retried. The model failed to answer. If the answer had started, only the generated part was charged (`details.charged_tokens`).

### overloaded

HTTP 503 · `overloaded_error` · retry after `Retry-After`. The service is overloaded or restarting. A request we stopped before the first token is not charged.

### model_unavailable

HTTP 503 · `overloaded_error` · retry after `Retry-After` or use another model. The model is temporarily unavailable.

### service_paused

HTTP 503 · `overloaded_error` · retry later. This part of the API is switched off for now, for example media generations.

### timeout

HTTP 504 · `timeout_error` · may be retried. The model did not answer in time or the request ran over 15 minutes. Only what was generated is charged.

### generation_timeout

HTTP 504 · `timeout_error` · do not retry without `Idempotency-Key`. `/v1/images/*` and `/v1/audio/speech` waited 120 seconds for the generation. It keeps running and is charged when it finishes: the id is in `error.unitool.generation_id`, read `GET /v1/generations/{id}`. A repeat with the same `Idempotency-Key` waits for the same generation; without one it starts a new paid generation.
