Skip to main content

Fallback Management API

This page documents the 3 gateway endpoints tagged Fallback Management 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
POST/fallbackSet the fallbacks of one model
GET/fallback/{model}Read the fallbacks of one model
DELETE/fallback/{model}Remove the fallbacks of one model

Endpoints​

POST /fallback​

Set the fallbacks of one model

Create or replace the fallback list of one model without sending the whole router settings. The models are tried in order once every retry on the primary model has failed. fallback_type general covers any error, context_window prompts too long for the model and content_policy provider content filter refusals. Every model named must exist on the gateway and a model cannot be its own fallback. The list is saved in the router settings the Fallbacks tab edits, applied at once and written to the audit log. Only the stored router settings are rewritten, so values from the config file never reach the database, and a list the config file sets is refused with a 400 because the file would win again on the next restart.

Request body (application/json, schema FallbackCreateRequest):

FieldTypeRequiredDescription
modelstringYesThe model name to configure fallbacks for (e.g., 'gpt-3.5-turbo')
fallback_modelsarray of stringYesList of fallback model names in order of priority
fallback_typeenum: "general", "context_window", "content_policy"NoType of fallback: 'general' (default), 'context_window', or 'content_policy'

Example request:

curl -X POST "http://localhost:4000/fallback" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"fallback_models": [
"gpt-6.1-sol"
],
"fallback_type": "general"
}'

Responses:

StatusDescriptionBody
200The saved fallback list, with whether it was created or updated.application/json FallbackResponse
400Invalid fallback models: ['gpt-missing'] or Model 'claude-sonnet-5-5' cannot be its own fallback or Database storage not enabled. Set 'STORE_MODEL_IN_DB=True' in your environment to use this feature. or router_settings key 'fallbacks' is set in the config file and cannot be changed here.application/json ErrorDetail
401No valid key was sent, or the key belongs to someone who is not a proxy adminapplication/json ProxyError
403An admin viewer tried to change something, and admin viewers can only readapplication/json ProxyError
404Model 'claude-sonnet-5-5' not found in routerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Router not initializedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
modelstringYesThe model name
fallback_modelsarray of stringYesList of fallback model names
fallback_typestringYesType of fallback
messagestringYesSuccess message

GET /fallback/{model}​

Read the fallbacks of one model

Return the fallback list of one model for the given fallback_type, as the router applies it right now, whether it came from the config file, the Fallbacks tab or POST /fallback. A model with no fallbacks of that type is a 404.

Parameters:

NameInTypeRequiredDescription
modelpathstringYes
fallback_typequeryenum: "general", "context_window", "content_policy"No

Example request:

curl -X GET "http://localhost:4000/fallback/model-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The fallback list the router applies right now.application/json FallbackGetResponse
401No valid key was sent, or the key belongs to someone who is not a proxy adminapplication/json ProxyError
404No general fallbacks configured for model 'claude-sonnet-5-5'application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Router not initializedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
modelstringYesThe model name
fallback_modelsarray of stringYesList of fallback model names
fallback_typestringYesType of fallback

DELETE /fallback/{model}​

Remove the fallbacks of one model

Delete the stored fallback list of one model for the given fallback_type. The router stops falling back for that model at once and the change is written to the audit log. Needs STORE_MODEL_IN_DB=True, and a list the config file sets is refused with a 400.

Parameters:

NameInTypeRequiredDescription
modelpathstringYes
fallback_typequeryenum: "general", "context_window", "content_policy"No

Example request:

curl -X DELETE "http://localhost:4000/fallback/model-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The fallback list was removed.application/json FallbackDeleteResponse
400Database storage not enabled. Set 'STORE_MODEL_IN_DB=True' in your environment to use this feature. or router_settings key 'fallbacks' is set in the config file and cannot be changed here.application/json ErrorDetail
401No valid key was sent, or the key belongs to someone who is not a proxy adminapplication/json ProxyError
403An admin viewer tried to change something, and admin viewers can only readapplication/json ProxyError
404No general fallbacks configured for model 'claude-sonnet-5-5'application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Router not initializedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
modelstringYesThe model name
fallback_typestringYesType of fallback
messagestringYesSuccess message