# Provider Routing

> Route requests across upstream providers. Customize ordering, sorting, fallbacks, performance thresholds, data policies, and pricing budgets per request.


# Provider Routing

Steer which upstream serves a request with a top-level `provider` object next to `model` and `messages`. It works on [Chat Completions](/api-reference/chat-completions) and is accepted on Responses and Messages. By default requests are load balanced across the top-priority providers for uptime. You need an API key (`sk-ar-...`) from the [dashboard](https://anyrouter.dev/dashboard/keys).

```bash
curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer <ANYROUTER_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/llama-3.3-70b-instruct",
    "messages": [{"role": "user", "content": "Hello"}],
    "provider": { "sort": "throughput", "max_price": { "prompt": 1, "completion": 2 } }
  }'
```

Model-id shortcuts replace a `provider` object: `:nitro` (sort by throughput), `:floor` (price), `:fast` (latency), `:exacto` (higher-precision weights; quality-first members on `anyrouter/auto`). On `anyrouter/auto`, append `[1m]` or `[500k]` (any `[<n>k]` or `[<n>m]`) to set `provider.min_context`, for example `anyrouter/auto[1m]:exacto`.

## Field reference

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `order` | string[] | – | Provider slugs to try in order, for example `["anthropic", "openai"]`. See [Ordering Specific Providers](#ordering-specific-providers). |
| `allow_fallbacks` | boolean | `true` | Allow backup providers when the primary is unavailable. |
| `require_parameters` | boolean | `false` | Only use providers that support all parameters in your request. |
| `require_params` | string[] | – | Hard requirements such as `["tools"]`. Distinct from `require_parameters`. |
| `min_context` | number | – | Minimum context window in tokens. `anyrouter/auto` keeps only members at or above it. |
| `data_collection` | "allow" \| "deny" | "allow" | Whether to use providers that may store data. |
| `zdr` | boolean | – | Only Zero Data Retention endpoints. |
| `enforce_distillable_text` | boolean | – | Only models that allow text distillation. |
| `only` | string[] | – | Provider slugs to allow. |
| `ignore` | string[] | – | Provider slugs to skip. |
| `quantizations` | string[] | – | Quantization levels to filter by, for example `["int4", "int8"]`. |
| `sort` | string \| object | – | `"price"`, `"throughput"`, `"latency"`, `"exacto"`, or `{ "by", "partition" }`. |
| `preferred_min_throughput` | number \| object | – | Preferred minimum tokens/sec. Number, or percentile cutoffs (p50/p75/p90/p99). |
| `preferred_max_latency` | number \| object | – | Preferred maximum seconds. Number, or percentile cutoffs (p50/p75/p90/p99). |
| `max_price` | object | – | Highest price you accept. |

Every field above, and the four shortcuts, is honored end to end. Filters that rely on provider metadata (`zdr`, `quantizations`, `data_collection`, `enforce_distillable_text`) use each upstream's `features` block and the model's `data_policy` in the catalog, so their result sets grow as that metadata fills in.

## Price-Based Load Balancing (Default Strategy)

Per model, requests are load balanced across providers, prioritizing price:

1. Prioritize providers without significant outages in the last 30 seconds.
2. Among those, pick from the lowest-cost candidates weighted by the inverse square of price.
3. Use the rest as fallbacks.

Example: providers at $1, $2 and $3 per M tokens, where the $2 provider had recent outages. The request is 9x more likely to land on the $1 provider than the $3 one (1/3² = 1/9). If $1 fails, $3 is tried, then $2.

Sending `tools` or `tool_choice` routes only to providers that support tool use; setting `max_tokens` routes only to providers that support that length. If `sort` or `order` is set, load balancing is off.

## Provider Sorting

Set `sort` to try providers in order of one attribute instead of load balancing:

- `"price"`: lowest price (same as `:floor`)
- `"throughput"`: highest throughput (same as `:nitro`)
- `"latency"`: lowest latency (same as `:fast`)
- `"exacto"`: higher-precision weights on a single model, quality-first members on `anyrouter/auto` (same as `:exacto`; a routing preference, not a model id)

```json
{ "model": "meta-llama/llama-3.3-70b-instruct", "provider": { "sort": "throughput" } }
```

## Advanced Sorting with Partition

With multiple `models` (see [model fallbacks](/guides/model-fallbacks)), `sort` can be an object:

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `sort.by` | string | – | `"price"`, `"throughput"` or `"latency"`. |
| `sort.partition` | string | `"model"` | `"model"` groups endpoints by model, so the primary model is always tried first. `"none"` sorts endpoints globally across all models. |

```json
{
  "models": ["anthropic/claude-sonnet-4-6", "openai/gpt-5.4-mini", "google/gemini-3.1-flash"],
  "provider": { "sort": { "by": "throughput", "partition": "none" } }
}
```

This routes to whichever endpoint across all three models has the best throughput right now. With [BYOK](/features/byok), `partition: "none"` lets BYOK endpoints win across model boundaries: if you have an OpenAI key but no Anthropic key, GPT on your key can be chosen even though Claude is listed first.

## Performance Thresholds

`preferred_min_throughput` (tokens/sec) and `preferred_max_latency` (seconds) are preferences, not filters: endpoints that miss them move to the end of the list, and no guarantee is made. A number applies to p50; an object sets percentile cutoffs, all of which must be met. Percentiles come from a rolling 5-minute window per model and provider (p90 latency of 2 s means 90% of requests finish in under 2 s). Use p90 or p99 for real-time apps and p50 throughput for batch work.

```json
{
  "models": ["anthropic/claude-sonnet-4-6", "openai/gpt-5.4-mini", "google/gemini-3.1-flash"],
  "provider": {
    "sort": { "by": "price", "partition": "none" },
    "preferred_min_throughput": { "p90": 50 },
    "preferred_max_latency": { "p50": 1, "p90": 3, "p99": 5 }
  }
}
```

This picks the cheapest model and provider that meets the thresholds; slower ones stay available as fallbacks.

## Ordering Specific Providers

`order` lists provider slugs to try one at a time, then falls back to other providers if none work. Add `allow_fallbacks: false` to fail instead. Without `order`, requests are [load balanced](#price-based-load-balancing-default-strategy).

```json
{ "model": "mistralai/mixtral-8x7b-instruct", "provider": { "order": ["openai", "together"], "allow_fallbacks": false } }
```

Here OpenAI is skipped because it does not host Mixtral, Together is tried, and the request fails if Together fails.

## Targeting Specific Provider Endpoints

A provider can host several endpoints for one model (a `turbo` variant, or regions such as `google-vertex/us-east5`). A base slug in `order`, `only` or `ignore` matches all of them; a full slug matches one.

| Slug | Matches |
| --- | --- |
| `"google-vertex"` | Every Vertex endpoint (all regions) |
| `"google-vertex/us-east5"` | Only the `us-east5` endpoint |
| `"deepinfra"` | Default and turbo endpoints |
| `"deepinfra/turbo"` | Only the turbo endpoint |

Copy exact slugs from the provider list on the model's page.

```json
{ "model": "deepseek/deepseek-r1", "provider": { "order": ["deepinfra/turbo"], "allow_fallbacks": false } }
```

## Requiring Providers to Support All Parameters

By default a provider that does not support a parameter in your request still receives it and ignores the parameter. `require_parameters: true` skips such providers.

```json
{ "model": "openai/gpt-5.4-mini", "response_format": { "type": "json_object" }, "provider": { "require_parameters": true } }
```

## Requiring Tool Calling and Context Size

For `anyrouter/auto` and other auto-routing models. The fields also persist on [presets](/features/presets); call `@presets/<slug>` and the floors apply on every request.

| Field | Type | Description |
| --- | --- | --- |
| `require_params` | string[] | `["tools"]` keeps only models that advertise tool calling; `["response_format"]` only models whose upstream advertises JSON mode. Not the boolean `require_parameters`. |
| `min_context` | number | Minimum context window in tokens. `1000000` keeps members with at least 1M. |

A non-empty `tools` array on the request also requires tool-calling members.

```json
{ "model": "anyrouter/auto", "provider": { "sort": "exacto", "min_context": 1000000, "require_params": ["tools"] } }
```

## Requiring Providers to Comply with Data Policies

`data_collection`: `"allow"` (default) permits providers that may store data non-transiently or train on it; `"deny"` uses only providers that do not collect user data. Each model's provider list shows a **Data Policy** tag. It reflects our best knowledge, not a definitive source for third-party policies.

```json
{ "model": "openai/gpt-5.4-mini", "provider": { "data_collection": "deny" } }
```

## Zero Data Retention Enforcement

`zdr: true` routes only to endpoints with a Zero Data Retention policy. `false` or unset has no effect. Use it per request when you do not want to enforce ZDR globally.

```json
{ "model": "openai/gpt-5.4", "provider": { "zdr": true } }
```

## Distillable Text Enforcement

`enforce_distillable_text: true` routes only to models whose author allows text distillation, for building fine-tuning or distillation datasets.

```json
{ "model": "meta-llama/llama-3.3-70b-instruct", "provider": { "enforce_distillable_text": true } }
```

## Disabling Fallbacks

`allow_fallbacks: false` serves the request only from the top (lowest-cost) provider, or from your `order` list when set. If that fails, the request fails.

```json
{ "model": "openai/gpt-5.4-mini", "provider": { "allow_fallbacks": false } }
```

## Allowing Only Specific Providers

`only` allows the listed provider slugs. It reduces fallback options and limits recovery.

```json
{ "model": "openai/gpt-5.4-mini", "provider": { "only": ["azure"] } }
```

## Ignoring Providers

`ignore` skips the listed slugs. Ignoring several reduces fallback options.

```json
{ "model": "meta-llama/llama-3.3-70b-instruct", "provider": { "ignore": ["deepinfra"] } }
```

## Quantization

Filter by quantization with `quantizations`. Quantized models can degrade on some prompts. Allowed levels: `int4`, `int8`, `fp4`, `fp6`, `fp8`, `fp16`, `bf16`, `fp32`, `unknown`.

```json
{ "model": "meta/llama-3.1-8b-instruct", "provider": { "quantizations": ["fp8"] } }
```

## Maximum Price

`max_price` is the highest price you accept, in dollars per 1M tokens: `{"prompt": 1, "completion": 2}` allows prompt price ≤ $1/M and completion price ≤ $2/M. Also available: `request` (per-request pricing, where supported) and `image` (per image input). Combine with `sort`, for example the highest throughput that costs at most $X/M.

Unlike the preferences above, `max_price` is a hard filter: if no provider matches, the request fails with a `404`.

## Provider-Specific Headers

AnyRouter forwards a curated set of `anthropic-beta` values to Anthropic-backed models. Separate several with commas, for example `anthropic-beta: fine-grained-tool-streaming-2025-05-14,interleaved-thinking-2025-05-14`.

| Feature | Header value | Description |
| --- | --- | --- |
| Fine-Grained Tool Streaming | `fine-grained-tool-streaming-2025-05-14` | Real-time updates as tool arguments are generated. |
| Interleaved Thinking | `interleaved-thinking-2025-05-14` | Reasoning interleaved with regular output instead of one block. |
| Structured Outputs | `structured-outputs-2025-11-13` | Strict tool use: validates tool parameters against your schema. |

AnyRouter enables prompt caching and extended context from model capabilities, and applies the structured-outputs header automatically for `response_format.type: "json_schema"`. For strict tool use (`strict: true` on tools) you must pass `anthropic-beta: structured-outputs-2025-11-13` yourself; without it AnyRouter strips `strict` and routes normally. Beta features are experimental and Anthropic may change them.

```bash
curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer <ANYROUTER_API_KEY>" \
  -H "Content-Type: application/json" \
  -H "anthropic-beta: interleaved-thinking-2025-05-14" \
  -d '{"model": "anthropic/claude-sonnet-4-6", "stream": true,
       "messages": [{"role": "user", "content": "What is 15% of 240? Think step by step."}]}'
```

## Terms of Service

Each upstream's terms are on the [Providers](/features/models-catalog) page. You may not violate the terms or policies of the third-party providers that power the models.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| `404` with `max_price` set | It is a hard filter and no upstream is within the ceiling. Raise or remove the cap. |
| Slow providers still used despite a threshold | `preferred_*` fields only deprioritize. Use `only` or `ignore` to exclude. |
| Slug matches more endpoints than expected | A base slug such as `"google-vertex"` matches every region. Use the full slug (`"google-vertex/us-east5"`). |
| Pinned provider down | With `allow_fallbacks: false` the request fails by design. |


## Related

- [Smart Routing](/docs/features/routing.md)
- [Model Fallbacks](/docs/guides/model-fallbacks.md)
- [Latency Overhead](/docs/guides/latency-overhead.md)
