Errors
Every error the API returns, what it means, and which ones are safe to retry.
Error shape
A request that fails returns an HTTP status of 400 or more and a JSON body with one error object:
insufficient_balance. Codes never change; new ones may be added.null when there are none. For example the fields that failed validation in details.issues (each a path and a message), why a key was refused in details.reason, or the price and your available balance on a 402.All error codes
| Status | Code | When | Retry |
|---|---|---|---|
| 400 | invalid_request | A field is missing, wrong or out of range. The message says which; details.issues lists the fields. | No |
| 401 | unauthorized | The key is missing, wrong or revoked. | No |
| 402 | insufficient_balance | Your balance is lower than the price. Top up or turn on auto-recharge. | No |
| 403 | permission_denied | The key lacks the permission, a monthly limit would be passed, or the address is not allowed. details.reason says which: key_permission, key_monthly_limit, monthly_limit or ip_not_allowed. | No |
| 404 | not_found | No such object on your account. | No |
| 409 | idempotency_conflict | The Idempotency-Key was used with a different body, or the first request with it is still running. | After a moment |
| 409 | job_not_cancellable | Cancel was asked for a job that is no longer queued. | No |
| 422 | content_refused | The request breaks the use rules. Nothing is charged. | No |
| 429 | rate_limited | Too many requests. Retry after Retry-After seconds. | Yes |
| 500 or 503 | server_error | Something went wrong on our side, or a service is briefly unavailable. Any hold is released at once. | Yes |
| 503 | model_paused | The model is paused for a short while. Retry later. | Yes |
A 403 permission_denied always says why in details.reason: key_permission (the key may not do this), key_monthly_limit or monthly_limit (the request would pass the key's or the account's monthly limit), or ip_not_allowed. If a job cannot be started after its price was held, you get 500 server_error and the hold is released at once.
Which errors are safe to retry
Retry 429, 500, 503 and network errors (timeouts, dropped connections), with backoff and the same Idempotency-Key, so a retry can never start a second job. For a 429, wait the Retry-After seconds first. An idempotency_conflict because the first request is still running is worth retrying after a moment.
Don't retry the others unchanged: fix the request (400), the key or its limits (401, 403), the balance (402) or the content (422) first. The SDKs retry the safe ones for you.
Job failures and request errors
An error response means the request was refused and nothing started. A job can also fail later, after the create succeeded. Then the job has status: "failed" and an error with a code (generation_failed, content_refused or invalid_input) and a message, and we send a job.failed event.
A failed job is never charged: the amount held for it returns to your balance at once. You can start it again with a new request (and a new idempotency key).