# Errors

> What to do after an error: the next step for each HTTP status, the error object, the 8 request error codes and the 5 task failure codes.

<a id="shape"></a>

## Error response shape
A failed Kerox API request returns a real HTTP status code and the error object below. `param` appears when one field is at fault. Branch on `error.code`; `error.message` says exactly what went wrong and may be reworded over time.


```json
{
  "error": {
    "code": "invalid_request",
    "message": "duration must be -1 or between 4 and 30.",
    "param": "input.duration"
  }
}
```


Every response also carries the `x-request-id` header. Include it when you email us at hi@kerox.ai.

<a id="next-steps"></a>

## What to do next
Branch on the HTTP status and `error.code`, not on `message`.

| You got | What it means | Do this |
| --- | --- | --- |
| HTTP `400` `invalid_request` | A field is missing or wrong; `error.param` names it | Fix that field and send again. A new request, not a retry |
| HTTP `401` `unauthorized` | No key, a mistyped key, or a key that was revoked or is past its expiry date | Check the `Authorization: Bearer <key>` header; create a new key in [Console → API → API Keys](https://kerox.ai/de/console/api-keys) if needed |
| HTTP `402` `insufficient_balance` | The available balance does not cover the estimate, or this key's spend limit would be passed; `message` says which | Top up ([Top-ups](https://kerox.ai/de/docs/pricing-billing.md#topups)) or raise the key's limit ([Key limits](https://kerox.ai/de/docs/authentication.md#limits)) |
| HTTP `400` `model_unavailable` | The model cannot take tasks now | Choose a live model or try later |
| HTTP `403` `forbidden` | Account or key restrictions | Verify your email, check the account status, outgoing IP and allowed models for this key |
| HTTP `404` `not_found` | Unknown path, model, file or task | Check the endpoint and model ID. For a task or file, use its returned ID and a key from the account that created it |
| HTTP `413` `invalid_request` | The request body or inline files are too large | Upload files first and submit their URLs |
| HTTP `409` `invalid_request` | An `Idempotency-Key` used before with a different body | Use a new key for a new request ([Idempotency](https://kerox.ai/de/docs/idempotency-limits.md#idempotency)) |
| HTTP `429` `rate_limited` with `retry-after` | Too many submits or uploads this minute | Wait that many seconds, then send the same request again |
| HTTP `429` `rate_limited` without `retry-after` | Too many tasks in progress | Wait for one of your tasks to finish, then send again ([Limits](https://kerox.ai/de/docs/idempotency-limits.md#rate-limits)) |
| HTTP `500` or `503` `internal_error` | A problem on our side | Retry with the same `Idempotency-Key`; if it keeps failing, email hi@kerox.ai with the `x-request-id` header |
| `status: "failed"` on a task | The task was accepted, then failed, and was refunded; `error.code` says why ([below](#task-failures)) | A retry is a new task: submit it again with a new `Idempotency-Key` |

**Presigned PUT, HTTP `412`.** The storage service returns this directly. Check the HTTP status before parsing JSON. Read `GET /v1/files/{id}`: use the URL when ready, or request a fresh upload if deleted or still pending after polling.

<a id="request-errors"></a>

## Request error codes
| `code` | HTTP | When it happens |
| --- | --- | --- |
| `invalid_request` | 400 / 409 / 413 | The request is wrong: not JSON, a missing, unknown or invalid field (named in `param`), a body over 4 MB or base64 files over 3 MB (413), or an Idempotency-Key reused with a different body (409). Fix it and send again. |
| `unauthorized` | 401 | No API key, an unknown or revoked key, or a key past its expiry date. |
| `forbidden` | 403 | The account is disabled or its email is not verified, the request IP is not on the key’s allowlist, or the key may not use this model. |
| `insufficient_balance` | 402 | The available balance is less than the estimate, the balance is negative, or the task would pass the key’s spend limit. The message says which. |
| `not_found` | 404 | The endpoint, model, task or file does not exist (or belongs to another account). |
| `model_unavailable` | 400 | The model is not open yet or is temporarily unavailable. Try another model or retry later. |
| `rate_limited` | 429 | Too many submissions or uploads per minute (`retry-after` says how long to wait), or too many tasks in progress. |
| `internal_error` | 500 / 503 | Our side failed (500) or is briefly unavailable (503). Retry with the same Idempotency-Key; if it persists, email hi@kerox.ai with the x-request-id of the response. |

<a id="task-failures"></a>

## Task failure codes
When a task is accepted (`201`) and later fails, `GET /v1/tasks/{id}` and the webhook return `status: "failed"` with `error: { code, message }`. Failed and timed-out tasks are refunded in full (`cost.status: "refunded"`).

| `code` | When it happens | What to do |
| --- | --- | --- |
| `content_violation` | The prompt, an input file or the result was blocked by content moderation. | Change the content and retry. |
| `moderation_unavailable` | Content moderation was temporarily unavailable. | Retry shortly. The hold is refunded. |
| `input_fetch_failed` | An input file could not be downloaded (the link does not open or has expired). | Use another URL, or upload with /v1/files. |
| `invalid_input` | The model rejected the parameters or an input file (for example a reference video over the resolution limit). | Change the input and retry. |
| `timeout` | The task did not finish within the model’s time limit. | Retry as is. |
| `generation_failed` | Generation failed for any other reason. | Retry as is. |
