Concepts

Errors

Reference codes and how to handle them.

Error shape

Errors return a non-2xx status and a consistent envelope with a type, machine-readable code and human message.

{
  "error": {
    "type": "invalid_request_error",
    "code": "insufficient_credits",
    "message": "Not enough credits (need 24)"
  }
}

Status codes

FieldTypeDescription
400invalid_request_errorMalformed request or unknown model/action.
401authentication_errorMissing or invalid API key.
402invalid_request_errorinsufficient_credits — top up to continue.
404invalid_request_errorResource not found.
422invalid_request_errorinvalid_params — a param failed validation.
429rate_limit_errorToo many requests or concurrent jobs for your plan.
500api_errorSomething went wrong on our end — safe to retry.

Handling

Treat 429 and 500 as retryable with backoff. 402 and 422 are terminal — fix the input or balance before retrying.