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.
402insufficient_creditsBilling account balance is too low to process the request. Add credits to continue.
403permission_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. Retry after the cooldown period.
500internal_errorUnexpected error while serving the request.
502bad_gatewayFailed to reach the model inference layer.
504gateway_timeoutModel did not respond within the 30-second timeout.

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

CodeStatusWhen
invalid_value400A request field has an invalid value (mime type, purpose, etc.)
context_length_exceeded400Request exceeds the model’s max context window
model_capability_mismatch400Request includes an image_url / video_url / file_id that requires a capability the chosen model lacks
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
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, implement exponential backoff with retries.