Skip to content

API

Errors

Status codes, the error body and which errors to retry.

When a request fails
When a request fails
Read the status
The HTTP status code
Read the error
The message says why
Choose what to do
Fix it, or wait before retrying
  1. Read the status. The HTTP status code
  2. Read the error. The message says why
  3. Choose what to do. Fix it, or wait before retrying

Errors come back as JSON with an error object, in OpenAI's shape.

The status code tells you what to do next.

Status codes

CodeMeaningRetry
400Bad request. invalid_json: the body isn't valid JSON. invalid_request: a field is wrong, or the request asks for something AZRouter doesn't offer, such as a server tool or web search. text_only: a model sold only at its lower price was sent tools, an image, audio or a file, or a coding agent's request. image_request: a model sold only at its lower price per image was sent something other than a text prompt for one image on /v1/images/generations. video_request: a model sold only at its lower price per second was sent something other than a text prompt and its video's length on /v1/videos. video_token_request: a model billed per video token was sent a field it doesn't take, a resolution it doesn't make, or something other than a JSON body on /v1/videos. embedding_request: a model sold only at its lower price for embeddings was sent something other than 1 to 128 text inputs on /v1/embeddings. speech_request: a model sold only at its lower price for speech was sent a voice name instead of an ElevenLabs voice ID, a format other than MP3 or a field it doesn't take on /v1/audio/speech, and speech_request_too_long more characters than its limit. content_refused: the model refused this request for content safety; change it first (repeated ones can pause the model for your account, see Rate limits). resend_blocked: the same request was refused or rejected moments ago, so sending it again unchanged is blocked for a few minutes; change it first. model_paused: the provider paused this model for your account after repeated refused requests, for up to 24 hours (see Rate limits).No
401invalid_api_key: the key is missing, malformed or revoked, or switched off because your spending reached your tier's monthly cap.After you fix the key or the cap resets
402insufficient_user_quota: your credit balance can't cover the request. The message says what it needed; see 402: not enough credits.After a top-up or a lower max_tokens
403access_denied: the key reached its own spending limit, or your account or usage tier can't make this request.After the limit or tier changes
404model_not_found: the slug is misspelled or the model is not on sale. Check GET /v1/models.No
413The request body is too large: a JSON body is at most 8 MiB.No
429rate_limit_exceeded: a rate limit was hit, yours or the upstream provider's, or the request would go over your monthly cap (then Retry-After is 3600).After Retry-After
429request_too_large: this one request is over a limit of your tier on its own, such as its input tokens per minute, so waiting won't help: send a smaller request, or move up a tier. It has no Retry-After.No
429refusal_hold: three requests refused for content safety on a model in 10 minutes pause that model for your account for up to 1 hour; see Rate limits.After Retry-After
500, 502, 503service_unavailable: no upstream can serve the request right now, or the gateway failed.With backoff

Error body

A key that doesn't exist:

Shell
curl https://api.azrouter.dev/v1/chat/completions \
  -H "Authorization: Bearer sk-not-a-real-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen/qwen3.8-flash", "messages": [{"role": "user", "content": "Hello"}]}'
JSON
{"error":{"message":"Invalid or expired API key.","type":"authentication_error","code":"invalid_api_key"},"request_id":"..."}

A body that isn't JSON:

Shell
curl https://api.azrouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $AZROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{not json'
JSON
{"error":{"message":"Request body must be valid UTF-8 JSON.","type":"invalid_request_error","param":null,"code":"invalid_json"}}

Most errors carry a request_id; quote it when you contact support. 429 and 5xx use a fixed message:

JSON
{"error":{"message":"The service is temporarily unavailable. Please retry.","type":"server_error","code":"service_unavailable"},"request_id":"..."}

402: not enough credits

A 402 has type insufficient_quota and code insufficient_user_quota, and its message says what the request needed.

A model priced by tokens

This request requires more credits, or fewer max_tokens.

You requested up to N tokens, but can only afford M.

To increase, visit https://azrouter.dev/dashboard/credits (opens in a new tab) and add more credits.

N is the max_tokens you sent, or the model's maximum output when you sent none; M is the most your balance pays for.

A price that isn't per token, such as an image or a second of video

This request requires more credits.

It can cost up to $X, but you can only afford $Y.

To increase, visit https://azrouter.dev/dashboard/credits (opens in a new tab) and add more credits.

Lower max_tokens or add credits. Rate limits explains how a request with no output cap is sized, and why parallel requests should each set one.

Retries

Retry 429 after the Retry-After header (not request_too_large, which has none), and 5xx with exponential backoff.

A 400, 401, 402 or 403 fails again until you change the request, the key or your balance.

The OpenAI SDKs already retry 429 and 5xx for you; see Rate limits.