Skip to content

Error Codes

All errors follow the OpenAI-compatible error format:

{
"error": {
"message": "A human-readable description of the error",
"type": "error_type",
"param": "field_name",
"code": "error_code"
}
}

The param and code fields are optional and may be null.

StatusTypeDescription
400invalid_request_errorRequest validation failed — malformed JSON, missing required fields, or invalid parameter values.
401authentication_errorMissing or invalid API key / JWT token.
402billing_errorBilling account balance is too low to process the request. Add credits to continue.
403authorization_errorValid credentials but insufficient permissions for the requested resource.
404invalid_request_errorResource not found — unknown route, or referenced resource (e.g. file_id) doesn’t exist or belongs to a different organization.
410invalid_request_errorResource gone — typically a referenced file is past its expires_at.
429rate_limit_errorRate limit exceeded. How to retry depends on the bucket — see Rate Limits.
499client_closed_requestClient disconnected before the response finished. Returned for aborted streams.
500server_errorUnexpected error while serving the request.
502server_errorFailed to reach the model inference layer.
504server_errorModel did not respond before the request timeout.

500, 502 and 504 all carry type: "server_error" — read code to tell them apart. A 500 carries no code.

The code field gives a more specific reason than the type alone. Notable ones:

CodeStatusWhen
invalid_value400A request field has an invalid value — a bad mime type or purpose, or an image_url / video_url / file_id needing a capability the chosen model lacks. param names the field
context_length_exceeded400Request exceeds the model’s max context window
file_not_found404Referenced file_id doesn’t exist or isn’t owned by your organization
file_expired410Referenced file_id is past its expires_at
invalid_api_key401Missing, malformed, or unknown API key
rate_limit_exceeded429Per-minute or per-day request/token cap hit
insufficient_credits402Balance too low
upstream_error502Could not reach the model inference layer, or its response was unreadable
timeout504Model did not respond before the request timeout
client_closed_request499Client disconnected before the response finished
from openai import OpenAI, APIError
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.aiand.com/v1",
)
try:
response = client.chat.completions.create(
model="openai/gpt-oss-120b",
messages=[{"role": "user", "content": "Hello!"}],
)
except APIError as e:
print(f"Status: {e.status_code}")
print(f"Message: {e.message}")

The OpenAI SDK automatically parses the error response and raises typed exceptions. For 429 errors, check the X-RateLimit-Policy header and handle the reject by bucket: back off (honoring Retry-After) on time-based rejects, but for concurrency rejects let in-flight requests drain instead of retrying. See Rate Limits.