翻篇收录说明
翻篇网页快照

Provider Routing - Smart Multi-Provider Request Management

https://openrouter.ai/docs/guides/routing/provider-selection

最近抓取:2026-12-04 08:09:08(北京时间)

最近内容变化:2026-12-04 08:09:08(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Route requests to the best provider

正文摘录

For Responses, Chat Completions, and Messages, default routing uses each provider’s measured price, throughput, latency, and reliability. For the Video API, see Video provider routing. You can customize how your requests are routed using the provider object in the request body for the Responses API, Chat Completions, and the Messages API. The Video API also accepts a provider object, but it doesn’t support provider.max_price or sorting by price, latency, or throughput. See Video provider routing for the supported options. For Responses, Chat Completions, and Messages, the provider object can contain the following fields: FieldTypeDefaultDescriptionorderstring[]-List of provider slugs to try in order (e.g. ["anthropic", "openai"]). Learn moreallow_fallbacksbooleantrueWhether to allow backup providers when the primary is unavailable. Learn morerequire_parametersbooleanfalseOnly use providers that support all parameters in your request. Learn moredata_collection”allow” | “deny""allow”Control whether to use providers that may store data. Learn morezdrboolean-Restrict routing to only ZDR (Zero Data Retention) endpoints. Learn moreenforce_distillable_textboolean-Restrict routing to only models that allow text distillation. Learn moreonlystring[]-List of provider slugs to allow for this request. Learn moreignorestring[]-List of provider slugs to skip for this request. Learn morequantizationsstring[]-List of quantization levels to filter by (e.g. ["int4", "int8"]). Learn moresortstring | object-Sort providers by price, throughput, or latency. Can be a string (e.g. "price") or an object with by and partition fields. Learn morepreferred_min_throughputnumber | object-Preferred minimum throughput (tokens/sec). Can be a number or an object with percentile cutoffs (p50, p75, p90, p99). Learn morepreferred_max_latencynumber | object-Preferred maximum latency (seconds). Can be a number or an object with percentile cutoffs (p50, p75, p90, p99). Learn moremax_priceobject-The maximum pricing you want to pay for this request. Learn more Regional data residency (Business and Enterprise)OpenRouter supports in-region routing in the EU and US on the Business and Enterprise plans. There is no provider preference or setting to turn on: send the request to https://eu.openrouter.ai or https://us.openrouter.ai, and its prompts and completions are processed entirely within that region. Learn more in the In-Region Routing guide. Default Routing This section applies to Responses, Chat Completions, and Messages. The Video API selects one eligible endpoint and does not retry on another provider if submission fails. See Video provider routing. For each model in your request, OpenRouter picks a provider by comparing what a good response would actually cost you at each one, not by list price alone. Each input is measured from recent production traffic, so routing reacts within minutes when a provider gets faster, slower, or less reliable: Effective price: the price the provider actually charges, reflecting its real cache hit rate and its typical mix of input and output tokens. Throughput: end-to-end output tokens per second. A faster provider can charge more and still win your request. Time to first token (TTFT): how long you wait before the response starts streaming. Rate limits: how often the provider rejects requests with a 429 because it is out of capacity. Reliability: how often requests fail because of the provider. Quality: whether the provider’s tool calls come back well formed. Providers close to the best share most of the traffic, and each request picks one at random, weighted by those shares. Providers far behind still get a small share, so routing notices when they improve. On top of the shares: A provider whose errors or 429s are far worse than the model’s other providers gets no traffic until it recovers. Routing learns how much load each provider can take before it returns 429s, and sends the rest to other providers. A burst of 429s or a jump in latency briefly lowers a provider’s share. If a request fails, the retry is picked the same way from the providers that are left. Follow-up requests in a conversation stay with the same provider while its prompt cache is warm. For more detail on each input, see How OpenRouter Routes Traffic Between Providers. When you send a request with tools or tool_choice, OpenRouter makes a best effort to route to providers known to support tool use. Similarly, if you set max_output_tokens (or max_tokens on Chat Completions), then OpenRouter will only route to providers that support a response of that length. Default routing applies whenever you leave the choice of provider to OpenRouter. It is bypassed when you set sort (or a default provider sort in your account settings), use the :floor or :nitro shortcuts, set order, or use your own provider key. If you set only or ignore and two or more providers remain, default routing picks among them. Provider Sorting As described above, default routing balances price against throughput, latency, and reliability. If you instead want to explicitly prioritize a particular provider attribute, you can include the sort field in the provider preferences. Default routing is bypassed, and the router will try providers in that order. The three sort options are: "price": prioritize lowest price "throughput": prioritize highest throughput "latency": prioritize lowest latency TypeScript SDKTypeScript (fetch)PythonGocURLimport { OpenRouter } from '@openrouter/sdk'; const openRouter = new OpenRouter({ apiKey: '<OPENROUTER_API_KEY>', }); const response = await openRouter.responses.send({ responsesRequest: { model: 'meta-llama/llama-3.3-70b-instruct', input: 'Hello', provider: { sort: 'throughput', }, stream: false, }, }); console.log(JSON.stringify(response, null, 2)); The remaining examples below show the JSON request body for POST https://openrouter.ai/api/v1/responses (the same provider object works on Chat Completions and Messages); pass it using any of the clients above. To always prioritize low prices instead of using default routing, set sort to "price". To always prioritize low latency instead of using default routing, set sort to "latency". Nitro Shortcut You can append :nitro to any model slug as a shortcut to sort by throughput. In addition to the throughput sort, :nitro makes priority service tier endpoints eligible for the request, so it is a superset of setting provider.sort to "throughput" (which only sorts). :nitro is a routing variant: it is not a separate entry in the models API, and the model’s metadata is the base model’s. See the Nitro variant docs for details. Request body{ "model": "meta-llama/llama-3.3-70b-instruct:nitro", "input": "Hello", "stream": false } Floor Price Shortcut You can append :floor to any model slug as a shortcut to sort by price. In addition to the price sort, :floor makes flex service tier endpoints eligible for the request, so it is a superset of setting provider.sort to "price" (which only sorts). :floor is a routing variant: it is not a separate entry in the models API, and the model’s metadata is the base model’s. See the Floor variant docs for details. Request body{ "model": "meta-llama/llama-3.3-70b-instruct:floor", "input": "Hello", "stream": false } Advanced Sorting with Partition When using model fallbacks, the sort field can be specified as an object with additional options to control how endpoints are sorted across multiple models. FieldTypeDefaultDescriptionsort.bystring-The sorting strategy: "price", "throughput", or "latency".sort.partitionstring"model"How to group endpoints for sorting: "model" (default) or "none". By default, when you specify multiple models (fallbacks), OpenRouter groups endpoints by model before sorting. This means the primary model’s endpoints are always tried first, regardless of their performance characteristics. Setting partition to "none" removes this grouping, allowing endpoints to be sorted globally across all models. To explicitly use the default behavior, set partition: "model". For more details on how model fallbacks work, see Model Fallbacks. preferred_max_latency and preferred_min_throughput do not guarantee you will get a provider or model with this performance level. However, providers and models that hit your thresholds will be preferred. Specifying these preferences should therefore never prevent your request from being executed. This is different than max_price, which will prevent your request from running if the price is not available. Use Case 1: Route to the Highest Throughput or Lowest Latency Model When you have multiple acceptable models and want to use whichever has the best performance right now, use partition: "none" with throughput or latency sorting. This is useful when you care more about speed than using a specific model. Request body{ "models": [ "anthropic/claude-sonnet-4.5", "openai/gpt-5-mini", "google/gemini-3-flash-preview" ], "input": "Hello", "provider": { "sort": { "by": "throughput", "partition": "none" } } } In this example, OpenRouter will route to whichever endpoint across all three models currently has the highest throughput, rather than always trying Claude first. Performance Thresholds You can set minimum throughput or maximum latency thresholds to filter endpoints. Endpoints that don’t meet these thresholds are deprioritized (moved to the end of the list) rather than excluded entirely. FieldTypeDefaultDescriptionpreferred_min_throughputnumber | object-Preferred minimum throughput in tokens per second. Can be a number (applies to p50) or an object with percentile cutoffs.preferred_max_latencynumber | object-Preferred maximum latency in seconds. Can be a number (applies to p50) or an object with percentile cutoffs. How Percentiles Work OpenRouter tracks latency and throughput metrics for each model and provider using percentile statistics calculated over a rolling 5-minute window. The available percentiles are: p50 (median): 50% of requests perform bett