Hoveydai

Errors

Error codes, what they mean and what to do next.

Reading time: 1 min

The error shape

Every /v1 error, even 401, has this shape, and the x-request-id header comes with it:

JSON
{  "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

StatusCodesNext step
400invalid_json, missing_required_parameter, invalid_type, invalid_value, unsupported_valueFix the request body.
401invalid_api_key, token_expired, session_revokedCheck the key.
402insufficient_credits, quota_exceededTop up the wallet or check the quota.
403model_requires_paid_plan, content_blockedCheck your plan or the request content.
404model_not_found, unknown_urlFix the model id or the address.
413request_too_largeMake the request smaller.
422context_length_exceeded, model_does_not_support_imagesShorten the input or pick another model.
429rate_limit_exceeded, too_many_concurrentWait for Retry-After and send again.
500internal_errorWrite to support with the request_id.
502provider_errorTry again shortly.
503model_unavailable, service_unavailableWait for Retry-After or pick another model.
504provider_timeoutTry 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.