Error Codes
Error format
Section titled “Error format”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.
Status codes
Section titled “Status codes”| Status | Type | Description |
|---|---|---|
400 | invalid_request_error | Request validation failed — malformed JSON, missing required fields, or invalid parameter values. |
401 | authentication_error | Missing or invalid API key / JWT token. |
402 | insufficient_credits | Billing account balance is too low to process the request. Add credits to continue. |
403 | permission_error | Valid credentials but insufficient permissions for the requested resource. |
429 | rate_limit_error | Rate limit exceeded. See Rate Limits for tier details. Retry after the cooldown period. |
500 | internal_error | Unexpected server error. The upstream provider may have returned a 5xx. |
502 | bad_gateway | Failed to connect to the upstream model provider. |
504 | gateway_timeout | Upstream model did not respond within the 30-second timeout. |
Handling errors
Section titled “Handling errors”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.