Reliability
Providers have outages, rate limits and slow periods, and a gateway is the right place to absorb them so applications do not have to. This page shows the reliability layers the gateway offers, how they work together and how to set them up from the Admin UI or the config file. Each layer is explained in detail on its own page, and all of them are part of the free gateway.
A real-world scenario
An internal assistant serves two thousand people through claude-sonnet-5-5. One Monday the Anthropic API starts timing out for a few minutes at a time. With the configuration below, a slow call is cut off after 30 seconds without a first token and retried on Bedrock, Anthropic is rested for 30 seconds once more than half of its calls in a minute fail, and when Bedrock is overloaded too the request goes to gpt-6.1-sol. Redis keeps the cooldowns and rate limit counters the same on every gateway replica, and the health checker spots the broken deployment before most users do. The support channel stays quiet.
Step by step
In the Admin UI
- Open
/ui/router-settingsas a proxy admin and pick the Loadbalancing tab. - Pick the High availability profile. It fills in
least-busy, 3 retries, 1 allowed fail, a 60 second cooldown, a retry delay of 1 second and turns pre-call checks on. Nothing is saved yet, and the form shows what would change. - Adjust Timeout, Number of Retries, Allowed Fails and Cooldown Time under Reliability & Retries if you need other values, then click Save Changes. These apply to running traffic at once. Settings whose help text says they apply at the next start, such as Default Fallbacks and Allowed Fails Policy, are saved and take effect after a restart.
- Pick the Fallbacks tab, click Add Fallbacks, set the Primary Model to
claude-sonnet-5-5and the Fallback Chain togpt-6.1-sol, and click Save All Configurations. - Open
/ui/models-and-endpoints, pick Health Status and turn on background health checks, or setbackground_health_checks: trueingeneral_settings. Deployments that fail their check show here. - Open
/ui/caching, pick Coordination Redis, fill in the Redis the replicas should share, click Test Connection and then Save Changes, and restart the gateway.
With curl
The same configuration in config.yaml.
model_list:
- model_name: claude-sonnet-5-5
spanway_params:
model: anthropic/claude-sonnet-5-5
api_key: os.environ/ANTHROPIC_API_KEY
timeout: 120
stream_timeout: 30
- model_name: claude-sonnet-5-5
spanway_params:
model: bedrock/us.anthropic.claude-sonnet-5-5
aws_region_name: us-east-1
timeout: 120
stream_timeout: 30
- model_name: gpt-6.1-sol
spanway_params:
model: openai/gpt-6.1-sol
api_key: os.environ/OPENAI_API_KEY
router_settings:
routing_strategy: simple-shuffle
num_retries: 2
cooldown_time: 30
fallbacks:
- claude-sonnet-5-5: ["gpt-6.1-sol"]
optional_pre_call_checks: ["enforce_model_rate_limits"]
redis_host: os.environ/REDIS_HOST
redis_port: os.environ/REDIS_PORT
redis_password: os.environ/REDIS_PASSWORD
general_settings:
background_health_checks: true
health_check_interval: 300
Set one model's fallbacks from a script instead of the whole file.
curl -X POST http://localhost:4000/fallback \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "fallback_models": ["gpt-6.1-sol"], "fallback_type": "general"}'
Send a request and watch the headers.
curl -i -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Summarise this ticket"}]}'
Expected result
A request for claude-sonnet-5-5 first goes to Anthropic or Bedrock. A rate limit or timeout is retried on the other deployment, a deployment that keeps failing is cooled down, and if both fail the request moves to gpt-6.1-sol. The POST /fallback call answers 200 with "message": "Fallback configuration created successfully", and the new chain shows on the Fallbacks tab at once.
Every response carries x-spanway-model-id with the deployment that answered, x-spanway-attempted-retries and x-spanway-attempted-fallbacks with how many were needed, and x-spanway-routing-reason with why the deployment was picked. The spend log row keeps the routing strategy, the routing preset, the auto router decision and the candidates the router skipped, see routing decision headers. The Admin UI has no cooldown list. A 429 No deployments available for selected model names the deployments in cooldown, the Prometheus metric spanway_deployment_cooled_down counts cooldowns per deployment, and alerting can notify you about outages, slow responses and cooldowns. Models + Endpoints, Health Status shows health check results, which are a separate signal.
The layers
| Layer | Setting | What it does |
|---|---|---|
| Multiple deployments | several model_list entries with one model_name | Spreads load across accounts, regions or providers. |
| Retries | num_retries, retry_policy | Retries transient errors on another deployment of the same group. |
| Cooldowns | allowed_fails, cooldown_time | Takes a failing deployment out of rotation for a short time. |
| Fallbacks | fallbacks, context_window_fallbacks, content_policy_fallbacks | Moves the request to another model group. |
| Timeouts | timeout, stream_timeout | Stops waiting for a slow provider so a retry can start. |
| Health checks | background_health_checks | Finds broken deployments before users hit them, see health checks. |
| Pre-call checks | optional_pre_call_checks | Filters deployments before the call, for example by context window or rate limit headroom. |
Profiles on the Loadbalancing tab
Picking a profile only fills in the form and shows what would change, and nothing is saved until you press Save Changes. A profile only sets the fields it lists, so your other settings stay as they are.
| Profile | Routing strategy | Settings it fills in | When to use it |
|---|---|---|---|
| Balanced | simple-shuffle | num_retries: 2, allowed_fails: 3, cooldown_time: 30, pre-call checks on | A sensible default that spreads traffic evenly. Its allowed_fails: 3 is the default, so the built-in error rate rule below decides cooldowns. |
| Low latency | latency-based-routing | num_retries: 1, timeout: 30, allowed_fails: 2, cooldown_time: 15 | Interactive apps that would rather fail fast than wait on a slow deployment. |
| Cost saver | cost-based-routing | num_retries: 2, pre-call checks on | Batch or background work where the cheapest deployment per token should win. |
| High availability | least-busy | num_retries: 3, allowed_fails: 1, cooldown_time: 60, retry_after: 1, pre-call checks on | Traffic that must keep flowing through provider trouble. |
Cooldowns
A cooldown takes a failing deployment out of rotation for cooldown_time seconds so callers stop waiting on it. Two rules decide when that happens.
- While
allowed_failsis left at its default of3and noallowed_fails_policyis set, the built-in error rate rule applies. A deployment is paused on a single429when its group has other deployments, once more than half of its calls in the current minute failed and it served at least 5 calls that minute, once every one of at least 1,000 calls in the minute failed, or on any error that is not worth retrying. A group with only one deployment is not paused by the error rate, so its only deployment keeps getting traffic. - Any other
allowed_fails, or anallowed_fails_policy, switches to counting. The deployment is paused once its failures inside onecooldown_timewindow go over the number, soallowed_fails: 1pauses on the second failure and0on the first.
Most 4xx errors never cause a cooldown, because the request was wrong rather than the deployment. The exceptions are 401, 402, 404, 408 and 429. disable_cooldowns: true turns cooldowns off. With Redis, the counters are shared by every replica.
| Setting or variable | Default | What it does |
|---|---|---|
cooldown_time, DEFAULT_COOLDOWN_TIME_SECONDS | 5 | Seconds a paused deployment gets no traffic, and the counting window. |
allowed_fails, DEFAULT_ALLOWED_FAILS | 3 | At 3, the error rate rule above. Any other value, the counting rule. |
DEFAULT_FAILURE_THRESHOLD_PERCENT | 0.5 | Share of failed calls in a minute that pauses a deployment under the error rate rule. |
DEFAULT_FAILURE_THRESHOLD_MINIMUM_REQUESTS | 5 | Calls a deployment must serve in the minute before the error rate counts. |
SINGLE_DEPLOYMENT_TRAFFIC_FAILURE_THRESHOLD | 1000 | Calls in a minute, all failed, that pause a deployment even when it is alone in its group. |
DEFAULT_COOLDOWN_REDIS_READ_INTERVAL_SECONDS | 1 | How often a replica reads the shared cooldown list from Redis. |
max_fallbacks, ROUTER_MAX_FALLBACKS | 5 | Most fallback groups one request may try. |
enable_weighted_failover | false | With simple-shuffle, retries a failed call on the group's other deployments before any fallback. |
timeout, REQUEST_TIMEOUT | 6000 | Seconds a call may run before it counts as a failure. |
The Test fallback button on the Fallbacks tab sends a request with mock_testing_fallbacks: true, which makes the primary model fail on purpose so you can see the fallback answer. Any client may send the same field to test a chain.
Pre-call checks
optional_pre_call_checks adds filters that run before a deployment is chosen. enforce_model_rate_limits skips deployments that are at their rpm or tpm, prompt_caching prefers the deployment that served the previous turn so provider prompt caches stay warm, session_affinity and deployment_affinity keep a session on one deployment, responses_api_deployment_check keeps Responses API follow-up calls on the deployment that holds the response, and router_budget_limiting applies provider budgets.
Client disconnects and overload
general_settings.cancel_on_disconnect cancels the upstream call when the client goes away, which frees capacity on self-hosted backends. global_max_parallel_requests and max_queued_requests_per_worker protect the gateway itself from overload by limiting concurrency and the waiting queue.
When limits cannot be verified
Rate limits and budgets fail closed by default. When Redis is configured but a rate limit counter cannot be read or updated, or a key, team, user, org or model budget cannot be verified because Redis or the database is unavailable, the request gets a 503 instead of being admitted past the limit. Set fail_closed_rate_limit_enforcement: false or fail_closed_budget_enforcement: false in general_settings to keep serving during an outage instead. Redis requirements describes both settings.
Errors
| What you see | Why | Fix |
|---|---|---|
429 No deployments available for selected model | Every deployment of the group is in cooldown or at its limits. | Add a deployment, raise rpm and tpm, shorten cooldown_time or raise allowed_fails. |
408 or Timeout errors after exactly timeout seconds | The provider is slower than your timeout. | Raise timeout for long outputs, and rely on stream_timeout to catch stalled streams instead. |
503 saying counters or budgets could not be verified | Redis or the database is unreachable and the gateway fails closed. | Fix the Redis connection on the Coordination Redis tab, or set the two fail_closed_* settings to false to serve during the outage. |
| Fallback never fires | Retries on the same group are exhausted first, and the error type has its own list. Context window and content policy errors only use their own fallback lists. | Set context_window_fallbacks or content_policy_fallbacks as well, or lower num_retries. |
| Different replicas disagree about cooldowns | No shared Redis, so each replica tracks failures on its own. | Configure the coordination Redis. |
Failed to update router settings in the Admin UI | The gateway refuses settings owned by config.yaml or values it does not support. | Change them in the file, or remove them from the file so the Admin UI owns them. |
| A deployment is never cooled down although it fails | Its group has only one deployment, or the errors are 4xx errors that do not cause a cooldown. | Add a second deployment, or set a non-default allowed_fails to count failures. |
| The primary model's error comes back although a fallback is set | enforce_fallback_model_access is on and the calling key may not use the fallback model, so the fallback was skipped. | Add the fallback model to the key or team. |
Logs
| Level | Line | Meaning and action |
|---|---|---|
| INFO | Fallback configured: <model> -> [<models>] (type: general) | A POST /fallback changed a fallback list. Normal. |
| INFO | Fallback deleted: <model> (type: general) | A DELETE /fallback removed one. Normal. |
| ERROR | Error creating fallback: ... or Error deleting fallback: ... | The change was not saved. The message names the cause, usually the database. |
| WARNING | allowed_fails counter fell back to this worker's in-memory count: ... | Redis did not answer, so this replica counts failures on its own until it is back. Check the coordination Redis. |
Audit
Every POST /fallback and DELETE /fallback/{model} writes an audit row on Spanway_Config with object id router_settings.fallbacks (or context_window_fallbacks, content_policy_fallbacks), the key that made the change and the lists before and after. Saves on the Router Settings page write a router_settings row with the settings before and after. See audit logs.
Related
- Routing, load balancing and fallbacks explains each setting in detail.
- Fallback management API changes one model's fallbacks from a script.
- Health checks and alerting watch deployments for you.
- Routing decision headers explains
x-spanway-routing-reason,x-spanway-attempted-retriesand the opt-inx-spanway-routing-skips. - Redis requirements covers the shared state behind cooldowns and limits.
- Router Settings page documents every control named above.