Production checklist
The defaults are tuned for a quick local start. Work through these steps before you put real traffic on the gateway. Each step names the exact setting the gateway reads.
A real-world scenario
A platform team has run the gateway on one container for a pilot and now has to serve the whole company. Before the launch they move the config into Git with every secret as an os.environ/NAME reference, generate a real master key and a separate salt key and put both in the secret store, connect a managed Postgres, run three containers with four workers each behind a load balancer, add Redis so rate limits hold across the three, set a 30 day spend log retention, turn the interactive API docs off and wire the Kubernetes probes to the health routes. On launch day the checklist is the runbook, and six months later a new engineer can read why each setting is there.
1. Use a config file and keep it in version control
Run the gateway with --config or CONFIG_FILE_PATH, and check the file into your deployment repository without secrets. Reference every secret with os.environ/NAME or a secret manager. Run the image with --config config.yaml --validate_config in CI, as shown in config files, so a broken file never reaches production.
2. Set a strong master key
The gateway refuses to start when SPANWAY_MASTER_KEY (or general_settings.master_key) is unset, empty, or a publicly known example value. Generate one with openssl rand -hex 32, prefix it with sk-, and store it in your secret store. Use the master key only for administration and give applications virtual keys. The SPANWAY_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY override exists for local development only.
3. Connect Postgres
Keys, users, teams, budgets and spend logs live in Postgres. Set DATABASE_URL. Schema migrations run at startup, before the server accepts traffic, so give the first boot after an upgrade enough time. Size the pool with general_settings.database_connection_pool_limit per worker, and use DATABASE_URL_READ_REPLICA to send read-only queries to a replica. For AWS RDS IAM auth use --iam_token_db_auth, and for Azure Database for PostgreSQL use --azure_postgresql_auth.
4. Run several workers and instances
The gateway starts one worker by default. Set --num_workers to the number of CPU cores you give each container, and run at least two containers behind a load balancer. Use --max_requests_before_restart to recycle workers periodically if your workload leaks memory in third-party libraries.
If you use the workflow runner, run its steps on separate containers started with --workflow_worker and set SPANWAY_WORKFLOW_RUNNER_ROLE=producer on the gateway containers, so long agent runs never take CPU from inference. See queue mode and workers.
5. Set SPANWAY_SALT_KEY
Provider credentials and other secrets that you add through the Admin UI or the API are encrypted before they are written to the database. The encryption key is derived from SPANWAY_SALT_KEY. If the salt key is not set, the gateway falls back to the master key, which means rotating the master key later would also require re-encrypting every stored secret. Set a separate, long random salt key on day one and never change it.
export SPANWAY_SALT_KEY="$(openssl rand -hex 32)"
New writes use XSalsa20-Poly1305 by default. Set general_settings.encryption_algorithm: aes-256-gcm to write new values with AES-256-GCM. Reads detect the format of each stored value, so switching the setting never strands existing data. Keep the salt key in your secret store and make sure every instance has the same value, otherwise one instance cannot read secrets written by another.
Values already stored stay in the old format until you re-encrypt them. Proxy admins can do this from the Credential Encryption tab in Admin Settings, which checks how many legacy values remain, runs a dry run, and runs the migration after a confirmation. The same steps are available from the CLI with spanwayctl encryption migrate. The migration needs the salt key or master key set and encryption_algorithm: aes-256-gcm in place, and returns a 400 with the reason when either is missing.
6. Add Redis for more than one instance
Rate limits, router cooldowns, cached keys and spend counters are shared through Redis when several instances run. Redis is required for exact limits across replicas. Without Redis each instance enforces limits on its own, which lets traffic exceed limits by a factor of the instance count, and the gateway logs a warning at startup saying so. See Redis requirements. When Redis is configured but cannot be reached, the gateway rejects requests that carry a rate limit or session limit with a 503 by default, so limits are never silently exceeded. Set general_settings.fail_closed_rate_limit_enforcement: false if you prefer to keep serving with per-instance limits during a Redis outage.
7. Control what is stored and for how long
Request and response bodies are not stored in spend logs by default. Turn that on deliberately with store_prompts_in_spend_logs, which also decides whether Lens and agent and workflow runs keep content, as What Spanway stores describes. Spend log rows are written in batches every PROXY_BATCH_WRITE_AT seconds (default 10). Set maximum_spend_logs_retention_period, for example 30d, so the spend log table does not grow without limit. Enterprise deployments can manage retention per data category from the compliance page.
8. Lock down the API surface
The interactive API explorer, the OpenAPI document and the route list answer 404 to anyone who has not signed in, see API docs and build details. Remove the explorer for everyone with NO_DOCS=true, or move it with DOCS_URL. Set DISABLE_ADMIN_UI=true on instances that only serve inference. Limit request size with general_settings.max_request_size_mb. Configure single sign-on for the Admin UI, see Admin UI SSO. Once every address of the gateway's domain is served over HTTPS, set SPANWAY_ENABLE_HSTS=true so browsers refuse plain HTTP to it. The other browser protection headers are always sent, see response security headers.
9. Logging, alerting and health checks
Set JSON_LOGS=true for structured logs and SPANWAY_LOG=INFO or ERROR to control verbosity. Wire liveness and readiness probes to /health/liveliness and /health/readiness, and turn on background model checks as described in health checks. Configure alerting for budget, outage and slow request alerts.
10. Pin versions and plan upgrades
Pin the image and Helm chart to a specific version instead of latest, and read the release notes before upgrading. The release cycle page explains how versions are published.
Verify a production gateway
Once the settings above are in place, these checks confirm them from the outside.
-
Confirm the gateway refuses to start with a weak master key by starting it once with
SPANWAY_MASTER_KEYunset. Expected result: it exits and prints theopenssl rand -hex 32command. -
Call the readiness probe the load balancer uses. It needs no key:
curl http://localhost:4000/health/readinessExpected result:
{"status": "healthy", "db": "connected", "airgapped": false, "coordination_redis": "connected"} -
With a proxy admin key, read the detailed readiness, which names the cache, the version and the callbacks, and confirm
cacheisredisandshow_no_redis_warningis false:curl http://localhost:4000/health/readiness/details -H "Authorization: Bearer $SPANWAY_API_KEY" -
Confirm the interactive docs are hidden by running
curl -i http://localhost:4000/openapi.jsonwithout a key, which answers404unlessSPANWAY_PUBLIC_API_DOCS=true. -
In the Admin UI, open Settings, then Admin Settings, and the Credential Encryption tab to see how many stored values still use the legacy format, and Logging Settings to confirm
store_prompts_in_spend_logsis what you intend. Router Settings, General tab shows the request size limit and the other general settings with where each value came from.
Errors
| Symptom | Meaning | Fix |
|---|---|---|
The gateway exits at startup naming SPANWAY_MASTER_KEY | The master key is unset, empty or a known example value. | Generate a real key and store it in the secret store. |
/health/readiness answers 503 with {"status": "unhealthy", "db": "disconnected"}, or 200 with "db": "disconnected" when allow_requests_on_db_unavailable is on | The database is unreachable from this instance. | Check DATABASE_URL, the network path and the pool limit. |
/health/readiness answers 200 with "coordination_redis": "error" | Redis is configured but does not answer this instance. The probe still passes. | Check the Redis host and network path, see Redis requirements. |
| A WARNING at startup about limits not being shared across instances | Redis is not configured and more than one instance runs. | Add Redis as in Redis requirements. |
| 503 on requests that carry a rate limit while Redis is down | fail_closed_rate_limit_enforcement is on by default. | Restore Redis, or set it to false to serve with per-instance limits. |
| One instance cannot read secrets another wrote | The instances run with different SPANWAY_SALT_KEY values. | Give every instance the same salt key. |
| 400 from the Credential Encryption migration | The salt key is missing or encryption_algorithm is not aes-256-gcm. | Set both, the 400 names which one. |
| Startup takes minutes after an upgrade | Schema migrations run before traffic is served. | Give the first instance time, then roll the rest. |
Related
- Settings reference for every setting named here.
- Health checks for the probes.
- Redis requirements for shared limits.
- Admission control for protecting workers under load.
- Deployment options for the Helm charts and Terraform stacks that encode this checklist.