Errors
Error codes, what they mean and what to do next.
The error shape
Every /v1 error, even 401, has this shape, and the x-request-id header comes with it:
{ "error": { "message": "Rate limit reached. Retry after 3 seconds.", "type": "rate_limit_error", "param": null, "code": "rate_limit_exceeded", "request_id": "..." }}
Write your app against error.code, not the text of message; codes are stable. type is one of invalid_request_error, insufficient_credits, permission_error, rate_limit_error and server_error.
Status codes
| Status | Codes | Next step |
|---|---|---|
400 | invalid_json, missing_required_parameter, invalid_type, invalid_value, unsupported_value | Fix the request body. |
401 | invalid_api_key, token_expired, session_revoked | Check the key. |
402 | insufficient_credits, quota_exceeded | Top up the wallet or check the quota. |
403 | model_requires_paid_plan, content_blocked | Check your plan or the request content. |
404 | model_not_found, unknown_url | Fix the model id or the address. |
413 | request_too_large | Make the request smaller. |
422 | context_length_exceeded, model_does_not_support_images | Shorten the input or pick another model. |
429 | rate_limit_exceeded, too_many_concurrent | Wait for Retry-After and send again. |
500 | internal_error | Write to support with the request_id. |
502 | provider_error | Try again shortly. |
503 | model_unavailable, service_unavailable | Wait for Retry-After or pick another model. |
504 | provider_timeout | Try again. |
Retrying
Only 429, 502, 503 and 504 are worth sending again. Wait a little (as long as Retry-After says, if it is there) and lengthen the gap each time. Other 4xx errors do not fix themselves by resending the same request.
Rate limit headers
When the request limit is active, responses carry x-ratelimit-limit-requests, x-ratelimit-remaining-requests and x-ratelimit-reset-requests. Read the active limits from these headers and check your current plan in the billing dashboard.
Did this page not help? Tell us.