Health checks
The gateway has two kinds of health endpoints. Probe endpoints (/health/liveliness and /health/readiness) tell an orchestrator whether the process is up and ready to take traffic, and do not call any provider. Model health endpoints report which deployments are healthy. /health sends a small real request to each deployment, or returns the latest background results without calling any provider when background_health_checks is on, and /health/latest and /health/history only read results already stored in the database. Service and license endpoints check integrations and the enterprise license.
A real-world scenario
A platform team runs the gateway on Kubernetes with two providers behind each model group. The liveness probe points at /health/liveliness and the readiness probe at /health/readiness, so a pod that loses its database stops receiving traffic without being killed. Background health checks run every five minutes, and an on-call engineer who gets paged opens Models + Endpoints, Health Status to see which deployment failed and the exact provider error, without sending a single real request herself. The status page and the public catalogue reuse the same stored checks.
Endpoints
| Method | Path | Summary |
|---|---|---|
| GET | /health/deployments | Live speed and rate limits per deployment |
| GET | /health/liveness | Liveness probe |
| OPTIONS | /health/liveness | Allowed methods of the liveness probe |
| GET | /health/liveliness | Liveness probe |
| OPTIONS | /health/liveliness | Allowed methods of the liveness probe |
| GET | /health/services | Send a test event to a logging or alerting integration |
| GET | /health | Check every deployment with a real request |
| GET | /health/history | Page through stored health checks |
| GET | /health/latest | Newest stored health check per model |
| GET | /health/shared-status | State of shared background health checks |
| GET | /health/license | License status without the key |
| GET | /health/readiness | Readiness probe |
| OPTIONS | /health/readiness | Allowed methods of the readiness probe |
| GET | /health/readiness/details | Readiness with cache, version and callback details |
| GET | /health/backlog | Requests in flight on this worker |
| GET | /health/drain | Drain this worker before it stops |
| POST | /health/test_connection | Test one model with the parameters you send |
Probe endpoints for Kubernetes and load balancers
/health/liveliness (also served as /health/liveness) returns 200 as soon as the server process is running. /health/readiness also checks the database connection and the shared Redis, and returns a body such as the one below. Neither endpoint needs a key, and neither calls a provider, so they are safe to hit every few seconds.
curl http://localhost:4000/health/readiness
{"status": "healthy", "db": "connected", "airgapped": false, "coordination_redis": "connected"}
When the database is unreachable ("db": "disconnected") or its lookups keep timing out ("db": "stalled"), /health/readiness answers 503 with "status": "unhealthy" in the body, so the orchestrator stops sending traffic to that pod. With general_settings.allow_requests_on_db_unavailable: true the gateway keeps serving through a database outage, so the probe stays 200 and only the body shows the database state. A gateway with no database configured reports "db": "Not connected" with 200.
coordination_redis tells you whether this worker can reach the Redis the replicas share for rate limit counters, spend tracking and locks (the coordination Redis, see Redis requirements). It helps when limits behave oddly or the website assistant answers unavailable, because you can see at a glance whether Redis is the cause. The value is connected when Redis answered a ping within one second, not_configured when the gateway has no Redis at all (normal for a single instance), and error when a Redis is configured but did not answer in time. This field is for information only. It never changes the status code, so a Redis outage alone keeps the probe at 200 and the pod stays in rotation, and the gateway falls back the way Redis requirements describes. Alert on error from your monitoring if you want to hear about it.
/health/readiness/details adds more detail for debugging and needs a key. /health/backlog reports the in-flight work of the worker that answered.
Draining a worker before it stops
GET /health/drain takes the worker out of rotation, so /health/readiness and /health/liveliness answer 503, and then waits until its in-flight requests finish or GRACEFUL_SHUTDOWN_TIMEOUT passes. It is meant for a Kubernetes preStop hook. The route needs no key, because the kubelet calls hooks without one, so it is protected by a shared token instead.
- Turn the route on with
general_settings.enable_drain_endpoint: true. While it is off the route answers404. - Set the token with
general_settings.drain_endpoint_tokenor theDRAIN_ENDPOINT_TOKENenvironment variable. The token is required. Without it every call is refused with401, because otherwise anyone who can reach the pod could take the worker out of service. - Send the same value on the
X-Drain-Tokenheader from the hook.
lifecycle:
preStop:
httpGet:
path: /health/drain
port: 4000
httpHeaders:
- name: X-Drain-Token
value: <same value as drain_endpoint_token>
Expected result: {"status": "drained", "drained_requests": 3} once the worker is idle. A wrong or missing token gets 401 Invalid or missing X-Drain-Token and changes nothing. A pod that stops without the hook is still drained by its stop signal.
Health
GET /health runs a health check against every deployment in model_list and returns two lists, healthy_endpoints and unhealthy_endpoints, with the deployment parameters (secrets removed) and the error for each failing one. Pass ?model=<model_name> to check one model group, or ?model_id=<id> to check one deployment. Because each check is a real provider call, it costs a few tokens and can take several seconds. Any key can call it. A proxy admin checks every deployment, and any other key only the deployments of the models it may call, so a team key cannot probe another team's models, and naming a model it may not call is a 403.
With background_health_checks on, GET /health calls no provider. It answers from the last background cycle, filtered to the model or deployment asked for, so the result is up to health_check_interval seconds old. For a fresh check of one model, use Run health check in the Admin UI or POST /health/test_connection.
Keys that are not proxy admins get each deployment without api_base and api_version, which would show which provider account or region a deployment talks to, and the response carries the Spanway-Health-Field-Notice header naming the removed fields. When some deployments the key may see have no model_info.id, the background answer leaves them out and adds a warnings list that says so.
curl "http://localhost:4000/health?model=claude-sonnet-5-5" -H "Authorization: Bearer $SPANWAY_API_KEY"
{
"healthy_endpoints": [{"model": "anthropic/claude-sonnet-5-5"}],
"unhealthy_endpoints": [],
"healthy_count": 1,
"unhealthy_count": 0
}
To avoid calling providers on demand, run checks in the background and read the cached results from /health/latest.
general_settings:
background_health_checks: true
health_check_interval: 300
health_check_details: false
health_check_interval is in seconds. With health_check_details: false the response leaves out deployment parameters. GET /health/latest returns the most recent stored result per deployment, as an object keyed by model id (or by model name for a deployment without an id), and GET /health/history pages through past results with limit and offset. Its total_records is the number of rows in the page you got, not the total, so keep raising offset by limit until fewer than limit rows come back. Both are open to proxy admins and admin viewers only, because they cover every model on the gateway. Old rows are deleted after maximum_health_check_retention_period.
Health check settings
| Setting | Default | What it does |
|---|---|---|
general_settings.background_health_checks | off | On, the gateway checks every deployment on a timer, so /health, the Health Status tab and health-based routing always have a recent answer. Off, checks only run when someone asks. Each check is a real provider call that costs a few tokens per deployment per cycle. |
general_settings.health_check_interval | 300 | Seconds between background cycles. Shorter spots a broken provider sooner and spends more tokens. |
general_settings.health_check_concurrency | unset (no limit) | Deployments checked at the same time in one cycle. Set it when many deployments share one provider account and checks would hit its rate limit. |
general_settings.background_health_check_model_groups | unset (all) | Only the listed model groups are checked in the background and filtered by health-based routing. |
general_settings.health_check_skip_disabled_background_models | off | On, deployments with model_info.disable_background_health_check: true are also left out of an on-demand /health. |
general_settings.health_check_details | on | Off, results only say healthy or unhealthy and leave out deployment parameters and the provider's full error text. Applied when the gateway starts. |
general_settings.use_shared_health_check | off | On, replicas take turns through Redis, so one runs each cycle and the others reuse its result. Needs Redis. Applied when the gateway starts. |
general_settings.health_check_staleness_threshold | twice the interval | Seconds after which a stored result is too old to route on. |
general_settings.health_check_ignore_transient_errors | off | On, a deployment whose check fails only with a timeout or a rate limit stays routable. |
router_settings.enable_health_check_routing | off | On, deployments the background checks mark unhealthy get no traffic. Needs background checks. |
general_settings.model_list_healthy_only | off | On, /models and /model/info hide models whose deployments are all unhealthy. Routing is not changed. |
general_settings.enable_drain_endpoint | off | Serves /health/drain, see draining a worker. |
general_settings.drain_endpoint_token, DRAIN_ENDPOINT_TOKEN | unset | The token /health/drain requires on X-Drain-Token. Without it every drain call is refused. |
general_settings.allow_public_health_readiness_details | off | On, the public /health/readiness returns the full details body, version and integrations included, to callers without a key. Leave it off on any gateway reachable from outside, because those details help an attacker. |
HEALTH_CHECK_TIMEOUT_SECONDS | 60 | Seconds one check may take before it counts as failed. model_info.health_check_timeout overrides it per deployment. |
DEFAULT_HEALTH_CHECK_INTERVAL | 300 | The interval used when health_check_interval is not set. |
DEFAULT_HEALTH_CHECK_PROMPT | test from spanway | The text a chat check sends. |
BACKGROUND_HEALTH_CHECK_MAX_TOKENS, BACKGROUND_HEALTH_CHECK_MAX_TOKENS_REASONING | unset | max_tokens for every check, or only for reasoning models. |
With more than one gateway instance, use_shared_health_check: true and Redis let one instance run the background checks and share the results with the others. GET /health/shared-status, also for proxy admins and admin viewers, shows whether sharing is on, whether Redis is reachable and which instance holds the lock.
Admin UI
The Health Status tab of Models + Endpoints shows the latest stored result for every model, with when it was checked and the error of a failing one, and runs a fresh check for one model on request, which is a real provider call. Health checks are free on every gateway.
The Background health checks card at the top of that tab edits the settings above without a config file change. A proxy admin can turn background_health_checks on or off, set health_check_interval and health_check_concurrency, limit the loop to named model groups with background_health_check_model_groups, skip opted-out deployments with health_check_skip_disabled_background_models, and hide unhealthy models from /models with model_list_healthy_only. Each card row saves through POST /config/field/update, and an empty value resets the row through POST /config/field/delete, so the config file or default applies again. Both routes are in the API reference and write an audit row for every save and reset. Saved values live in the database and take effect when the gateway next restarts. A row the config file sets is shown locked, because the file owns that key, and an admin viewer sees every row read-only.
curl -X POST "http://localhost:4000/config/field/update" \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"config_type": "general_settings", "field_name": "health_check_interval", "field_value": 120}'
Expected result: {"config_type": "general_settings", "field_name": "health_check_interval", "field_value": 120, "message": "Field health_check_interval updated"}, and the row shows In DB on the next load of the tab.
How the check request is built
The gateway sends a short random message and, for chat style modes (chat, completion, responses), sets max_tokens to 16 by default so the check stays cheap. Other modes such as embeddings, images, audio, rerank, OCR and moderation get a request of the right shape without max_tokens. You can tune each deployment in model_info.
model_info key | Effect |
|---|---|
mode | Which kind of request to send, for example embedding or audio_transcription. |
health_check_max_tokens | Explicit max_tokens for the check. |
health_check_reasoning_effort | Reasoning effort used only for checks, for example none. |
health_check_params | Extra fields merged into the check request. |
health_check_model | Model to call instead of the deployment model. |
health_check_voice | Voice used for text to speech checks. |
health_check_timeout | Seconds this deployment's check may take, instead of HEALTH_CHECK_TIMEOUT_SECONDS. |
health_check_max_tokens_reasoning, health_check_max_tokens_non_reasoning | max_tokens for the check, picked by whether the model is a reasoning model. health_check_max_tokens wins over both. |
disable_background_health_check | true keeps this deployment out of the background loop, for example a model that must never receive test traffic. |
BACKGROUND_HEALTH_CHECK_MAX_TOKENS sets a global max_tokens for checks.
Wildcard routes
A wildcard deployment such as anthropic/* has no concrete model to call, so a health check against it would fail. Set health_check_model to a real model under that prefix, and the check calls that model instead. For wildcard routes the gateway does not add max_tokens unless you set health_check_max_tokens or BACKGROUND_HEALTH_CHECK_MAX_TOKENS.
model_list:
- model_name: "anthropic/*"
spanway_params:
model: "anthropic/*"
api_key: os.environ/ANTHROPIC_API_KEY
model_info:
health_check_model: anthropic/claude-haiku-5-5
Text to speech models
Deployments with mode: audio_speech need a voice. The check uses alloy by default, which works for OpenAI voices. Set health_check_voice for providers with different voice names.
model_list:
- model_name: tts
spanway_params:
model: openai/gpt-4o-mini-tts
api_key: os.environ/OPENAI_API_KEY
model_info:
mode: audio_speech
health_check_voice: coral
Service checks
GET /health/services?service=<name> sends a test event to an integration configured on the gateway and reports whether it succeeded. Supported names include slack, slack_budget_alerts, email, webhook, ms_teams, langfuse, langfuse_otel, datadog, datadog_llm_observability, braintrust, arize, galileo, newrelic, signoz, openmeter, generic_api, pointfive and sqs. A logging integration must be in spanway_settings.success_callback, and an alerting one in general_settings.alerting, otherwise the call answers 422 and names the missing setting. The webhook, New Relic and PointFive tests send a real alert or ping, so only proxy admins may run them. Errors come back in the OpenAI error shape, {"error": {"message": ..., "type": ..., "param": null, "code": "422"}}.
License status
GET /health/license reports whether an enterprise license is active, without exposing the key. license_type is enterprise with an active license and starter without one.
{
"has_license": true,
"license_type": "enterprise",
"expiration_date": "2027-...",
"allowed_features": ["*"],
"limits": {"max_users": 100, "max_teams": 20}
}
See enterprise for how to set the license.
Step by step
-
Wire the probes. Both need no key:
curl http://localhost:4000/health/livelinesscurl http://localhost:4000/health/readinessExpected result:
"I'm alive!"and{"status": "healthy", "db": "connected", "airgapped": false, "coordination_redis": "connected"}. During a graceful shutdown both answer 503 with{"status": "shutting_down"}. -
Turn on background checks in
general_settingsas shown above, roll the gateway, and read the stored results with an admin key:curl http://localhost:4000/health/latest -H "Authorization: Bearer $SPANWAY_API_KEY"Expected result:
{"latest_health_checks": {"<model id>": {...}}, "total_models": N}with one entry per deployment, its status andchecked_at. -
Run a real check for one model group when you need it now. It calls the provider:
curl "http://localhost:4000/health?model=claude-sonnet-5-5" -H "Authorization: Bearer $SPANWAY_API_KEY"Expected result: the
healthy_endpointsandunhealthy_endpointslists above. When you named a model and none of its deployments is healthy, the status code is 503 with the same body. -
In the Admin UI open Models + Endpoints and the Health Status tab. Each model shows its last result and error, and Run health check sends a fresh check.
-
Check that a logging integration works end to end, for example Datadog:
curl "http://localhost:4000/health/services?service=datadog" -H "Authorization: Bearer $SPANWAY_API_KEY"Expected result:
{"status": "healthy", "message": "Datadog is healthy"}.
Errors
| Status | Route | Meaning | Fix |
|---|---|---|---|
503 {"status": "shutting_down"} | /health/liveliness, /health/readiness | The worker is draining after /health/drain or a stop signal. | Expected during a rollout, the orchestrator removes the pod. |
503 {"status": "unhealthy", "db": "disconnected"} or "db": "stalled" | /health/readiness, /health/readiness/details | The database is unreachable from this instance, or its lookups keep timing out. | Check DATABASE_URL and the network path. Set allow_requests_on_db_unavailable: true only if the gateway should keep serving during a database outage. |
200 with "coordination_redis": "error" | /health/readiness, /health/readiness/details | A Redis is configured but did not answer a ping within one second. Requests still flow, but shared limits, the website assistant chat and other Redis features are degraded. | Check the Redis host, password and network path, see Redis requirements. |
503 Service Unhealthy (...) | /health/readiness/details | The details could not be read. | The message names the failing part. |
401 Authentication Error, No api key passed in. | the authenticated routes | No key was sent. | Send the bearer token. |
401 Authentication Error, Only proxy admin can be used to ... | /health/latest, /health/history, /health/shared-status | These cover every model, so only proxy admins and admin viewers may read them. | Use an admin or admin viewer key. |
403 {"error": "key not allowed to health-check model <model>"} or ... model_id <id> | /health | The key may not call the model or deployment it named. | Use an admin key, or a key with the model. |
404 {"error": "Model with ID <id> not found"} | /health?model_id=... | No deployment carries that id. | Copy the id from Models + Endpoints. |
500 {"error": "Model list not initialized"} | /health | The gateway has loaded no models yet. | Retry after startup, or add models. |
403 View-only users cannot manage models. or User does not have permission to make this model call. ... | /health/test_connection | The test uses the same rule as adding a model, so view-only users and keys that are not team admins of the model's team may not run it. | Use a proxy admin key, or a team admin key with team_id in model_info. |
400 Environment variable references are not permitted in request parameters. | /health/test_connection | The body named an os.environ/ value. | Send the model name, a stored model id or spanway_credential_name instead. |
422 "<service>" is not set up on this gateway. Add it to spanway_settings.success_callback to test it. | /health/services | The logging integration is not configured. | Add it to spanway_settings.success_callback. |
422 "slack" not in proxy config: general_settings. Unable to test this. or MS_TEAMS_WEBHOOK_URL not set. Unable to test this. | /health/services | The alerting integration is not in general_settings.alerting, or its webhook is missing. | Add it to alerting and set the webhook. |
403 Only proxy admins can trigger the webhook test alert. (or the New Relic and PointFive variants) | /health/services | These tests send a real alert or ping. | Use a proxy admin key. |
500 MS Teams webhook returned status <code>: ... | /health/services | Teams refused the test message. | Check the webhook URL. |
401 Invalid or missing X-Drain-Token | /health/drain | The header is wrong or missing, or no drain token is configured. | Set drain_endpoint_token or DRAIN_ENDPOINT_TOKEN and send it on X-Drain-Token. |
404 Not Found | /health/drain | enable_drain_endpoint is not true. | Turn it on. |
500 {"error": "Database not initialized"} | /health/latest, /health/history | Stored checks need Postgres. | Set DATABASE_URL. |
500 Failed to retrieve latest health checks: ... or Failed to retrieve health check history: ... | /health/latest, /health/history | The database read failed. | Check the database connection named in the message. |
| A wildcard deployment is always unhealthy | /health, background checks | A check against anthropic/* has no concrete model. | Set health_check_model as shown above. |
Logs
| Level | Line | Meaning and action |
|---|---|---|
| INFO | background_health_check_config enabled=... shared=... interval_seconds=... | Logged at startup with the settings the loop will use. Normal. |
| INFO | background_health_check_loop_started interval_seconds=... | The background loop started. Normal. |
| INFO | Pod <id> acquired health check lock | With shared checks, this replica runs the next cycle. Normal. |
| WARNING | background_health_check_loop_overlap_detected existing_loop_active=true ... | A second loop tried to start beside a running one and was skipped. Normal after a config reload, check for duplicate startup hooks if it repeats. |
| WARNING | background_health_check_model_groups matched no deployments; groups=[...] | The listed groups match no deployment, so nothing is checked. Fix the group names. |
| WARNING | background_health_check_cycle_duration_exceeded_interval cycle_id=... duration_ms=... | One cycle took longer than health_check_interval. Raise the interval or health_check_concurrency. |
| WARNING | background_health_check_db_save_incomplete released the window lock so another pod can retry | Saving the cycle's results did not finish. Another replica retries. Check the database if it repeats. |
| WARNING | Failed to save background health checks to database: ... | The results were not stored, so /health/latest shows older rows. Check the database. |
| WARNING | Refused /health/drain because no drain token is set. ... | A drain call arrived while no token is configured. Set drain_endpoint_token or DRAIN_ENDPOINT_TOKEN. |
| ERROR | Error in shared health check, falling back to direct health check: ... | Redis did not answer, so this replica checked every deployment itself. Check Redis. |
| ERROR | Spanway Redis Cache PING: - Got exception from REDIS : ... | The readiness probe could not ping the shared Redis, so it reports "coordination_redis": "error". Repeats on every probe while Redis is down. Check Redis. |
| ERROR | Error getting latest health checks: ... or Error getting health check history: ... | The database read failed. Check the connection named. |
Related
- Status page and public model catalogue, which reuse stored checks.
- Admission control for
/health/backlog. - Production checklist for probes and graceful shutdown, and draining a worker for the
preStophook. - Alerting for being told when a deployment turns unhealthy.
- Enterprise for
/health/license.