Docker quick start
This guide runs the Spanway gateway in Docker. The first section starts a single container with a config file. The second adds Postgres with Docker Compose, which you need for virtual keys, teams, users, the Admin UI and spend tracking.
Fastest start: dev mode
To try everything on a laptop first, including the Admin UI and virtual keys, the spanway-ai-dev image runs the gateway with its own built-in database, so there is no Postgres to set up. Three commands start it:
docker pull registry.spanway.ai/spanway/spanway-ai-dev:2.0.0
printf 'SPANWAY_MASTER_KEY=sk-%s\nSPANWAY_SALT_KEY=sk-%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > spanway-dev.env
docker run -d --name spanway-dev -p 127.0.0.1:4000:4000 --env-file spanway-dev.env -v spanway-dev:/var/lib/spanway/dev registry.spanway.ai/spanway/spanway-ai-dev:2.0.0
Then open http://localhost:4000/ui and sign in as admin with the SPANWAY_MASTER_KEY value from spanway-dev.env. Dev mode is for trying the gateway only, never for production. Dev mode walks through adding a model and a key, and lists its limits. The rest of this page uses the normal spanway-ai image, which is the one to run for real.
A real-world scenario
A developer wants to try the gateway on a laptop before the platform team sets it up for the company. She pulls the image, writes a config with one Anthropic model, starts the container with her provider key and a generated master key, and sends a request from the OpenAI client she already uses. When that works she adds Postgres with Docker Compose so she can open the Admin UI, create a virtual key for a colleague and see both of their requests in the logs.
Step by step
-
Pull the image and write
config.yamlas shown in Run one container with a config file, then start the container withdocker run. The first log lines show the config being loaded and the server listening on port 4000. -
Check that the gateway is up. The liveness probe needs no key:
curl http://localhost:4000/health/livelinessExpected result:
"I'm alive!" -
Send a request with the master key:
curl http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Say hello in one line."}]}'Expected result: an OpenAI-format chat completion with
"model": "claude-sonnet-5-5", plusx-spanway-model-idandx-spanway-response-costheaders. -
Stop the single container and start the Compose stack with Postgres from Run with Postgres using Docker Compose. Open
http://localhost:4000/uiand sign in asadminwith the master key as the password. The Home page shows your usage. -
Create a key for an application. Click Virtual Keys in the sidebar, then + Create New Key. Type a Key Name such as
laptop-test, pickclaude-sonnet-5-5under Models, and click Create Key. The Save your Key dialog shows the key once, so click Copy Virtual Key and store it, because you cannot view it again. -
Open Logs in the Admin UI. Every request you sent appears with its model, tokens and cost.
Pull the image
docker pull registry.spanway.ai/spanway/spanway-ai:2.0.0
Spanway is in private preview. The container images and Helm charts will be published soon. To request access, write to sales@spanway.ai, and preview customers receive download instructions in their onboarding pack.
The image exposes port 4000 and starts the gateway through its built-in spanway-container proxy command. Any arguments you pass after the image name go to the spanway command, so --config, --port, --num_workers and --detailed_debug work the same as on the command line. Container images describes every image and its start command.
Run one container with a config file
Create a config.yaml next to where you run Docker.
model_list:
- model_name: claude-sonnet-5-5
spanway_params:
model: anthropic/claude-sonnet-5-5
api_key: os.environ/ANTHROPIC_API_KEY
Mount it into the container and pass the provider key and a master key as environment variables.
export SPANWAY_MASTER_KEY="sk-$(openssl rand -hex 32)"
echo "$SPANWAY_MASTER_KEY"
docker run -p 4000:4000 \
-v $(pwd)/config.yaml:/app/config.yaml \
-e ANTHROPIC_API_KEY="your-provider-key" \
-e SPANWAY_MASTER_KEY \
registry.spanway.ai/spanway/spanway-ai:2.0.0 \
--config /app/config.yaml
Check that the gateway is up. The liveness endpoint does not need a key.
curl http://localhost:4000/health/liveliness
You can also point the gateway at a config with the CONFIG_FILE_PATH environment variable instead of the --config flag, or load it from a storage bucket with SPANWAY_CONFIG_BUCKET_NAME, SPANWAY_CONFIG_BUCKET_OBJECT_KEY and SPANWAY_CONFIG_BUCKET_TYPE.
Run with Postgres using Docker Compose
Keys, users, teams, budgets and spend logs are stored in Postgres. Set DATABASE_URL and the gateway runs its schema migrations at startup, before it serves traffic.
services:
spanway:
image: registry.spanway.ai/spanway/spanway-ai:2.0.0
command: ["--config=/app/config.yaml"]
volumes:
- ./config.yaml:/app/config.yaml
ports:
- "4000:4000"
environment:
DATABASE_URL: "postgresql://llmproxy:dbpassword9090@db:5432/spanway"
STORE_MODEL_IN_DB: "True"
env_file:
- .env
depends_on:
- db
healthcheck:
test: ["CMD", "/app/.venv/bin/python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:4000/health/liveliness')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
db:
image: postgres:16
restart: always
environment:
POSTGRES_DB: spanway
POSTGRES_USER: llmproxy
POSTGRES_PASSWORD: dbpassword9090
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -d spanway -U llmproxy"]
interval: 1s
timeout: 5s
retries: 10
volumes:
postgres_data:
The gateway healthcheck uses the CMD form and calls the image's own Python directly. The image has no shell, so a CMD-SHELL check can never run and the container would stay unhealthy.
Put secrets in a .env file next to the compose file. Change the database password before using this outside a laptop.
SPANWAY_MASTER_KEY="sk-replace-with-openssl-rand-hex-32"
SPANWAY_SALT_KEY="a-long-random-string-you-never-change"
ANTHROPIC_API_KEY="your-provider-key"
docker compose up -d
Environment variables used here
| Variable | Default | What it does | When it is off or unset |
|---|---|---|---|
SPANWAY_MASTER_KEY | none, it is required | The admin key for the gateway. Anyone holding it can do everything, so generate it with openssl rand -hex 32 and keep it secret. | The gateway refuses to start when it is unset, empty or a publicly known default. |
SPANWAY_SALT_KEY | the master key | Encrypts the provider keys the gateway stores in the database. Set it once and never change it, because values encrypted with the old salt can no longer be read. | The master key is used instead, so rotating the master key later also needs a master key migration. |
DATABASE_URL | unset | The Postgres connection string. The database holds keys, users, teams, budgets and spend logs, and the Admin UI needs it. | The gateway still serves requests with the models in config.yaml and the master key, but virtual keys, the Admin UI sign-in and spend tracking are off. |
STORE_MODEL_IN_DB | off | True lets admins add and edit models from the Admin UI and POST /model/new, saved in the database, so a new model needs no restart. Needs DATABASE_URL. | Models come only from config.yaml, and adding one in the Admin UI or with /model/new answers 500 Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature. |
CONFIG_FILE_PATH | unset | The path of the config file, used instead of the --config flag. | The gateway reads the file named by --config, or starts with no models when neither is given. |
Every other variable the images read is listed in the environment variable reference.
Errors
| Symptom | Meaning | Fix |
|---|---|---|
The container exits at once with Spanway proxy refused to start: no master key is set, so every request would be accepted without authentication., ... the master key is empty. or ... the master key is a publicly known default. | The master key is missing, empty or a known example. | Export a real key, for example sk-$(openssl rand -hex 32), and pass it with -e SPANWAY_MASTER_KEY. See proxy refuses to start. |
Config file not found: /app/config.yaml in the log | The volume mount path and the --config argument differ. | Mount the file at the path you pass to --config. |
Is a directory naming /app/config.yaml in the log | config.yaml did not exist on the host when the container started, so Docker created an empty folder at the mount point instead. | Stop the container, delete the empty config.yaml folder on the host, create the file, and start again. |
401 Authentication Error, No api key passed in. | The request carried no key. | Add -H "Authorization: Bearer $SPANWAY_MASTER_KEY". |
400 Invalid model name passed in model=... | The model in the request does not match a model_name in config.yaml. | Use the model_name you registered, or add the model. |
| 401 or 403 from the provider in the response | The provider key is wrong or the account has no access to the model. | Check ANTHROPIC_API_KEY or the matching variable in .env. |
| The Admin UI sign-in page says a database is needed | The container runs without DATABASE_URL. | Use the Compose stack with Postgres. |
database "spanway" does not exist or the migration fails at startup | Postgres was not ready or the credentials differ from DATABASE_URL. | Let the db service pass its health check first, and check the password in both places. |
Logs
The gateway writes its logs to the container output, so docker logs <container> or docker compose logs spanway shows them. These are the lines you see while starting it.
| Level | Line | Meaning | Action |
|---|---|---|---|
| Output | Spanway proxy refused to start: ... followed by the fix | The master key is unset, empty or a known default, and the container exits. | Set a generated key, as the errors above say. |
| CRITICAL | SPANWAY_MASTER_KEY is not set. The proxy refuses to start, and refuses every request, unless dangerously_permit_weak_or_unset_master_key is on for local development. | No master key reached the config. | Pass SPANWAY_MASTER_KEY. |
| Output | Initialized Success Callbacks - [...] | The config file loaded and its logging callbacks started. | None. |
| WARNING | Attempt <n> timed out after <s>s or The process failed to execute. Details: ... Retrying... (<n> attempts left) | The schema migration at startup did not finish on that try, usually because Postgres was still starting. | None if a later try succeeds. If every try fails, check DATABASE_URL and that the db service is healthy. |
The log reference lists every startup line, and Logging explains how to raise the level.
Related
The request examples on this site read SPANWAY_API_KEY from the environment, which holds the master key or a virtual key. Open http://localhost:4000/ui and sign in with the master key, or create a key from the command line as shown in virtual keys. For multi-instance deployments, add Redis as described in Redis requirements, then review the production checklist.
- Dev mode for the one-container image with a built-in database, for a laptop only.
- Proxy quick start for the command line options and the first request from the SDK.
- Configuration for every section of
config.yaml. - Docker compose files for the compose stacks that ship with the gateway.
- Container images for the images and how to verify them.
- Production checklist before real traffic.