Error response families
Chat Completions, Responses, Messages, and Gemini are public protocol boundaries, not Web dashboard APIs. They return the error shape of the requested protocol and are never wrapped in the Web application’s{ success, data, error } envelope. service validation errors are preserved whenever they can be returned safely.
OpenAI-compatible Chat Completions and Responses gateway errors use the OpenAI-style shape below, with optional Agent-First hints:
message, type) are present. code and param are optional and appear only when relevant. The hint fields (did_you_mean, suggestions, hint, retryable, retry_after, balance_usd, estimated_cost_usd) are optional extensions for AI agent self-correction. See the Agent-First API guide for details.
Anthropic Messages and Gemini /v1beta endpoints use their native error families and response shapes. Do not write one parser that assumes every AI Sonar endpoint uses the OpenAI shape above.
AI Sonar does not retry deterministic service 400/422 responses. Rate limits, 5xx responses, and timeouts may use bounded retries before the response starts. No protocol retries occur after response bytes have been delivered.
HTTP Status Codes
Error Types
Authentication Errors (401)
Payment Errors (402)
Access Errors (403)
Validation Errors (400)
model_not_found.
Rate Limit Errors (429)
When you exceed rate limits:Retry-After header and retry_after field both indicate the exact seconds to wait before retrying.
Payload Too Large (413)
When input or file size exceeds limits:- Image file too large (max 20MB)
- Audio file too large (max 25MB)
- Input text exceeds model context length
Service Errors (5xx)
Retry only when
retryable is true. If retry_after is present, wait for the specified number of seconds. Use alternatives to select another available model when provided.
Handling Errors in Python
Handling Errors in JavaScript
Best Practices
Implement exponential backoff
Implement exponential backoff
When rate limited, wait progressively longer between retries:
Set timeouts
Set timeouts
Always set reasonable timeouts to avoid hanging requests:
Log errors for debugging
Log errors for debugging
Log the full error response including request ID for support:
Handle model-specific errors
Handle model-specific errors
Some models have specific requirements (e.g., max tokens, image formats).
Validate inputs before making requests.