Smart Routing

How AnyRouter picks an upstream for each request, with automatic failover, model aliases and per-request override controls.

Each request goes through a routing layer that picks the best upstream for the model, skips unhealthy backends and fails over automatically. You can steer it per request.

Select a model directly (anthropic/claude-sonnet-4-6), by preset (@preset/code-reviewer), or a preset with a model override (openai/gpt-5.4-mini@preset/code-reviewer). See Presets.

How a model maps to an upstream

Each model id has a list of upstream candidates with routing metadata (priority, price, latency, throughput). Per request, AnyRouter builds the candidate set, applies your provider preferences, skips cooled-down backends and dispatches to the highest-priority candidate. On a retryable error it tries the remaining candidates in order, unless fallbacks are disabled.

A candidate is marked unhealthy for a short window after a 5xx, a timeout (timeout_ms exceeded) or an exhausted rate-limit budget. Requests that hit a fallback are logged with the final backend id.

Provider preferences

json
{
  "model": "openai/gpt-5.4-mini",
  "provider": {
    "only": ["OpenAI", "Groq"],
    "order": ["Groq", "OpenAI"],
    "sort": "latency",
    "allow_fallbacks": true,
    "max_price": { "prompt": "1.00", "completion": "2.00" },
    "preferred_max_latency": 300,
    "preferred_min_throughput": 40
  }
}
  • only limits candidates to the named providers; ignore removes them.
  • order pins a preferred backend order before the default.
  • sort reorders by price, latency, throughput or exacto.
  • require_params (for example ["tools"] or ["response_format"]) keeps only backends supporting those parameters. It is distinct from boolean require_parameters.
  • min_context is a token floor; anyrouter/auto drops members below it.
  • max_price.prompt and max_price.completion filter out backends above budget.
  • preferred_max_latency and preferred_min_throughput drop candidates that miss the target.
  • allow_fallbacks: false stops after the first candidate fails.

Provider names are normalized (OpenAI, openai, Z.AI, Moonshot AI all map to the right backend).

Force a specific upstream

Set X-AnyRouter-Provider to pin a request to one candidate, for reproducible evals, BYOK tests or routing around an outage:

bash
curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer sk-ar-your-key" \
  -H "X-AnyRouter-Provider: openrouter" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-5.4-mini", "messages": [{"role": "user", "content": "hi"}]}'

If the forced provider is unhealthy, the request fails immediately. Header pinning bypasses normal fallback selection.

Model aliases

Some models have several slugs for compatibility (anthropic/claude-sonnet-4-6 and claude-sonnet-4-6 route to the same backend). Canonical slugs are provider/model; bare slugs are resolved by lookup.

Built-in anyrouter/* aliases appear in the models catalog and work on chat completions, messages and responses:

AliasWhat it routes to
anyrouter/autoTop usage and top stable platform models (free-tier mixed with credit-billed), health-aware failover. Honors provider.sort: "exacto", min_context, require_params: ["tools"] and ["response_format"]. anyrouter/auto[1m] / [500k] are min-context shortcuts, not separate listing ids.
anyrouter/latestThe newest live chat models first: up to 20 ordered by release date, then older ones. Models with poor recent success are skipped; preview and alpha models count only when used and healthy. Up to 12 upstream hops per request. The response model field and X-AnyRouter-Model header name the model that answered.
anyrouter/freeCurated $0 platform models (Go plan)
anyrouter/hermes / anyrouter/coworkPer-provider tool-calling chains, billed to credits
anyrouter/byok / anyrouter/coding / anyrouter/agentChains built from your own provider keys

anyrouter/latest follows release dates, not traffic: a newer healthy model is always tried first. Pin a concrete id for a specific generation.

Retired listing ids can keep working on chat completions: the request is rewritten to a configured fallback (today stealth/ox-alpha and stealth/ox-alpha[1m] route to anyrouter/auto), and the old model page says the model was removed.

Parallel upstreams for anyrouter/free and anyrouter/auto

If the first upstream sends no usable token after about 2.5 seconds, AnyRouter starts one more (a different provider or model from the same alias). The first real token wins and the other is cancelled. You are billed only for the upstream that answered. It applies to streaming requests only, fires at most once per request, and is skipped for very long prompts.

When a second upstream started, the response carries x-anyrouter-hedge: won=<model>;delay=<ms>. No header means one upstream ran. The model field always names the model that answered.

To turn it off, go to Dashboard > Settings > Routing and switch off Parallel upstreams (faster first token), or send {"parallelHedgeEnabled": false} to PUT /api/v1/user/preferences. Members are still tried one after another on failure.

Tracing and request ids

Inference endpoints accept an optional trace object, kept on internal routing steps and forwarded as correlation metadata to AI Gateway-backed upstream calls:

json
{
  "trace": {
    "trace_id": "4f8c2b9670b44b49a2e71e7fd5c0b1d3",
    "trace_name": "checkout-flow",
    "span_name": "summarize-cart"
  }
}

Every response includes an X-Request-ID header for support.

Rate-limit headers

Responses carry rate-limit metadata for your key and for the upstream that served the request. The router starts failing over when the upstream limit is close to exhausted; clients that respect the headers get smoother behavior. See Rate Limits for the per-key headers.

X-RateLimit-Limit: 600
X-RateLimit-Remaining: 599
X-RateLimit-Reset: 1760000060
X-Upstream-RateLimit-Remaining: 998

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer