Skip to content
صوتك عربي

Errors

Read and handle API errors consistently.

Errors use an OpenAI-compatible envelope. Check the HTTP status first, then use error.code for programmatic handling. Keep request_id when it is present so support can trace a request.

{
  "error": {
    "message": "Invalid API key",
    "type": "authentication_error",
    "code": "auth_failed",
    "param": null,
    "request_id": "…"
  }
}

Common responses

StatusMeaningClient action
400Invalid input or unsupported optionCorrect the request; do not retry unchanged.
401Missing, invalid, or expired credentialReplace the credential.
402Insufficient balanceAdd balance before retrying.
403The key lacks the needed scopeUse a key with the required permission.
404Resource is unavailable to this accountCheck the identifier and access.
413Request or upload is too largeReduce the request or split the file.
429Rate or authentication throttleRespect Retry-After, then retry with backoff.
5xxTemporary API or capacity failureRetry idempotent work with bounded backoff.

Do not present raw API messages directly to end users. Map stable error codes to clear product copy and log the request ID separately.

On this page