Skip to main content

Spanway documentation

Spanway is a self-hosted AI gateway, a bridge to any model. It runs inside your own infrastructure and gives every application one OpenAI-compatible API for the model providers you use, including OpenAI, Anthropic, AWS Bedrock, Google Vertex AI, Azure OpenAI and many more. Applications authenticate with Spanway virtual keys instead of provider credentials, and the gateway takes care of request translation, retries, fallbacks, load balancing, budgets, rate limits, guardrails, logging and cost tracking.

Spanway is commercially licensed software. The core gateway runs without a license, and enterprise features such as single sign-on, custom roles, access requests, compliance controls, billing and audit logging are enabled by a license key. Spanway is currently in private preview.

Agents, workflows, evals, governance and compliance features run inside the gateway itself, so they share its keys, policies, spend ledger, guardrails and audit trail. Why gateway-native explains what that adds for each capability.

A new install keeps no request content. The gateway always records metadata such as the key, model, tokens, cost and latency so budgets and dashboards work, but it stores prompts and responses only when you turn prompt storage on, message logging is not turned off, and no zero data retention policy applies. What Spanway stores lists every store and how retention and data subject requests reach it.

Spanway is distributed as a container image with its code compiled inside, together with Helm charts and Terraform modules that deploy that image. No gateway package is published to a package index and nothing runs from source, so there is nothing to install on a host beyond a container runtime. You either run the gateway (also called the proxy) yourself and share it across teams, or use Spanway Cloud, where Spanway runs the same image for you and you receive a base URL and a key. Applications reach both the same way, over HTTPS with a Spanway virtual key, as described in calling the gateway.

Quick start​

The steps below start a gateway on your machine with one model. Postgres is not needed for this first test.

  1. Pull the gateway image. Spanway ships as a container image, so there is nothing to install on the host beyond Docker.
docker pull registry.spanway.ai/spanway/spanway-ai:2.0.0
Private preview

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.

  1. Write a config.yaml with one model. The model_name is the public name your applications use, and spanway_params tells the gateway how to reach the provider.
model_list:
- 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
  1. Generate a master key and start the gateway. It listens on port 4000 by default, and any arguments after the image name go to the spanway command inside the container.
export SPANWAY_MASTER_KEY="sk-$(openssl rand -hex 32)"
export ANTHROPIC_API_KEY="your-provider-key"
docker run -p 4000:4000 -v "$PWD/config.yaml:/app/config.yaml" \
-e SPANWAY_MASTER_KEY -e ANTHROPIC_API_KEY \
registry.spanway.ai/spanway/spanway-ai:2.0.0 --config /app/config.yaml
  1. Send a request in the OpenAI format.
curl -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": "Hello from Spanway"}]}'

The response has the same shape as an OpenAI chat completion, whichever provider served it.

About SPANWAY_API_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.

Where to go next​

GoalPage
Run the gateway in a container with PostgresDocker quick start
Learn the CLI and the first request in detailProxy quick start
Call the gateway from the OpenAI, Anthropic and Responses APIsCalling the gateway
Understand every section of config.yamlConfiguration
Issue keys with budgets and model limitsVirtual keys
Find setup details for a providerProviders
Find your way around the Admin UIUsing the Admin UI
See why the features live in the gatewayWhy gateway-native
Check what the gateway keeps about each requestWhat Spanway stores
Turn on enterprise featuresEnterprise
Deploy on Kubernetes or a cloudDeployment options
Browse every endpointAPI reference
See what shipped in this buildRelease notes

Calling Spanway from your code​

Every application talks to Spanway over HTTPS with a base URL and a Spanway virtual key. The gateway serves the OpenAI API, so the OpenAI SDKs work by changing their base URL and key. It also serves the Anthropic Messages API on /v1/messages, so Anthropic SDKs and coding tools such as Claude Code work the same way, and the OpenAI Responses API on /v1/responses. The same key works across every model and provider the admin allows, so moving from one provider to another is a change to model.

import os
from openai import OpenAI

client = OpenAI(base_url="http://localhost:4000/v1", api_key=os.environ["SPANWAY_API_KEY"])
response = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Write one sentence about gateways."}],
)
print(response.choices[0].message.content)
import os
from anthropic import Anthropic

client = Anthropic(base_url="http://localhost:4000", api_key=os.environ["SPANWAY_API_KEY"])
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=200,
messages=[{"role": "user", "content": "Write one sentence about gateways."}],
)
print(message.content[0].text)

On Spanway Cloud the base URL is the one shown in your workspace, such as https://api.spanway.ai. OpenAI SDKs take it with /v1 added (https://api.spanway.ai/v1), while the Anthropic and Google SDKs take the bare root because they add /v1/messages or /v1beta themselves, see connect any client. The key is a virtual key created in the Admin UI. Calling the gateway covers every header the gateway accepts and the Spanway request and response headers. For managing keys, teams, models and budgets from code, use the spanway-client Python package or the @spanway/client TypeScript package, which wrap the management API.

Errors​

What you seeWhat it meansFix
401 with auth_errorThe key is wrong, or no Authorization: Bearer header was sent.Create a virtual key in Virtual Keys and send it as a bearer token.
400 with Invalid model name passed in model=<name>The gateway serves no model with that name.Call GET /v1/models with your key to list the names it may use.
Connection refused on port 4000The gateway is not running or listens elsewhere.Check the container and curl http://localhost:4000/health/liveliness.

Every error status is explained in the error reference, and troubleshooting starts from a symptom.