Skip to main content

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:
For gateway-originated OpenAI-compatible errors, the required base fields (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)

Public routes do not distinguish typo, hidden, deferred, or non-public model states in the response body. If a model is not currently available through the model details, AI Sonar returns model_not_found.

Rate Limit Errors (429)

When you exceed rate limits:
Headers included:
The 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:
Common causes:
  • 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

When rate limited, wait progressively longer between retries:
Always set reasonable timeouts to avoid hanging requests:
Log the full error response including request ID for support:
Some models have specific requirements (e.g., max tokens, image formats). Validate inputs before making requests.