Skip to main content

Error Format

All errors follow a consistent JSON format:

Error Types

Common Errors and Solutions

401 — Invalid API Key

Fix: Check that your API key is correct and hasn’t been revoked.

403 — Provider Not Allowed

Fix: Your API key has an allowed_providers restriction. Use a different key or update the allowed providers via the management API.

429 — Rate Limited

Fix: Implement exponential backoff. Consider raising your key’s rate limit.

502 — Upstream Failed

Fix: The LLM provider returned an error or is unreachable. ARouter automatically handles key failover, but the provider itself may be experiencing issues. Retry or switch to a different provider.

Handling Errors in Code

Retry Strategy

For production applications, we recommend:
  1. Retry on 429 and 502 with exponential backoff
  2. Do not retry on 400, 401, 403 — these are permanent errors
  3. Set a max retry count (e.g., 3 attempts)
  4. Consider multi-model routing — if one model cannot serve the request, send an ordered candidate list via models and route

Handling Errors During Streaming

When streaming (stream: true), errors behave differently depending on when they occur:
  • Before any tokens are sent — ARouter returns a standard HTTP error response with a non-200 status code. Handle this the same as non-streaming errors.
  • After tokens have been sent — The HTTP status is already 200 OK. The error is delivered as an SSE event in the stream body.
Mid-stream errors look like:
Check the finish_reason on each chunk. If it’s "error", the stream has terminated abnormally.
See the Streaming Guide for complete error handling examples.