Skip to main content

Routing presets API

This page documents the 10 gateway endpoints tagged routing presets in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

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
GET/routing/tier_policiesList the budget tier policies
GET/routing/tier_policies/{scope_type}/{scope_id}Read a budget tier policy
PUT/routing/tier_policies/{scope_type}/{scope_id}Assign a budget tier policy
DELETE/routing/tier_policies/{scope_type}/{scope_id}Remove a budget tier policy

Endpoints​

GET /routing/presets​

List the routing presets of a scope

List the latest version of every routing preset in a scope, global or a team id.

Parameters:

NameInTypeRequiredDescription
scopequerystringNo

Example request:

curl -X GET "http://localhost:4000/routing/presets" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Preset versions, newest first.application/json RoutingPresetList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read presets of that scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
presetsarray of RoutingPresetVersionYesPresets

POST /routing/presets​

Create a routing preset or save a new version

Create a routing preset or save a new version of it. Global presets need a proxy admin, team presets a proxy admin or an admin of that team. A team preset cannot reuse a global preset's name. Requests reference the preset as @preset/<slug> and always get the newest version.

Request body (application/json, schema RoutingPresetWrite):

FieldTypeRequiredDescription
slugstringYesSlug
scopestringNoScope
configPresetConfigYes

Example request:

curl -X POST "http://localhost:4000/routing/presets" \
-H "Authorization: Bearer $SPANWAY_API_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
}
}
}'

Responses:

StatusDescriptionBody
200The newest version of the preset.application/json RoutingPresetVersion
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not change presets of that scope. Read-only roles are refused by the route check with a plain text detailapplication/json ErrorDetail
409The name is taken by the other scope, global or teamapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
scopestringYesScope
slugstringYesSlug
versionintegerYesVersion
configPresetConfigYes
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At

GET /routing/presets/{slug}​

Read a routing preset

Read the latest version of a routing preset in a scope.

Parameters:

NameInTypeRequiredDescription
slugpathstringYes
scopequerystringNo

Example request:

curl -X GET "http://localhost:4000/routing/presets/slug-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The newest version of the preset.application/json RoutingPresetVersion
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read presets of that scopeapplication/json ErrorDetail
404No preset with that name exists in the scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
scopestringYesScope
slugstringYesSlug
versionintegerYesVersion
configPresetConfigYes
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At

DELETE /routing/presets/{slug}​

Delete a routing preset

Delete a routing preset and hide its version history. Requests that reference it start failing with a 404 once each replica's preset cache expires.

Parameters:

NameInTypeRequiredDescription
slugpathstringYes
scopequerystringNo

Example request:

curl -X DELETE "http://localhost:4000/routing/presets/slug-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The preset and how many versions were hidden.application/json RoutingPresetDeleted
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not change presets of that scope. Read-only roles are refused by the route check with a plain text detailapplication/json ErrorDetail
404No preset with that name exists in the scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
scopestringYesScope
slugstringYesSlug
deleted_versionsintegerYesDeleted Versions

GET /routing/presets/{slug}/versions​

List the versions of a routing preset

List every version of a routing preset, newest first, with who saved each one and when.

Parameters:

NameInTypeRequiredDescription
slugpathstringYes
scopequerystringNo

Example request:

curl -X GET "http://localhost:4000/routing/presets/slug-123/versions" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Preset versions, newest first.application/json RoutingPresetList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read presets of that scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
presetsarray of RoutingPresetVersionYesPresets

POST /routing/presets/{slug}/rollback​

Roll a routing preset back

Save an older version of a routing preset again as its newest version, so history is kept and requests pick the restored configuration up within the preset cache lifetime.

Parameters:

NameInTypeRequiredDescription
slugpathstringYes

Request body (application/json, schema RoutingPresetRollback):

FieldTypeRequiredDescription
scopestringNoScope
versionintegerYesVersion

Example request:

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

Responses:

StatusDescriptionBody
200The newest version of the preset.application/json RoutingPresetVersion
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not change presets of that scope. Read-only roles are refused by the route check with a plain text detailapplication/json ErrorDetail
404The preset has no such versionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Presets need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
scopestringYesScope
slugstringYesSlug
versionintegerYesVersion
configPresetConfigYes
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At

GET /routing/tier_policies​

List the budget tier policies

List every budget tier policy with the share of its team or organization budget used and the tier that share selects. Only proxy admins and admin viewers can list them.

Example request:

curl -X GET "http://localhost:4000/routing/tier_policies" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Every policy with its live budget tier.application/json TierPolicyList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read that policyapplication/json ErrorDetail
500Budget tier policies need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policiesarray of TierPolicyStatusYesPolicies

GET /routing/tier_policies/{scope_type}/{scope_id}​

Read a budget tier policy

Read the budget tier policy of one team or organization, with the share of its budget used and the tier that share selects right now.

Parameters:

NameInTypeRequiredDescription
scope_typepathenum: "team", "organization"Yesteam or organization
scope_idpathstringYesThe team id or organization id

Example request:

curl -X GET "http://localhost:4000/routing/tier_policies/scope_type-123/scope_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The policy, the share of the budget used and the tier that share selects.application/json TierPolicyStatus
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read that policyapplication/json ErrorDetail
404No policy is assigned to that team or organizationapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Budget tier policies need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policyTierPolicyYes
budget_used_percentnumber or nullYesShare of this team's or organization's own budget used, in percent. Empty without a budget
budget_tierenum: "economy", "balanced", "frontier"YesThe tier the budget used right now selects

PUT /routing/tier_policies/{scope_type}/{scope_id}​

Assign a budget tier policy

Assign or replace the budget tier policy of a team or organization. Each tier names a routing preset, and requests that use model @tier move to a cheaper preset as the budget used crosses each shift percentage. Team policies need a proxy admin or an admin of that team, organization policies a proxy admin. A team preset may be used by a team policy, an organization policy can only use global presets.

Parameters:

NameInTypeRequiredDescription
scope_typepathenum: "team", "organization"Yesteam or organization
scope_idpathstringYesThe team id or organization id

Request body (application/json, schema TierPolicyWrite):

FieldTypeRequiredDescription
configTierPolicyConfigYes

Example request:

curl -X PUT "http://localhost:4000/routing/tier_policies/scope_type-123/scope_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"config": {
"presets": {
"frontier": "frontier-models",
"balanced": "balanced-models",
"economy": "economy-models"
},
"default_tier": "frontier",
"shifts": [
{
"at_percent": 75,
"tier": "balanced"
},
{
"at_percent": 90,
"tier": "economy"
}
]
}
}'

Responses:

StatusDescriptionBody
200The policy, the share of the budget used and the tier that share selects.application/json TierPolicyStatus
400A tier names a routing preset that the scope cannot useapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not change the policy of that team or organization. Read-only roles are refused by the route check with a plain text detailapplication/json ErrorDetail
404The team or organization does not existapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Budget tier policies need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policyTierPolicyYes
budget_used_percentnumber or nullYesShare of this team's or organization's own budget used, in percent. Empty without a budget
budget_tierenum: "economy", "balanced", "frontier"YesThe tier the budget used right now selects

DELETE /routing/tier_policies/{scope_type}/{scope_id}​

Remove a budget tier policy

Remove the budget tier policy of a team or organization. Requests that use model @tier start failing with a 404, or fall through to the organization policy, once each replica's 30 second cache expires.

Parameters:

NameInTypeRequiredDescription
scope_typepathenum: "team", "organization"Yesteam or organization
scope_idpathstringYesThe team id or organization id

Example request:

curl -X DELETE "http://localhost:4000/routing/tier_policies/scope_type-123/scope_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The policy that was removed.application/json TierPolicyDeleted
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not change the policy of that team or organization. Read-only roles are refused by the route check with a plain text detailapplication/json ErrorDetail
404No policy is assigned to that team or organizationapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Budget tier policies need a connected databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
scope_typeenum: "team", "organization"YesScope Type
scope_idstringYesScope Id