Skip to content

Errors

Errors

All errors return JSON with OpenAI-compatible format:

{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"code": null
}
}

Error Types

StatusTypeDescription
401authentication_errorInvalid or missing API key
429rate_limit_errorRate limit exceeded
502upstream_errorModel service unavailable
413invalid_request_errorRequest body too large
400invalid_request_errorInvalid request parameters
503server_errorService temporarily unavailable

Handling Errors

Python

from openai import AuthenticationError, RateLimitError
try:
response = client.chat.completions.create(...)
except AuthenticationError as e:
print(f"Invalid API key: {e}")
except RateLimitError as e:
print(f"Rate limited: {e}")
# Implement backoff

Node.js

try {
const response = await client.chat.completions.create(...);
} catch (error) {
if (error.status === 401) {
console.error('Invalid API key');
} else if (error.status === 429) {
console.error('Rate limited');
}
}