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.
429rate_limit_errorRate limit exceeded. See Rate Limits for tier details. Retry after the cooldown period.
500internal_errorUnexpected server error. The upstream provider may have returned a 5xx.
502bad_gatewayFailed to connect to the upstream model provider.
504gateway_timeoutUpstream model did not respond within the 30-second timeout.
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="gpt-4o-mini",
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.