Key and team router settings
Global router_settings in config.yaml apply to every request. Some applications need different behaviour, for example a batch job that should retry rate limits many times, or a latency sensitive service that should fall back to another model immediately. Keys and teams can carry their own router_settings, which apply only to their requests and take priority over the global settings.
When you would use this
A nightly batch job can wait, so you want it to retry rate limit errors up to eight times and fall back to a second model when the first is exhausted. The checkout service cannot wait, so you want a 20 second timeout and a single retry. You put the first set of settings on the batch job's key and the second on the checkout team, and the global settings stay as they are for everyone else.
Before you start
For a key you need the key owner, a team admin of the key's team or a proxy admin. For a team you need a proxy admin, or an organization admin with edit access to the team, because team admins may only change the team fields a proxy admin opened to them (tpm_limit, rpm_limit and max_budget), and router_settings is never one of them. GET /router/fields lists every field the router accepts with its type and description, which is what the Admin UI uses to render the form.
Fields you can set
The router_settings object on a key or team accepts the same fields the router accepts at runtime.
| Field | Effect for this key or team |
|---|---|
fallbacks, context_window_fallbacks | Fallback model groups, preferred over the global lists. |
num_retries, max_retries, timeout, retry_after | Retry count and timeouts. |
retry_policy, model_group_retry_policy | Retries per error type, globally or per model group. |
allowed_fails, cooldown_time | Cooldown thresholds. |
routing_strategy, routing_strategy_args | Strategy used to pick deployments. |
model_group_alias | Model name aliases. |
enable_tag_filtering, tag_routing_prefix | Tag routing behaviour. |
weights | Weights between deployments for simple-shuffle. |
optional_pre_call_checks | Extra pre-call checks. |
Step by step
-
Set them on a key. In the Admin UI open Virtual Keys, click + Create New Key, expand Optional Settings and then Router Settings, fill in the retries, timeout and fallbacks, and click Create Key. On an existing key the same group is on the Settings tab after Edit Settings. Over the API pass
router_settingson/key/generateor/key/update.curl -X POST http://localhost:4000/key/generate \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"key_alias": "nightly-batch","models": ["claude-sonnet-5-5", "gpt-6.1-sol"],"router_settings": {"num_retries": 6,"model_group_retry_policy": {"claude-sonnet-5-5": {"RateLimitErrorRetries": 8}},"fallbacks": [{"claude-sonnet-5-5": ["gpt-6.1-sol"]}]}}'/key/updatechanges the settings later, and sending{}ornullremoves them so the key follows the global settings again. -
Set them on a team. Open Teams, click Create Team or open a team's Settings tab and click Edit Settings, open the Router Settings section with its Loadbalancing and Fallbacks tabs, and save. Over the API pass
router_settingson/team/newor/team/update.curl -X POST http://localhost:4000/team/update \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"team_id": "team-ds", "router_settings": {"timeout": 20, "num_retries": 1}}'Team settings apply to every key of the team. When both the key and its team set a value, the key's value is used for that key.
-
Check what is stored. The key's Settings tab lists Router Settings, and the team's Settings tab does the same. Over the API
/key/infoand/team/inforeturn the overrides stored on a key or team, andGET /router/settingsreturns the global settings they override.curl "http://localhost:4000/team/info?team_id=team-ds" -H "Authorization: Bearer $SPANWAY_API_KEY" -
Watch it work. Send a request with the key and read the
x-spanway-attemptsandx-spanway-routing-reasonresponse headers, which say how many provider calls the request took and why it was routed where it was, see routing decision headers.
What you should see
A request from the batch key that hits a rate limit on claude-sonnet-5-5 is retried up to eight times and then served by gpt-6.1-sol, and x-spanway-attempts counts the tries. A request from a checkout team key gives up after 20 seconds and one retry. Keys with no override follow router_settings from the config.
Fallbacks and access
Fallback lists from the key and team are honoured together with the global lists and any fallbacks sent in the request body. With general_settings.enforce_fallback_model_access: true, a fallback is only attempted when the key, its team and its project are allowed to call the fallback model, which stops router settings from becoming a way around model restrictions.
Errors
| Error | Cause | Fix |
|---|---|---|
422 naming a field under router_settings | The field is not one the router accepts, or has the wrong type. | Check GET /router/fields for the name and type. |
| Fallback never happens | enforce_fallback_model_access is on and the key or team may not call the fallback model. | Add the fallback model to the key's and team's models. |
| Retries stop sooner than configured | The team or global num_retries is lower and the key sets none, or the error type is not retried by the retry policy. | Set num_retries or the policy on the key itself. |
403 on /key/update | The caller may not change that key. | Use the key owner, a team admin of its team or a proxy admin. |
403 Team admins on this proxy do not have permission to update 'router_settings'. ... on /team/update | Team admins cannot change a team's router settings. | Ask a proxy admin. |
Settings vanish after /key/update | The update sent router_settings: {} or null. | Send the full object again, because an empty value clears it. |
Related
- Routing for what each setting does.
- Reliability for retries, fallbacks and cooldowns.
- Routing decision headers for checking what happened to a request.
- Virtual keys and team budgets for the rest of the key and team fields.
- Router Settings page for the global settings in the Admin UI.