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.

The one exception is POST /v1/messages, which answers in Anthropic’s envelope so that Anthropic SDKs and Claude Code read it natively:

{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "A human-readable description of the error"
},
"request_id": "…"
}

code and param are included inside error when set. A request that exceeds the model’s context window is a 400 whose message begins prompt is too long and carries the capability_rejected: prompt_too_long token, which Claude Code’s automatic compaction looks for. The status codes below apply to both shapes.

StatusTypeDescription
400invalid_request_errorRequest validation failed — malformed JSON, missing required fields, or invalid parameter values.
401authentication_errorMissing or invalid API key / JWT token.
402billing_errorBilling account balance is too low to process the request. Add credits to continue.
403authorization_errorValid credentials but insufficient permissions for the requested resource.
404invalid_request_errorResource not found — unknown route, a model your organization cannot use, or referenced resource (e.g. file_id) doesn’t exist or belongs to a different organization.
410invalid_request_errorResource gone — a referenced file is past its expires_at, or the endpoint has been removed.
429rate_limit_errorRate limit exceeded. How to retry depends on the bucket — see Rate Limits.
499client_closed_requestClient disconnected before the response finished. Returned for aborted streams.
500server_errorUnexpected error while serving the request.
502server_errorUpstream error, or a provider connection could not be used or checked. Read code for the reason.
504server_errorModel did not respond before the request timeout.

500, 502 and 504 all carry type: "server_error" — read code to tell them apart. A 500 carries no code.

The code field gives a more specific reason than the type alone. Notable ones:

CodeStatusWhen
invalid_value400A request field has an invalid value — a bad mime type or purpose, an image_url / video_url / file_id needing a capability the chosen model lacks, a content part type the model does not support, a tool result with no matching tool call, a tool_choice asking for a tool that is not in tools, or a max_tokens (max_completion_tokens when a chat request sends that, max_output_tokens on /v1/responses) at least as large as the model’s context window. param names the field
invalid_media_url400A media URL does not meet the URL requirements, for example an http URL, an IP address, or an internal hostname. Also returned when the model server cannot download a URL that meets them: the host refused the download (the message gives the host’s HTTP status), or the file is larger than the download limit. Also returned when a media content part carries no media and no file_id, for example an image named only by uuid. Use a public https URL, a file_id, or a base64 data: URL. param names the field
context_length_exceeded400Request exceeds the model’s max context window. Shorten the prompt or lower the requested output tokens
media_count_exceeded400The request has more images or videos than this model accepts in one request. The message gives the limit. A PDF counts as one image per page. Send fewer, or use a model that accepts more. param names the field
media_size_exceeded400The request’s images and videos, once decoded, are larger in total than this model accepts in one request. A PDF sends one image per page. Send fewer or smaller images, fewer PDF pages, or a shorter or lower-resolution video. param names the field
unsupported_value400The request uses something that is not available: previous_response_id or an item_reference input item on /v1/responses (response objects are not stored), or an input item type or tool type the model does not support. param names the field, and the message names the type when it is a standard one
file_not_found404Referenced file_id doesn’t exist or isn’t owned by your organization
file_expired410Referenced file_id is past its expires_at
endpoint_removed410The endpoint no longer exists, such as /v1/completions. The message names the endpoint to use instead
model_not_found404The model is not an exact model id, or the model is not priced in your billing currency. GET /v1/models lists chat models and GET /v1/videos/models lists video models
model_deprecated404The model was retired. The message names the model to use instead
model_access_denied404The model exists, but your organization does not have access to it. Contact support@aiand.com to request access
invalid_api_key401Missing, malformed, or unknown API key
rate_limit_exceeded429A rate limit was exceeded. Model-bucket rejects set X-RateLimit-Policy; authentication throttles carry only Retry-After
insufficient_credits402Balance too low
upstream_error502Could not reach the model inference layer, or its response was unreadable
connection_unavailable502Requests through provider connections are not supported yet; ai& credits are not charged
connection_lookup_failed502Provider connections could not be checked and no cached list is available
connection_rate_limit_exceeded429Too many requests through your organization’s provider connections. This limit is set by ai&, not by your provider; retry after the Retry-After seconds
connection_requires_api_key403The model is served through your organization’s own provider connection, which accepts requests made with an API key only, not from the console
provider_key_rejected403Anthropic rejected the key on your organization’s Anthropic connection. An org admin must replace the key before the connection serves again
unsupported_endpoint400The model is served through your organization’s Anthropic connection, which accepts requests on /v1/messages and /v1/messages/count_tokens only
timeout504Model did not respond before the request timeout
client_closed_request499Client disconnected before the response finished

A model can turn reasoning off only if its published levels include none. Sending reasoning_effort none, reasoning.effort none, chat_template_kwargs.reasoning_effort none, chat_template_kwargs.enable_thinking: false or chat_template_kwargs.thinking: false, or on /v1/messages a thinking block with type disabled, to a reasoning model that does not publish none, returns 400 invalid_request_error:

Model '<name>' cannot disable reasoning: suppressing it needs reasoning_effort 'none', which this model does not publish. Supported values: <levels>. Use '<level>' for the least reasoning.

<level> is the lowest of that model’s published levels. A model without the reasoning capability ignores these fields instead.

A level other than none that a model doesn’t list runs at the next listed level up, or the model’s highest, instead of failing; an unlisted none is the 400 above. A value outside the effort vocabulary, such as ultra, gets Model '<name>' does not support <field> '<value>'. Supported values: <levels>. A reasoning model that lists no levels at all answers any level with Model '<name>' lists no reasoning levels, so it cannot apply <field>. Two fields that set different levels, such as reasoning_effort and chat_template_kwargs.reasoning_effort, none next to chat_template_kwargs.enable_thinking: true, or on /v1/messages a reasoning_effort other than none next to thinking: { "type": "disabled" }, get <field> and <field> set different reasoning levels. Send the level in one field.

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="google/gemma-4-31b-it",
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 with X-RateLimit-Policy, handle the reject by bucket: back off (honoring Retry-After) on time-based rejects, but for concurrency rejects let in-flight requests drain instead of retrying. An authentication throttle has no policy and should honor Retry-After. See Rate Limits.