Environment variables
Most of the gateway's behaviour is set in config.yaml, which the settings reference describes. A few things have to be known before the config is read, such as where the config lives, which database to use and how many workers to start, so they come from environment variables set on the container. This page lists those variables. Every one of them is optional unless the row says otherwise, and leaving a variable unset keeps the default shown.
A real-world scenario
A platform team runs the gateway on a container service whose task definition cannot mount files. They keep config.yaml in an S3 bucket, give the gateway its database through separate host, user and password variables from their secret store, start four workers per container, and turn on the bundled PgBouncer so many containers share a small number of database connections. Every one of those choices is an environment variable on the task, so they read this page to set them without touching the image.
Steps
Environment variables are set where the container runs, not in the Admin UI, so there is nothing to click.
-
Pick the variables you need from the tables below.
-
Add them to the container. With Docker that is
-e NAME=valueor an.envfile, with thespanway-helmchart it is theenvVarsvalue (<component>.extraEnvin thespanwaychart), and with the Terraform stacks it isgateway_extra_env,backend_extra_envor the stack inputs the Terraform page lists. -
Restart the container, because the gateway reads these variables only at start.
-
Check the result with a key that may read the details:
curl http://localhost:4000/health/readiness/details \-H "Authorization: Bearer $SPANWAY_API_KEY"
Expected result
The readiness details answer 200 with "db": "connected" when the database variables are right, and spanway_version names the release you run. A variable with a wrong value shows up as one of the errors below in the container log.
Start-up and server
| Variable | Default | What it does in plain words | Who changes it |
|---|---|---|---|
SPANWAY_MASTER_KEY | none, required | The admin key. The gateway refuses to start without it, or when it is empty or a publicly known default. | Every operator, once, from openssl rand -hex 32. |
SPANWAY_SALT_KEY | the master key | Encrypts provider keys stored in the database. Set it once and never change it, because values encrypted with the old salt can no longer be read. | Every operator with a database. |
CONFIG_FILE_PATH | unset | The config file path, used instead of --config. Unset, the gateway reads the file named by --config. | Operators who cannot pass command arguments. |
HOST, PORT | 0.0.0.0, 4000 | The address and port the server listens on, the same as --host and --port. | Operators whose platform assigns a port. |
NUM_WORKERS | 1 | How many worker processes one container starts, the same as --num_workers. More workers use more CPU cores and memory, and each opens its own database connections. | Operators sizing a container with several cores. |
SPANWAY_NON_ROOT | true in the images | Tells the gateway it runs as an unprivileged user, so it copies the Admin UI and logo files to /var/lib/spanway instead of writing next to its own code. Off only outside the images. | Nobody, the images set it. |
OPENAPI_URL | /openapi.json | Moves the OpenAPI document that the Postman page downloads to another path. | Operators who publish the spec under a different path. |
NO_OPENAPI | off | true removes the OpenAPI document route, so /openapi.json answers 404. It changes nothing else. Ignored when OPENAPI_URL is set. | Operators who do not want the API description served. |
NO_DOCS | off | true removes the interactive API docs page at /. | Operators who do not want the docs page served. |
SPANWAY_PUBLIC_API_DOCS | off | true shows the interactive docs, the OpenAPI document and the route list to everyone. Off, only signed-in users see them and everyone else gets 404, so strangers learn nothing about the gateway from its own docs. Turning it on publishes every management route, see API docs and build details. | Operators of a private development or test gateway only. |
DOCS_URL | / | Moves the interactive API docs page to another path. When it is set, NO_DOCS is ignored. | Operators who serve something else at /. |
DISABLE_ADMIN_UI | off | true stops serving the Admin UI. The API keeps working. | Operators who manage the gateway only through the API. |
SERVER_ROOT_PATH, SERVER_ROOT_PATHS | unset | Serve the gateway under one path prefix, or several comma separated ones, see settings reference. | Operators behind a load balancer that routes a sub-path. |
SPANWAY_ENABLE_HSTS | off | true tells browsers to use only HTTPS for the gateway's domain for a year. Turn it on only when every address is HTTPS. | Operators who own the domain. |
SPANWAY_DISABLE_LOGIN_RATE_LIMIT | off | true turns off the failed sign-in lockout. Use it only in tests. | Nobody in production. |
SPANWAY_AIRGAPPED | off | true turns off every optional outbound fetch and uses the bundled copies, see air-gapped deployment. | Operators on a network with no internet route. |
SPANWAY_RELEASE_CHECK_URL | unset | The release feed the Admin UI upgrade notice reads. Unset, no notice is shown. | Operators who were given a feed address. |
PROXY_BATCH_WRITE_AT | 10 | Seconds between the batched writes of spend and usage to the database. A lower value shows new requests in the spend views sooner and writes to the database more often. | Operators tuning database load. |
Config from object storage
The gateway can read its config from a bucket in two ways. The entrypoint way copies one object to a local file before the gateway starts, and it is what the Terraform stacks use on AWS. The gateway way reads the object itself at start, including the files the config pulls in with include. Use one of them, not both.
| Variable | Default | What it does in plain words | Who changes it |
|---|---|---|---|
SPANWAY_PROXY_CONFIG_S3_BUCKET, SPANWAY_PROXY_CONFIG_S3_KEY | unset | Entrypoint way. With both set and CONFIG_FILE_PATH set, the container downloads that S3 object to CONFIG_FILE_PATH before the gateway starts. | Operators on ECS or another platform without mounted files. |
SPANWAY_CONFIG_BUCKET_NAME, SPANWAY_CONFIG_BUCKET_OBJECT_KEY | unset | Gateway way. With the bucket name set, the gateway reads the config from that object instead of a file. The object key is required once the bucket is set. | Operators who keep the config in a bucket. |
SPANWAY_CONFIG_BUCKET_TYPE | S3 | Which store the gateway way reads. gcs reads Google Cloud Storage, and any other value or unset reads S3. | Operators on Google Cloud. |
Database
The gateway needs Postgres for virtual keys, users, teams, budgets, spend logs and the Admin UI sign-in. Give it either DATABASE_URL or the separate DATABASE_* parts, from which it builds the URL.
| Variable | Default | What it does in plain words | Who changes it |
|---|---|---|---|
DATABASE_URL | unset | The Postgres connection string. Unset and with no DATABASE_HOST, the gateway runs without a database, so only the master key and the models in config.yaml work. | Every operator with a database. |
DATABASE_HOST, DATABASE_PORT, DATABASE_USER (or DATABASE_USERNAME), DATABASE_PASSWORD, DATABASE_NAME, DATABASE_SCHEMA | unset, port 5432 | The parts the gateway joins into DATABASE_URL when that is unset, so the password can come from a separate secret. The Terraform stacks set them. | Operators whose secret store holds the parts separately. |
DATABASE_URL_READ_REPLICA, or DATABASE_HOST_READ_REPLICA, DATABASE_PORT_READ_REPLICA and the other _READ_REPLICA parts | unset | A read-only replica. Set, read-only lookups go to the replica and take load off the writer. Unset, everything goes to the writer. | Operators with a reader endpoint such as an Aurora reader. |
IAM_TOKEN_DB_AUTH | off | true signs in to an AWS RDS or Aurora database with a short-lived IAM token instead of a password, and refreshes the token before it expires. Needs DATABASE_HOST, DATABASE_USER and DATABASE_NAME and an IAM role that may connect. | Operators on AWS who do not want a stored database password. |
AZURE_POSTGRESQL_AUTH | off | true signs in to Azure Database for PostgreSQL with a Microsoft Entra token instead of a password. Cannot be on together with IAM_TOKEN_DB_AUTH. | Operators on Azure. |
DISABLE_SCHEMA_UPDATE | off | true stops the gateway from applying database migrations at start, for setups where a separate migration job does it. Off, every gateway applies pending migrations before it serves traffic. | Operators who run the migrations-job role, which the charts and Terraform stacks do. |
SPANWAY_MIGRATION_DIR | unset | A writable folder the migration files are copied to before they run, for a read-only root filesystem. | Operators who run the image with a read-only root filesystem. |
SPANWAY_PGBOUNCER_ENABLED | off | true starts the PgBouncer bundled in the image beside the gateway, so every worker in the container shares a few database connections. This helps when many containers would otherwise open too many connections. | Operators with many gateway containers on one database. The charts and Terraform stacks have their own switch for it. |
SPANWAY_PGBOUNCER_MAX_DB_CONNECTIONS | 20 | The most connections PgBouncer opens to Postgres from one container. | Operators tuning connection use. |
SPANWAY_PGBOUNCER_MAX_CLIENT_CONN | 1000 | The most connections the workers may open to PgBouncer. | Rarely changed. |
STORE_MODEL_IN_DB | off | True lets admins add and edit models, and other settings, from the Admin UI and the API, saved in the database. | Operators who manage models from the Admin UI. Off, models come only from config.yaml. |
Entrypoint and tracing
The entrypoint variables USE_DDTRACE, REDIS_CA_PEM_B64, PROMETHEUS_MULTIPROC_DIR, USE_V2_MIGRATION_RESOLVER and USE_PRISMA_DB_PUSH are described with their defaults on container images. Provider keys such as ANTHROPIC_API_KEY are read wherever the config names them with os.environ/, as configuration explains.
Errors
| What you see | What it means | Fix |
|---|---|---|
Spanway proxy refused to start: no master key is set, so every request would be accepted without authentication. | SPANWAY_MASTER_KEY is missing. | Set it, see proxy refuses to start. |
Config file not found: <path> | CONFIG_FILE_PATH or --config names a file that is not in the container. | Mount the file at that path, or fix the path. |
SPANWAY_CONFIG_BUCKET_OBJECT_KEY must be set to load the config from a bucket. | The bucket name is set but the object key is not. | Set SPANWAY_CONFIG_BUCKET_OBJECT_KEY. |
Unable to load config from given source. | The gateway could not read the bucket object. | Check the bucket, the key, SPANWAY_CONFIG_BUCKET_TYPE and the container's read access. |
DATABASE_URL uses unsupported scheme '<scheme>'. ... | The connection string is not Postgres. | Use a postgresql:// URL. Other databases are not supported. |
SPANWAY_PGBOUNCER_ENABLED is set but no DATABASE_URL could be assembled | PgBouncer was turned on without a database. | Set DATABASE_URL or the DATABASE_* parts. |
Logs
The gateway does not log the value of these variables. The lines that show them taking effect are the startup and database lines in the log reference, for example the migration retries when the database is still starting and _db_health_readiness_check: reconnect failed when it cannot be reached.
Related
- Settings reference for the
general_settingskeys inconfig.yaml. - Container images for the variables the entrypoint reads.
- Docker quick start for a first run.
- Terraform for the variables the stacks set for you.