Skip to main content

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.

  1. Pick the variables you need from the tables below.

  2. Add them to the container. With Docker that is -e NAME=value or an .env file, with the spanway-helm chart it is the envVars value (<component>.extraEnv in the spanway chart), and with the Terraform stacks it is gateway_extra_env, backend_extra_env or the stack inputs the Terraform page lists.

  3. Restart the container, because the gateway reads these variables only at start.

  4. 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​

VariableDefaultWhat it does in plain wordsWho changes it
SPANWAY_MASTER_KEYnone, requiredThe 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_KEYthe master keyEncrypts 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_PATHunsetThe config file path, used instead of --config. Unset, the gateway reads the file named by --config.Operators who cannot pass command arguments.
HOST, PORT0.0.0.0, 4000The address and port the server listens on, the same as --host and --port.Operators whose platform assigns a port.
NUM_WORKERS1How 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_ROOTtrue in the imagesTells 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.jsonMoves the OpenAPI document that the Postman page downloads to another path.Operators who publish the spec under a different path.
NO_OPENAPIofftrue 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_DOCSofftrue removes the interactive API docs page at /.Operators who do not want the docs page served.
SPANWAY_PUBLIC_API_DOCSofftrue 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_UIofftrue stops serving the Admin UI. The API keeps working.Operators who manage the gateway only through the API.
SERVER_ROOT_PATH, SERVER_ROOT_PATHSunsetServe 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_HSTSofftrue 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_LIMITofftrue turns off the failed sign-in lockout. Use it only in tests.Nobody in production.
SPANWAY_AIRGAPPEDofftrue 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_URLunsetThe release feed the Admin UI upgrade notice reads. Unset, no notice is shown.Operators who were given a feed address.
PROXY_BATCH_WRITE_AT10Seconds 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.

VariableDefaultWhat it does in plain wordsWho changes it
SPANWAY_PROXY_CONFIG_S3_BUCKET, SPANWAY_PROXY_CONFIG_S3_KEYunsetEntrypoint 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_KEYunsetGateway 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_TYPES3Which 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.

VariableDefaultWhat it does in plain wordsWho changes it
DATABASE_URLunsetThe 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_SCHEMAunset, port 5432The 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 partsunsetA 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_AUTHofftrue 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_AUTHofftrue 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_UPDATEofftrue 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_DIRunsetA 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_ENABLEDofftrue 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_CONNECTIONS20The most connections PgBouncer opens to Postgres from one container.Operators tuning connection use.
SPANWAY_PGBOUNCER_MAX_CLIENT_CONN1000The most connections the workers may open to PgBouncer.Rarely changed.
STORE_MODEL_IN_DBoffTrue 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 seeWhat it meansFix
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 assembledPgBouncer 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.