Guides
Errors
Errors use standard HTTP status codes and a JSON body with a stable code you can branch on.
{
"error": {
"type": "invalid_request_error",
"code": "invalid_parameter",
"message": "duration must be an integer from 3 to 15.",
"param": "duration"
}
}Codes
| HTTP | Code | Meaning |
|---|---|---|
| 400 | invalid_parameter | A parameter is missing, unknown or out of range. See param. Nothing is charged. |
| 400 | invalid_media | A media URL is not public HTTPS, could not be fetched, or is not a supported file. See param. Nothing is charged. |
| 400 | invalid_request | The job was created but rejected when it started (for example, an image that cannot be decoded). The charge was refunded; error.job_id names the failed job. |
| 401 | invalid_api_key | The API key is missing, malformed or revoked. |
| 402 | insufficient_credits | The account balance does not cover this job. Nothing is created or charged. |
| 403 | model_not_permitted | Your key is not approved for this model. |
| 404 | not_found | The job does not exist for your account. |
| 409 | idempotency_conflict | An Idempotency-Key was reused with a different body. |
| 429 | rate_limited | Too many requests, running jobs, or jobs this hour. See Rate limits. |
| 500 | internal_error | Something failed on our side. Safe to retry. |
| 502 | generation_failed | The job could not be started. The charge was refunded; error.job_id names the failed job. Safe to retry. |
| 503 | capacity_unavailable | Pricing or capacity is temporarily unavailable. Nothing is charged. Retry with backoff. |
Retrying safely
Send an Idempotency-Key header (any unique string, up to 64 characters) on POST requests. Retrying with the same key and body returns the original job instead of creating — and charging — a second one. Retry 429, 500, 502 and 503 with exponential backoff; do not retry other 4xx errors without changing the request.