DocsAPI Reference

Configuration

Environment variables for self-hosted Tokamak deployments


All configuration is via environment variables. In the shipped Compose stack they live in a single tokamak-services/.env file that the services consume through their Compose configuration.

This page covers what you need for a production deployment. For every variable and its default, see Environment Variables.


Required

VariableDescription
DB_POSTGRESQL_WRITE_DSNPostgreSQL connection string, e.g. postgres://tokamak:tokamak@api-db:5432/tokamak
COMPOSE_PROFILESWhich service groups to start. Nothing runs if this is empty.

Change before going to production

These ship with development defaults that are unsafe on a public deployment.

VariableWhy
TOKAMAK_AUTH_SERVICE_TOKENAuthenticates core → auth calls. The default is a well-known development value.
MODEL_PROVIDER_SECRETEncrypts stored provider credentials. The default is a well-known development value.
AUTHZ_DELEGATION_PRIVATE_KEYSigns the gateway's delegation JWTs. If unset an ephemeral key is generated, which breaks across restarts and across replicas.
AUTHZ_DELEGATION_KEY_IDKey ID published in the delegation JWKS.
APIKEY_SECRETEncrypts stored API keys.
TOKAMAK_AUTH_ENCRYPTION_SECRETEncrypts credentials held by the auth service.
JWT_SIGNING_SECRETSession signing key on the auth service — minimum 32 characters. Do not set it on core; core refuses to start if it is present.
SYSTEM_ADMIN_EMAILComma-separated emails seeded as platform owners on startup. Without it nobody can administer a fresh deployment.

Service wiring

VariableDefaultDescription
TOKAMAK_CORE_URLhttp://tokamak-core:8090Where gateway and auth reach core
TOKAMAK_AUTH_URLhttp://tokamak-auth:8092Where gateway and core reach auth
TOKAMAK_DELEGATION_JWKS_URL—The gateway's JWKS endpoint, so core can verify delegation tokens
TOKAMAK_CORE_DB_SCHEMAllm_apiSchema owned by core
TOKAMAK_AUTH_DB_SCHEMAtokamak_authSchema owned by auth
AUTO_MIGRATEtrueRun core migrations on startup. Auth always migrates.

Authentication

VariableDefaultDescription
JWT_ACCESS_TOKEN_TTL1hAccess token lifetime
JWT_REFRESH_TOKEN_TTL168hRefresh token lifetime (7 days)
API_KEY_DEFAULT_TTL2160hDefault API key lifetime (90 days)
API_KEY_MAX_TTL2160hMaximum API key lifetime
API_KEY_MAX_PER_USER100Maximum keys per user
API_KEY_PREFIXsk_livePrefix on issued keys

OIDC (optional)

Keycloak is not part of the Compose stack. To use an existing installation:

VariableDescription
KEYCLOAK_ENABLEDSet to true to enable OIDC validation
KEYCLOAK_BASE_URLBase URL of the Keycloak deployment
KEYCLOAK_REALMRealm name
KEYCLOAK_CLIENT_IDClient ID

With Keycloak disabled, the deployment still accepts API keys and self-signed session tokens.


Ports and networking

VariableDefaultDescription
HTTP_PORT8080 on gateway, 8090 on core, 8092 on auth, 8093 on billingPer-service listener
CORS_ALLOWED_ORIGINS—Allowed origins on the gateway (comma-separated)
CORS_EXTRA_ORIGINS—Additional origins on core

Expose backend traffic through the gateway. Core, auth and billing are private in the base Compose files; the billing development override publishes a local port. Frontends and selected infrastructure also publish host ports.


Media storage

VariableDefaultDescription
MEDIA_STORAGE_BACKENDs3s3 or local
MEDIA_S3_ENDPOINThttps://s3.menlo.aiS3-compatible endpoint
MEDIA_S3_BUCKET—Bucket name
MEDIA_S3_ACCESS_KEY_ID—Access key
MEDIA_S3_SECRET_ACCESS_KEY—Secret key
MEDIA_S3_REGIONus-west-2Region
MEDIA_LOCAL_STORAGE_PATH—Filesystem path when the backend is local
MEDIA_LOCAL_STORAGE_BASE_URL—Base URL for locally stored media
MEDIA_MAX_BYTES52428800Maximum file size (50 MB)
MEDIA_PUBLIC_URLhttp://localhost:8080Public-facing URL for media
MEDIA_RETENTION_DAYS30Days before media is deleted

Request archives

Off by default. When enabled, request and response payloads are written to S3 for audit and replay.

VariableDefaultDescription
ARCHIVE_ENABLEDfalseEnable archiving
ARCHIVE_S3_BUCKET—Bucket name
ARCHIVE_S3_REGIONus-west-2Region
ARCHIVE_RETENTION_DAYS365Retention window
ARCHIVE_COMPRESSIONtrueCompress payloads

Invitation email delivery

Configure these on auth. Leaving the host unset disables email delivery; administrators can still copy invitation links. Partial or invalid SMTP configuration fails startup.

VariableDefaultPurpose
INVITATION_SMTP_HOSTunsetSMTP server; enables delivery when configured
INVITATION_SMTP_PORT587STARTTLS-capable SMTP port, not implicit TLS/465
INVITATION_SMTP_FROMunsetSender address
INVITATION_SMTP_USERNAME, INVITATION_SMTP_PASSWORDunsetSet both when the relay requires authentication
INVITATION_SMTP_REQUIRE_TLStrueRequire STARTTLS; SMTP authentication always requires TLS
INVITATION_APP_URLunsetCustomer app origin for invitation links; HTTPS required except loopback

Use a local email sink and disposable recipients for development. Confirm delivery status and acceptance before inviting customers. Retries reuse the invitation credential; delivery is not proof of membership. A crash after SMTP acceptance can produce duplicate mail without duplicate grants.

Billing and payment setup

Billing runs privately on port 8093, owns the tokamak_billing schema and runs its migrations on boot. Provider credentials alone do not activate charging for every organization.

VariableServicePurpose
TOKAMAK_BILLING_DB_DSNbillingRequired database connection; falls back to DB_POSTGRESQL_WRITE_DSN
TOKAMAK_BILLING_DB_SCHEMAbillingOwned schema; default tokamak_billing
TOKAMAK_BILLING_MODEcoreDISABLED by default; SHADOW observes; AUTHORITY follows per-organization activation
TOKAMAK_BILLING_STRIPE_SECRET_KEYbillingEnables the deposit provider surface; keep server-side
TOKAMAK_BILLING_STRIPE_WEBHOOK_SECRETbillingEnables signature-verified Stripe webhook handling
TOKAMAK_BILLING_STRIPE_PUBLISHABLE_KEYbillingEnables in-page card confirmation; must match the deployment's test/live band
TOKAMAK_BILLING_CARD_ENTRYbillingelements or checkout; unset chooses from configured capabilities. Stripe Elements requires a publishable key; Airwallex uses per-intent client secrets
TOKAMAK_BILLING_RECEIPT_MODEbillingboth (default), stripe, or tokamak
TOKAMAK_BILLING_CHECKOUT_RETURN_BASE_URLbillingPublic gateway base for the hosted checkout callback
TOKAMAK_BILLING_CHECKOUT_APP_RETURN_URLbillingCustomer app destination after the callback
TOKAMAK_BILLING_OPS_TOKENSbillingServer-held credentials for internal operations; never expose to browsers

This is an onboarding summary, not the full activation procedure. Configure service trust, provider band, webhooks, redirects, fee policy and organization activation together. Read the repository's tokamak-services/docs/reference/billing.md, env.md and billing-activation-runbook.md before an enforced rollout.

Use payment test mode and local test services for development. Verify quote review, a completed test purchase, credit settlement, receipt access and pending-payment recovery before opening purchases to customers. See Credits and billing for the customer workflow.

Adding Airwallex as a second payment provider

Billing talks to payment providers through one port with one adapter per provider. Stripe and Airwallex can be configured side by side; every stored deposit, saved card, refund and dispute keeps routing to the provider recorded on it. New purchases using a saved card use that card's provider; other new purchases use the deployment's default provider, which must be named explicitly.

VariableServicePurpose
TOKAMAK_BILLING_DEFAULT_PAYMENT_PROVIDERbillingstripe or airwallex. Required whenever any payment credential is set — a Stripe-only deployment must set stripe before upgrading, or billing refuses to boot
TOKAMAK_BILLING_AIRWALLEX_CLIENT_ID / TOKAMAK_BILLING_AIRWALLEX_API_KEYbillingThe Airwallex API credential, set together. Registers the Airwallex adapter; does not change the default
TOKAMAK_BILLING_AIRWALLEX_ENVbillingdemo or prod. Checked against the deployment band at boot: prod requires live, demo requires test
TOKAMAK_BILLING_AIRWALLEX_WEBHOOK_SECRETbillingEnables the signature-verified webhook route POST /v1/billing/webhooks/airwallex

Point an Airwallex webhook subscription at https://<gateway>/v1/billing/webhooks/airwallex and subscribe to the payment_intent.*, payment_attempt.*, refund.*, payment_dispute.*, payment_consent.* and payment_method.* events. Registering the adapter changes nothing for customers until the default provider is switched, which is a separate, gated change. The full ordered procedure, the verification steps and what is deliberately left disabled are in the repository's tokamak-services/docs/rollouts/airwallex-setup-runbook.md.

Logging and observability

VariableDefaultDescription
LOG_LEVELinfodebug / info / warn / error
LOG_FORMATconsoleconsole or json — use json in production
ENVIRONMENTdevelopmentdevelopment or production
OTEL_ENABLEDfalseEnable OTLP trace and metric export
OTEL_EXPORTER_OTLP_ENDPOINT—Collector endpoint

See Observability.


Features

VariableDefaultDescription
ENABLE_SWAGGERtrueServe the Swagger UI
MODEL_SYNC_ENABLEDtruePeriodically refresh provider model lists

On this page