Proxy quick start
This guide starts the Spanway gateway from its container image, registers a model, and sends requests with the OpenAI SDK and with curl. It takes about five minutes and does not need a database. For a setup with Postgres and Docker Compose, see the Docker quick start.
A real-world scenario
A developer on a data team has an OpenAI key and an Anthropic key and wants every script in the team to use one client and one URL. She starts the gateway from the image with a two model config, points the OpenAI SDK at http://localhost:4000, and switches a script from one provider's model to the other by changing only the model string. The team then replaces the provider keys in their scripts with one virtual key each, so the real provider keys live only on the gateway.
Install
Spanway ships only as a container image, with its code compiled inside. Pull it, then define a spanway shell function so the commands on this page run the spanway command inside the container, with the current directory mounted at /app/work and the provider keys and master key passed through.
docker pull registry.spanway.ai/spanway/spanway-ai:2.0.0
spanway() {
docker run --rm -it -p 4000:4000 -v "$PWD:/app/work" -w /app/work \
-e SPANWAY_MASTER_KEY -e OPENAI_API_KEY -e ANTHROPIC_API_KEY \
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 provides two commands. spanway starts the gateway, and spanwayctl is the client CLI for managing keys, models and users on a running gateway. Run spanwayctl from the same image with --entrypoint spanwayctl.
Start with a single model
The fastest start passes a model on the command line. The gateway reads the provider credential from the environment.
export SPANWAY_MASTER_KEY="sk-$(openssl rand -hex 32)"
export OPENAI_API_KEY="your-provider-key"
spanway --model openai/gpt-6.1-sol
The gateway refuses to start without a master key, with an empty one, or with a publicly known example value. The refusal message prints the command to generate a key. For a throwaway local test only, SPANWAY_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=true starts it anyway, and with no master key it then accepts every request without authentication.
For anything beyond a quick test, use a config file. It lets you register several models, set a master key and turn on features.
model_list:
- model_name: gpt-6.1-sol
spanway_params:
model: openai/gpt-6.1-sol
api_key: os.environ/OPENAI_API_KEY
- model_name: claude-sonnet-5-5
spanway_params:
model: anthropic/claude-sonnet-5-5
api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
master_key: os.environ/SPANWAY_MASTER_KEY
spanway --config config.yaml
Common command line options
| Option | Default | What it does |
|---|---|---|
--config | none | Path to the config.yaml file. |
--host | 0.0.0.0 | Address to listen on. Also read from HOST. |
--port | 4000 | Port to listen on. Also read from PORT. |
--num_workers | 1 | Number of worker processes. The default can be changed with DEFAULT_NUM_WORKERS_SPANWAY_PROXY. |
--model | none | Start with a single model and no config file. |
--detailed_debug | off | Verbose request and response logging, including request and response bodies. For development only, never in production. |
--debug | off | Debug logging with less detail. |
--drop_params | off | Drop OpenAI parameters a provider does not support. |
--ssl_keyfile_path, --ssl_certfile_path | none | Serve HTTPS directly from the gateway. |
--run_gunicorn, --run_granian | off | Use a different server than the default. Both ship in the gateway images. |
--validate_config | off | Load and validate the config, then exit. |
--health | off | Run health checks against the configured models. |
--version | off | Print the installed version. |
Make a request
The gateway speaks the OpenAI API, so any OpenAI client works. Point it at the gateway and use the master key or a virtual key.
The examples on this site read your key from the SPANWAY_API_KEY environment variable, which holds your master key or a virtual key. Export it before running an example. The gateway refuses to start when its master key is unset, empty, or a publicly known example value, so always generate a real master key, for example with openssl rand -hex 32.
import os
from openai import OpenAI
client = OpenAI(base_url="http://localhost:4000", api_key=os.environ["SPANWAY_API_KEY"])
response = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Give me a one line status update."}],
)
print(response.choices[0].message.content)
curl http://localhost:4000/v1/models -H "Authorization: Bearer $SPANWAY_API_KEY"
The /v1/models call lists the public model names the key can use.
Open the Admin UI
The Admin UI is served at http://localhost:4000/ui. Sign in with the master key as the password, or set UI_USERNAME and UI_PASSWORD. The UI needs a database to create keys, teams and users, so connect Postgres with DATABASE_URL before using it. See Admin UI.
Step by step
-
Define the
spanwayshell function and start the gateway with the config above. The log shows each model being loaded. -
List the models the key can use:
curl http://localhost:4000/v1/models -H "Authorization: Bearer $SPANWAY_API_KEY"Expected result:
{"data": [{"id": "gpt-6.1-sol", "object": "model", "created": 1677610602, "owned_by": "openai"}, {"id": "claude-sonnet-5-5", "object": "model", "created": 1677610602, "owned_by": "openai"}], "object": "list"} -
Send a chat completion with either model name:
curl http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "gpt-6.1-sol", "messages": [{"role": "user", "content": "Give me a one line status update."}]}'Expected result: a chat completion whose
modelis the public name you sent and whose headers carryx-spanway-response-cost. -
Validate a config change before restarting with
spanway --config config.yaml --validate_config, which exits 0 on a good file. -
Once Postgres is connected, open
http://localhost:4000/ui, sign in with the master key, and use Virtual Keys, + Create New Key to give each application its own key. Models + Endpoints shows the two models and lets you run a health check on each.
Errors
| Symptom | Meaning | Fix |
|---|---|---|
The gateway refuses to start and prints the openssl rand -hex 32 command | SPANWAY_MASTER_KEY is unset, empty or a known example value. | Generate a key and export it before starting. |
OPENAI_API_KEY or ANTHROPIC_API_KEY reported as missing in the log | The config references a variable that is not in the container's environment. | Export it in the shell, the function passes it through with -e. |
401 Authentication Error, No api key passed in. | The request has no Authorization header. | Export SPANWAY_API_KEY and send it as a bearer token. |
400 Invalid model name passed in model=... | The model does not match a model_name in the config. | Use a name from GET /v1/models. |
429 Rate limit reached from the provider | The provider account is over its limit. | Add a second deployment with the same model_name, see routing. |
--validate_config exits 1 with Spanway: config validation failed: ... | The file is not valid YAML, an include file is missing, or a model entry failed to load. A misspelled key is not reported. | Fix the line or entry the message names. |
Related
Read configuration for every config section, then create virtual keys for your applications. Before going live, work through the production checklist.
- Docker quick start for the Compose stack with Postgres.
- Configuration for the config sections.
- Supported endpoints for everything beyond chat completions.
- CLI for
spanwayctl.