Skip to main content

Routing presets

A routing preset is a named, versioned bundle of the models to try, the provider preferences to apply and default generation parameters. Callers reference it by name instead of repeating the same settings in every request, and admins change it in one place with a full version history and a rollback. Presets apply to /v1/chat/completions, /v1/responses and /v1/messages, are part of the free gateway and need a connected database.

A real-world scenario​

A European customer must only be served from Azure and Bedrock regions in the EU, prefers the fastest of those, and wants a conservative temperature on every call. Instead of teaching five applications those rules, the admin saves a global preset eu-fast with the two models, provider.only set to azure and bedrock, sort: throughput and temperature: 0.2. The applications send "model": "@preset/eu-fast". When a cheaper EU region appears, the admin saves version 2 of the preset and every application picks it up within a minute. When the new region misbehaves, one click rolls back to version 1.

Step by step​

In the Admin UI​

  1. Open /ui/routing-presets as a proxy admin. Leave Scope (global or a team id) at global, or type a team id for a team preset, and click Show.
  2. Click New preset. Type the Name, for example eu-fast, and edit Configuration (JSON) so it sets at least one of models, provider and params. Click Save. A toast reads Saved @preset/eu-fast.
  3. Send a request with "model": "@preset/eu-fast" from any key the preset's models allow.
  4. To change it, click Edit on the row, adjust the JSON and click Save. The Version column increases and requests use the new version within a minute.
  5. Click Versions to see every version with who saved it and when, and Roll back on an older one to make it the newest again. Delete hides the preset and all its versions, and requests that reference it start failing with a 404.

With curl​

curl -X POST http://localhost:4000/routing/presets \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"slug": "eu-fast",
"scope": "global",
"config": {
"models": ["gpt-5.6", "claude-sonnet-5-5"],
"provider": {"only": ["azure", "bedrock"], "sort": "throughput"},
"params": {"temperature": 0.2, "max_tokens": 2000}
}
}'
FieldWhat it does
slugThe name. Lowercase letters, digits, ., _ and -, up to 64 characters.
scopeglobal for the whole gateway, or a team id for that team's members.
config.modelsThe model to call first, then up to seven fallbacks.
config.providerA provider preferences object.
config.paramsDefaults for temperature, top_p and max_tokens. On /v1/responses, max_tokens fills max_output_tokens. They don't count as parameters the client asked for under require_parameters.

At least one of models, provider and params is needed. Posting the same slug and scope again saves a new version.

Use the preset, then read its history and roll back.

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "@preset/eu-fast", "messages": [{"role": "user", "content": "hi"}]}'

curl "http://localhost:4000/routing/presets/eu-fast/versions?scope=global" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"

curl -X POST http://localhost:4000/routing/presets/eu-fast/rollback \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"scope": "global", "version": 2}'

Expected result​

Saving answers with the new version.

{
"scope": "global",
"slug": "eu-fast",
"version": 3,
"config": {
"models": ["gpt-5.6", "claude-sonnet-5-5"],
"provider": {"only": ["azure", "bedrock"], "sort": "throughput"},
"params": {"temperature": 0.2, "max_tokens": 2000}
},
"created_by": "admin@example.com",
"created_at": "2026-11-21T09:12:44.102Z"
}

The chat request is answered by gpt-5.6 on Azure or Bedrock, whichever has the higher measured throughput, with claude-sonnet-5-5 as the fallback and temperature: 0.2 applied unless the request sets its own. The request metadata and the spend log record routing_preset: eu-fast@3, so you can see which version served each request. The versions call lists every version newest first, and a rollback answers with a new version, 4, that carries the configuration of version 2. Every write is recorded in the audit log with the configuration before and after.

Use a preset​

Any of these three forms works.

  • "model": "@preset/eu-fast" calls the preset's first model, with the rest as fallbacks.
  • "model": "claude-sonnet-5-5@preset/eu-fast" calls claude-sonnet-5-5 with the preset's preferences and parameters, and the preset's other models as fallbacks.
  • "preset": "@preset/eu-fast" next to "model" does the same as the second form. A preset value without the @preset/ prefix is ignored.

The request wins over the preset. Parameters the request sets are kept, fallbacks the request sends replace the preset's, and a model suffix or provider object in the request is applied after the preset's provider preferences, so "model": "gpt-5.6:floor@preset/eu-fast" sorts by price even though the preset sorts by throughput.

A preset can only narrow what the caller's key and team allow. Its models go through the usual key and team model checks, and its provider preferences sit after the team and key defaults, so a preset can't reach a provider the key excludes. A client can't set the routing_preset metadata field itself.

Team and global presets​

A request first looks for the preset in its key's team and then in the global scope. To keep a team from quietly replacing a preset the gateway relies on, a team preset can't use the name of a global preset, and a global preset can't take a name a team already uses. Both cases answer 409, and the check holds even when two admins save at the same moment.

Only proxy admins can create, change or delete global presets. Team presets can be changed by proxy admins and by admins of that team. Read only roles can read presets but are refused every POST and DELETE on the preset paths, with the route check messages listed under Errors. Anyone can read global presets, and team presets are readable by that team's members. The Admin UI shows the create, edit, delete and roll back buttons only for scopes you may change.

MethodPathSummary
GET/routing/presetsList the routing presets of a scope
POST/routing/presetsCreate a routing preset or save a new version
GET/routing/presets/{slug}Read a routing preset
DELETE/routing/presets/{slug}Delete a routing preset
GET/routing/presets/{slug}/versionsList the versions of a routing preset
POST/routing/presets/{slug}/rollbackRoll a routing preset back

Limits​

  • Each replica caches a looked up preset for 60 seconds and a missing one for 5 seconds, so a change can take up to a minute to reach every replica.
  • Presets don't carry system prompts or tools yet. Use prompt management for system prompts.
  • Presets need a connected database. Without one, a request that references @preset/... fails with a 500, while a bare preset value and requests to other endpoints are unaffected.

Errors​

Errors from the management routes under /routing/presets:

What you seeWhyFix
409 A global preset is named 'eu-fast', so a team preset cannot shadow itThe name is taken in the other scope.Pick another name for the team preset.
409 Team presets already use the name 'eu-fast', so a global preset cannot take itA team already has a preset with that name.Pick another global name, or delete the team preset.
403 Only proxy admins can change global routing presetsA team admin or internal user wrote to the global scope.Use a proxy admin key, or write a team preset.
403 Only proxy admins or admins of team '<team>' can change its routing presetsThe caller is not an admin of that team.Ask a team admin or a proxy admin.
403 user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /routing/presetsAn admin viewer tried to write. The route check refuses it before the preset code runs, so detail is plain text.Use a proxy admin key.
403 Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/routing/presets. ...An internal viewer tried to write.Use a key with a writing role.
403 You cannot read routing presets of scope '<team>'The caller is not a member of that team.Read your own team's presets, or ask a proxy admin.
404 No routing preset 'eu-fast' in scope 'global'Read or delete of a preset that was deleted or never created in that scope.Check the name and the scope.
404 Routing preset 'eu-fast' in scope 'global' has no version 9A rollback named a version that does not exist.Pick a version from Versions.
422 on saveslug breaks the naming rule, or config sets none of models, provider and params.Fix the name, and set at least one section.
500 No database connectedPresets live in the database.Connect a database.

Errors on inference requests that reference a preset:

What you seeWhyFix
400 '@preset/EU fast' is not a valid preset reference. Preset names use lowercase letters, digits, '.', '_' and '-'The name after @preset/ breaks the naming rule.Use the preset name exactly as saved.
400 Preset 'eu-tuning' lists no models, so the request must name one, for example 'my-model@preset/eu-tuning'The preset only carries provider or params.Send "model": "<model>@preset/<name>".
404 No routing preset '@preset/eu-fast'No preset with that name in the key's team or the global scope.Create it, or check the key's team.
500 Routing presets need a connected databaseThe request references a preset and the gateway has no database.Connect a database.
A change is not visible to every caller for up to a minuteReplicas cache presets for 60 seconds.Wait, or restart replicas when a change is urgent.

Logs​

Presets write no operator log line of their own. The preset and version that served a request show in the x-spanway-routing-reason response header as preset=eu-fast@3 and in the spend log metadata as routing_preset, and every write, rollback and delete writes an audit row with the configuration before and after.

Promote, test and automate presets​

  • Environments promote global presets from one gateway to another as the RoutingPreset kind. Each promoted change writes an audit row that carries the plan id.
  • The request inspector resolves @preset/... in a dry run, so you can see the model, fallbacks and parameters a preset gives a request before sending it.
  • The admin MCP server offers tools to list and read presets and their versions and to roll one back, such as list_routing_presets and rollback_routing_preset.