Using routing policies
A routing policy isn’t sent in the request body. Gateway resolves it for you on every call based on what you attach to the request and what’s configured on your org. This page covers how that resolution works and what you can do from the request side.
How routing policies are applied
Routing policies are attached to an API key, a project, or a customer, or set as the org default. When Gateway receives a request, it resolves the policy in this order:
- A policy named on the request. An explicit
routing_policy_id, a model alias, or a routing policy id sent as themodelvalue. - A policy bound to the API key. A key can carry its own policy, which beats everything below it. See Bind a policy to a key.
- The customer’s default policy, if you resell Gateway capacity and the request names a
customer. See Embedded Routing. - The project’s policy. A request resolves to a project when it’s authenticated with a project API key, or carries the
project_idbody field orX-Project-Idheader. - The org default policy, when nothing above resolved.
- No policy, direct model calls. Gateway routes directly to the model named in the request.
A key binding that cannot be used, because the policy was deleted, deactivated, or is scoped to a different project or customer, is skipped rather than treated as an error, and resolution continues down the list. POST /v1/embeddings ignores key bindings entirely.
When a routing policy is active, the model field in your request is optional. The policy selects the provider and model automatically. Omit it for Priority and Intelligent routing. model is only required when no policy resolves for the request.
Switching strategies per request
You cannot pass a routing strategy in the request body, but you can name a policy. Create one policy per strategy (for example, one Cost Optimized and one Quality First) and select between them per request:
- Send the policy’s id as
routing_policy_id, or as themodelvalue, or send its@alias/<slug>as the model. - Or bind a policy to the API key each workload uses, so no per-request field is needed.
Either way one organization key reaches any policy, which is what you want when different features or user tiers need different cost and quality trade-offs. Setting both routing_policy_id and a policy id in model is rejected with 400 conflicting_routing_policy rather than resolved by guesswork, and a policy scoped to a project or customer that the request does not resolve to returns 400 routing_policy_requires_project or 400 routing_policy_requires_customer.
Sending a priority list with the request
When a call already knows its own order of preference, send it as priority_order instead of creating a policy first. It is priority routing, the same PRIORITY strategy a stored policy uses, expressed inline: Gateway tries each entry in turn and returns the first success. It bypasses every stored policy (the organization default, a customer’s default, a key binding) the way a direct model call does, while each entry still runs under your controls: the key’s allowed models, vendor and region limits, ZDR, and vendor access all apply to every entry, and a model none of them permit is skipped.
Each entry is a model id (provider/model, or a bare name that resolves the same way model does) or an object with model, an optional priority (lower tries first, as in the routing policies API; list order otherwise), and an optional vendors list, which pins that entry to those execution hosts in order of preference. Up to 10 entries.
The list becomes a policy
The first request that sends a given list creates a routing policy from it, under the customer or project the request is scoped to, or the organization otherwise. The policy’s id is derived from the list’s content and scope, so the same list is always the same policy: every request that sends it is attributed to that id (routing.policy_id, the x-merge-routing-policy-id header, and per-policy usage), and you can name it later with routing_policy_id instead of resending the list. Creation happens after the response, never on the request path. The policy is named from its content, for example Priority: gpt-5.6-sol → claude-sonnet-5 (bedrock) → glm-5.3, is never a default, and is hidden from the policy list endpoints unless you pass include_inline=true.
How it fails over is the same as a stored PRIORITY policy: an entry moves to the next on a provider fault (a 5xx, a 429, a timeout, a billing 402), not on a request error (a 400, 401 or 403 stops the chain), and an entry tries each vendor that serves its model before the next entry is tried unless it is pinned. On a stream, failover happens before the first byte; a fault after the stream has opened is not retried. When every entry fails, the last entry’s error is returned.
model may be omitted, or set to the first entry, which is what the OpenAI and Anthropic SDKs need since they require a model; any other value is rejected with 400 priority_order_model_conflict on the SDK-compatible surfaces (422 on /v1/responses). priority_order cannot be combined with routing_policy_id, a policy alias, or the top-level vendor / vendors pins: pin per entry instead.
Using default_routing
Set the request’s model field to the sentinel value "default_routing" to explicitly request policy-based routing without naming a model.
The sentinel value is case-insensitive and whitespace is stripped, so " Default_Routing " resolves the same as "default_routing".
default_routing is useful when you have a client that always sends a model field, for example the OpenAI SDK or a templated request payload, but you want every request to honor the project or org default policy. Set the value once at the client level and Gateway will pick the model.
If no routing policy resolves for the request (no project policy and no org default), Gateway rejects requests sent with model: "default_routing" because there’s no policy to hand off to. Either configure an org default policy or send a concrete model ID.
FAQs
Can I pass a routing strategy in the request body?
No. Routing strategies live on policies, so there is no type, axis, or strategy field on the POST /responses request body. Name the policy you want instead, with routing_policy_id, its alias, or its id as the model value.
Do I need to pass the model field?
Do I need to pass the model field?
Only when no routing policy applies. If a policy is active (via project or org default), omit model or pass "default_routing" and the policy picks the provider and model for you. This works for Priority and Intelligent routing.
How do I compare routing strategies in my code?
Create one policy per strategy and send routing_policy_id per request, so the comparison is a one-field change with no extra keys or projects. Omit the field to hit the default that resolves for the request.
What happens if all providers fail?
Gateway returns an error after all failover attempts are exhausted. Provider health is tracked automatically so requests skip providers that are currently down.
Can I have multiple default policies?
One org-level default, and one project-scoped policy per project, which serves that project’s unnamed requests. Beyond the defaults you can hold as many policies as you need and select between them per request or per API key.