Routing decision headers
Every response from the gateway carries headers that say which deployment served the call, which routing strategy picked it, and why the request ended up there. When a request needed more than one provider call, the headers also say how many calls were made and what caused the last retry or fallback. On request, the gateway lists every candidate deployment it skipped and the reason for each skip, and the same record is stored with the request's spend log so you can look it up later in the Admin UI or over the API.
This page covers every routing header the gateway returns. You do not need to turn anything on. The headers are returned for every routing strategy, including a plain pick with no auto router, a routing preset and every fallback hop.
A real-world scenario
A team runs the model group chat over three deployments with the latency-based-routing strategy. For a few minutes, every answer comes from the slowest deployment and the team wants to know why. They send one request with the x-spanway-routing-skips: true header and read the response headers. x-spanway-routing-reason says strategy=latency-based-routing, x-spanway-attempts says 1, and x-spanway-routing-skips lists the two faster deployments with the reason cooldown. The deployments had been put in cooldown after a burst of rate limit errors, and the Logs page confirms it for every request in that window without anyone reproducing the problem.
The headers
| Header | When it is sent | Value |
|---|---|---|
x-spanway-routing-reason | Always, as long as a strategy picked the deployment. | key=value pairs separated by ; . See the next table. |
x-spanway-attempts | Always. | How many provider calls the request took, counting retries and fallbacks. 1 means the first call succeeded. |
x-spanway-routing-skips | Only when the request carried x-spanway-routing-skips: true. | A JSON list of the candidates the router skipped, each with deployment_id, model and reason. Up to 25 entries. [] when nothing was skipped. |
x-spanway-model-id, x-spanway-model-group | Always. | The deployment and the model group that served the call. |
x-spanway-attempted-retries | Always on routed requests, 0 when no retry happened. | Retries made on the same model group. |
x-spanway-max-retries | After a retry. | The retry cap that applied. |
x-spanway-attempted-fallbacks | Always on routed requests, 0 when no fallback happened. | How many fallback hops were made before success. |
x-spanway-fallback-errors | After a fallback, when the request sends include_fallback_errors: true and general_settings.expose_fallback_errors_to_caller is on. That setting is off by default, because the upstream error text can reveal provider details, see the settings reference. | The errors that caused each hop, as JSON. |
x-spanway-complexity-router-tier, -cause, -score, -reasoning-effort | When an auto router of type complexity decided the tier. | The tier, what decided it, the score and the pinned reasoning effort. |
x-spanway-quality-router-model, -tier, -via, -keyword, -complexity | When a quality router decided. | The routed model and how it was chosen. |
x-spanway-adaptive-router-model | When an adaptive router decided. | The logical model it chose. |
x-spanway-context-fit, x-spanway-context-fit-dropped-messages | When context fit trimmed the request. | The strategy that ran and how many messages it removed. |
The parts of x-spanway-routing-reason, in the order they appear. A part is left out when it does not apply, so a plain request to a group with the default strategy reads strategy=simple-shuffle and nothing else.
| Part | Meaning |
|---|---|
strategy | The routing strategy that picked the deployment, for example simple-shuffle, latency-based-routing, cost-based-routing, usage-based-routing-v2 or least-busy. A routing group's strategy or a key's router_settings override shows up here when one applied. |
preset | The routing preset and version that applied, for example eu-fast@3. |
budget_tier | The budget tier a request that sent model @tier was served on, for example economy. |
router, tier, cause | For auto-routed requests, the router type, the tier it chose and what decided it. The causes are listed on the auto routing page. |
fallback_cause | The error class that triggered the last fallback hop, for example RateLimitError or Timeout. |
retry_cause | The error class that triggered the last retry, when the request was retried but never fell back. |
The skip reasons in x-spanway-routing-skips and in the spend log. context_window, rpm_limit and unsupported_param come from the router's pre-call checks, so they are recorded only when router_settings.enable_pre_call_checks is on. Without it, those candidates are not filtered out before the call and the provider's own error shows instead.
| Reason | The candidate was skipped because |
|---|---|
cooldown | It was in cooldown after recent failures. See reliability. |
blocked | An admin paused it on the Models + Endpoints page. |
health_check | A background health check marked it unhealthy. |
context_window | The prompt is longer than its context window. |
rpm_limit | Its rpm limit for the current minute was reached. |
unsupported_param | The request used a parameter it does not support, such as response_format, and drop_params is off. |
data_policy | It does not satisfy the request's data policy, for example a region or data retention rule. |
provider_preferences | The request's provider preferences excluded it. |
callback | A pre-call filter dropped it, for example a provider budget limit or a deployment affinity rule. |
tag | Its tags do not match the request's tags under tag routing. |
web_search | The request needs web search and the deployment does not support it. |
routing_plugin | A routing plugin narrowed the candidates and left it out. |
order | A deployment with a lower order was available. |
already_tried | This request already failed on it. |
A client cannot set routing_strategy or routing_candidate_skips in the request metadata. Values sent by the caller are removed before routing. Deployments that belong to another team are never listed, so a key cannot learn about another team's private deployments from the skip list.
Read the headers for one request
-
Send a request with
-iso curl prints the response headers, and add the opt-in header to see the skipped candidates.curl -i -X POST http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-H "x-spanway-routing-skips: true" \-d '{"model": "chat", "messages": [{"role": "user", "content": "hi"}]}' -
Read the routing headers in the output.
x-spanway-model-id: 7c1f0a2e-azure-eastusx-spanway-model-group: chatx-spanway-attempts: 1x-spanway-routing-reason: strategy=latency-based-routingx-spanway-routing-skips: [{"deployment_id":"91b2-openai-primary","model":"openai/gpt-5.6","reason":"cooldown"}] -
To look the request up later, open the Admin UI logs page at
/ui/?page=logs, click the row for the request, and open the Metadata card in the detail drawer. The JSON showsrouting_strategy,routing_presetwhen a preset applied,routing_decisionfor auto-routed requests, androuting_candidate_skipswith the same list the header carried, whether or not the client asked for the header. -
The same record is available over the API with the
x-spanway-call-idof the response.curl "http://localhost:4000/spend/logs?request_id=$CALL_ID" \-H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result
Every successful response carries x-spanway-attempts and, when a strategy made the pick, x-spanway-routing-reason. After a fallback, x-spanway-attempts is at least 2, x-spanway-attempted-fallbacks is at least 1, and the reason ends with fallback_cause=<error class>. x-spanway-routing-skips appears only when the request asked for it. The spend log row of the request holds routing_strategy, routing_preset when a preset applied, and routing_candidate_skips whenever a candidate was skipped, so the skip reasons stay available after the response is gone.
Skip records are limited to 25 per request. On a model group with more skipped candidates, the first 25 in filter order are kept. A deployment skipped for the same reason on every retry or fallback hop of one request is listed once.
Errors
This feature adds no errors. When every candidate is skipped, the request fails with the same errors as before, which name the reason that emptied the list. ContextWindowExceededError means no deployment has a large enough context window, RateLimitError means every deployment reached its rpm limit or is in cooldown, and 400 with No deployment of model ... satisfies the data policy or ... the provider preferences means a routing rule excluded every candidate. See exception mapping for the status codes.
Logs
This feature adds no operator log lines. The router's existing DEBUG lines healthy_deployments after team filter, cooldown deployments and get_available_deployment for model: ..., Selected deployment: ... show the same filtering as it happens, and All deployments in cooldown via health-check routing, bypassing cooldown filter at WARNING means the health check policy let cooled down deployments serve. None of them needs action on its own. Set SPANWAY_LOG=DEBUG to see the debug lines.
Related
Reliability explains retries, fallbacks and cooldowns. Auto routing lists the decision causes of the complexity router. Routing presets explains the preset part. Data policy routing and provider preferences explain the rules behind those skip reasons. Request headers lists the headers a client can send, and the Logs page explains the detail drawer.