Cost, occupancy, tags and semantic fallbacks
Last updated: 2026-11-24T13:12:28-03:00 (UTC-3)
Four ways to decide which target serves a request, beyond the declared order and weights:
| Feature | What it does | Flag |
|---|---|---|
cost strategy |
Tries the cheapest target first | routing_strategies |
least_busy strategy |
Tries the target with the fewest in-progress requests first | routing_strategies |
| Tag routing | Reserves targets for requests with certain tags (for example, enterprise customers) | tag_routing |
| Semantic fallbacks | Sends to another alias when the request exceeds the context or hits the content policy | semantic_fallbacks |
By cost or by occupancy
Section titled “By cost or by occupancy”features: routing_strategies: truemodels: - id: chat routing_strategy: cost # or least_busy; ordered is the default targets: - {provider: openai, model: gpt-4.1-mini} - {provider: groq, model: llama-3.3-70b-versatile}cost: the lowest-priced target goes first. The price is input + output per million tokens, from the price book or automatic pricing. A target without a price goes last.least_busy: the target with the fewest in-progress requests on this replica goes first. It is the default of the alias a local inference pool generates, where a replica that is not ready goes last.- The other targets remain as fallbacks, in the strategy’s order.
In the console, the model editor shows the Routing strategy section when the alias has two or more targets and no weights.
Limits:
- requires two or more targets;
- does not combine with weights, latency or automatic routing;
- the Responses route keeps the declared order.
By tags
Section titled “By tags”Useful for giving a group of customers a dedicated deployment without creating another alias:
features: tag_routing: truemodels: - id: chat targets: - {provider: dedicated, model: gpt-4.1, tags: {tier: enterprise}} - {provider: shared, model: gpt-4.1}usage_tags: allowed_values: {tier: [enterprise, free]} defaults_by_team: {acme: {tier: enterprise}}targets[].tags reserves a target for requests whose usage tags carry every listed name and value. Tags come from the X-Gateway-Tags header and from the team defaults (see usage tags).
- Targets whose tags match the request’s come first.
- Targets without tags form the general pool.
- With no eligible target, the response is
403 no_target_for_tags.
In the console, each target has the Reserved for tags field.
Semantic fallbacks
Section titled “Semantic fallbacks”A request too long for the model, or refused by the provider’s content policy, can go on to another alias instead of coming back as an error:
features: semantic_fallbacks: truemodels: - id: chat context_window_fallback: chat-long # context overflow content_policy_fallback: chat-safe # refusal by content policy targets: [{provider: openai, model: gpt-4.1-mini}]context_window_fallbacknames the alias that serves a request too long for the model’s context window, andcontent_policy_fallbackthe alias that serves a request the provider refused for its content policy; both needsemantic_fallbacks.- The second attempt happens only once. Its answer carries
X-Gateway-Fallback: <kind>:<alias>(context_window:chat-long). - Other 400 errors come back as they were.
- With
targets[].max_input_tokensdeclared, a request clearly too long for a target is caught before it is sent: the target is skipped without a provider call, the next target is tried, and when none is left the request goes tocontext_window_fallbackthe same way. See context window check before dispatch.
The fallback alias is admitted exactly like a direct request of the same key, so a fallback can never reach a model, budget or plan the key could not reach on its own:
| Check on the fallback alias | Applies when |
|---|---|
The key’s allowed_models (and access groups) |
Always |
| The team policy | team_policy_enforcement is on |
| The organization ceiling | organizations is on |
| Plan entitlements for the alias’s features (routing strategy, retries, semantic cache and so on) | feature_plan_entitlements is on |
| Rate limits, including per end user | rate_limits / end_user_rate_limits are on |
| Budgets and TPM/TPD, including model, team and end-user policies, with an approved rate for the fallback’s target | budget_limits / tpm_limits are on |
| Input guardrails of the fallback alias | guardrails is on |
The second attempt carries the client’s X-Gateway-End-User, X-Gateway-Session-Id, X-Gateway-Tags, X-Gateway-Cache and X-Gateway-Timeout-Ms headers, so end-user and tag budgets, tag-reserved targets, cache directives and the client’s timeout apply to it too. It is a separate request in usage and budgets, with the request ID <request id>.fallback. The refused first attempt keeps its own record and reservation under the usual rules.
When the fallback alias gets no provider answer, there is no fallback. That covers a refusal by the gateway before dispatch (access, plan, rate limit, budget, guardrail, quota or policy storage unavailable) and a provider that could not be reached or timed out. The client then gets the original provider error unchanged, which names the real cause (the prompt is too long, the content was refused), and the header X-Gateway-Fallback-Refused: <kind>:<code> with the gateway code of the refusal:
HTTP/1.1 400 Bad RequestX-Gateway-Fallback-Refused: context_window:model_forbidden
{"error":{"code":"context_length_exceeded","message":"This model's maximum context length is 8192 tokens"}}Common codes are model_forbidden (key, team policy or organization), entitlement_forbidden, rate_limit_exceeded, quota_exceeded (see budgets and TPM), guardrail_blocked, quota_unavailable, upstream_error and request_timeout. The header never names the fallback alias, which the key may not be allowed to know. The refusal is also logged as semantic_fallback_refused with the kind and code. If the fallback’s provider answers with an error, that answer is returned as it is, with X-Gateway-Fallback.
See also
Section titled “See also”- Weights and per-target capacity.
- Automatic routing: choosing the alias by the request’s content.
- Circuit breaker: taking a failing target out of rotation.