Skip to content

Environment Variables Reference

All environment variables are validated at startup using Zod schemas defined in packages/server/src/config/env.ts. The server will exit with descriptive errors if validation fails.

Core

VariableRequiredDefaultDescription
NODE_ENVNodevelopmentdevelopment, production, or test
PORTNo3000HTTP server listen port
HOSTNo0.0.0.0HTTP server bind address
LOG_LEVELNoinfoerror, warn, info, http, verbose, debug, silly

Database

VariableRequiredDefaultValidation
MONGODB_URINomongodb://localhost:27017/ai-gatewayMust be a valid URL. See the note below on replica sets.
MONGODB_DB_NAMENoai-gatewayNon-empty string
REDIS_HOSTNolocalhostString
REDIS_PORTNo6379Positive integer
REDIS_PASSWORDProd(empty)Required in production
REDIS_DBNo0Non-negative integer

Authentication

VariableRequiredDefaultValidation
JWT_SECRETYesMinimum 16 characters. Must not contain placeholder values in production.
JWT_REFRESH_SECRETYesMinimum 16 characters. Must not contain placeholder values in production.
JWT_ACCESS_EXPIRYNo15mDuration string (e.g., 15m, 1h)
JWT_REFRESH_EXPIRYNo7dDuration string (e.g., 7d, 30d)
ENCRYPTION_KEYYesExactly 64 hex characters (256-bit AES key). Sequential patterns rejected in production.

Super Admin Seed

Used by pnpm seed to create the initial administrator account.

VariableRequiredDefaultValidation
SUPER_ADMIN_EMAILNoadmin@ai-gateway.localValid email address
SUPER_ADMIN_PASSWORDYes12+ characters, must include uppercase, lowercase, digit, and special character

Semantic Cache

VariableRequiredDefaultDescription
CACHE_EMBEDDING_MODELNonomic-embed-textEmbedding model for cache similarity
CACHE_SIMILARITY_THRESHOLDNo0.96Cosine similarity threshold (0.0-1.0)
CACHE_DEFAULT_TTL_SECONDSNo86400Cache entry TTL in seconds (default: 24 hours)

Rate Limiting

VariableRequiredDefaultDescription
RATE_LIMIT_WINDOW_MSNo60000Window duration in milliseconds
RATE_LIMIT_MAX_PER_WINDOWNo60Max requests per window

CORS and Networking

VariableRequiredDefaultDescription
CORS_ORIGINSNo(empty)Comma-separated allowed origins (each must be a valid URL)
SOCKET_CORS_ORIGINNohttp://localhost:3001The origin the admin console is served from. The console opens a WebSocket for live dashboard and audit updates; if this does not match, the connection is refused and the console simply stops updating without reporting why.
ADMIN_URLNohttp://localhost:3001Admin dashboard URL
SSO_CALLBACK_BASE_URLNo(optional)Base URL for SSO callback endpoints

Background Workers

VariableRequiredDefaultDescription
BULLMQ_PREFIXNoaigwRedis key prefix for BullMQ queues

S3 Backup

All S3 variables are optional. When not configured, audit log backups are stored locally.

VariableRequiredDefaultDescription
S3_BUCKETNoS3 bucket name
S3_REGIONNous-east-1AWS region
S3_ACCESS_KEY_IDNoAWS access key ID
S3_SECRET_ACCESS_KEYNoAWS secret access key
S3_PREFIXNobackupsKey prefix within the S3 bucket

SIEM Export

All SIEM variables are optional. When not configured, SIEM export is disabled.

VariableRequiredDefaultDescription
SIEM_TYPENoExport type: splunk, elk, or webhook
SIEM_URLNoSIEM endpoint URL
SIEM_TOKENNoAuthentication token
SIEM_BATCH_SIZENo100Events per batch

Audit retention

Set on the worker, which is the only writer of audit entries.

VariableRequiredDefaultDescription
AUDIT_LOG_RETENTION_DAYSNo365Days an audit entry is kept before the TTL index removes it. 0 disables expiry entirely.

Observability (OpenTelemetry)

All optional. When OTEL_EXPORTER_OTLP_ENDPOINT is unset, OpenTelemetry is a no-op with zero overhead. When set, the server and worker export traces, metrics, and logs over OTLP/HTTP; the collector base URL has /v1/{traces,metrics,logs} appended. See Observability for the full metric list and Grafana/Prometheus assets.

VariableRequiredDefaultDescription
OTEL_EXPORTER_OTLP_ENDPOINTNoOTLP collector base URL (e.g. http://otel-collector:4318). Unset disables OpenTelemetry export.
OTEL_SERVICE_NAMENoai-gateway / ai-gateway-workerOverrides the service.name resource attribute (worker defaults to ai-gateway-worker).
OTEL_METRIC_EXPORT_INTERVAL_MSNo30000Metric export interval in ms when OTLP is enabled.

For full ESM auto-instrumentation, start each process with node --import ./dist/telemetry/otel.js ./dist/index.js. Prometheus metrics remain available at GET /metrics regardless of OTLP configuration.

Encryption Key Source (KMS / BYOK)

VariableRequiredDefaultDescription
KEY_PROVIDERNoenvSource of the data-encryption key. env uses ENCRYPTION_KEY. A misconfigured value fails loudly rather than silently falling back. (vault / awskms are extension points, not yet implemented.)

Budget Alert Delivery

All optional; a budget’s notifyVia channel is a no-op unless the matching variables are set. Delivery is best-effort and isolated per channel. See Budgets.

VariableRequiredDefaultDescription
SMTP_HOSTNoSMTP server host (enables email alerts).
SMTP_PORTNo587SMTP port.
SMTP_SECURENofalseUse TLS on connect (set true for port 465).
SMTP_USERNoSMTP username.
SMTP_PASSNoSMTP password.
SMTP_FROMNogatewyse@localhostFrom address for alert emails.
BUDGET_ALERT_WEBHOOK_URLNoWebhook endpoint for budget alerts (HMAC-signed when a secret is set).
BUDGET_ALERT_WEBHOOK_SECRETNoSecret used to HMAC-sign webhook payloads.
SLACK_WEBHOOK_URLNoSlack incoming-webhook URL for budget alerts.

License (EE)

The Enterprise Edition gates service on an Ed25519-signed license JWT issued by the 137 & Co. platform. If LICENSE_TOKEN is missing or invalid when NODE_ENV=production, the server still boots but locks out: every request except health probes, admin sign-in, and the licence endpoints is refused until a valid licence is installed. It never exits, so recovery never requires shell access.

VariableRequiredDefaultDescription
LICENSE_TOKENProdEd25519-signed JWT issued by the 137 & Co. platform. Required in production.
LICENSE_PUBLIC_KEYSWhen LICENSE_TOKEN is setOne or more PEM-encoded public keys joined with ;; (the double-semicolon delimiter is used because newlines inside env values are unreliable across shells and Docker).
LICENSE_SERVER_URLNoPoints the daily revocation check at the licence server; set it on every non-air-gapped deployment. Air-gap is a signed licence claim (Government edition), never a configuration setting — unsetting this does not make a deployment air-gapped.
LICENSE_PHONE_HOME_INTERVAL_MSNo86400000Polling interval (ms) for the revocation check. Default is 24 hours.
LICENSE_GRACE_PERIOD_MSNo604800000How long a revoked licence continues to serve before the deployment locks out. Default is 7 days, measured from the issuer’s revocation timestamp.
GATEWYSE_LICENSE_FINGERPRINTNoOptional hardware-fingerprint override. Read directly via process.env in packages/license/src/fingerprint.ts (it is not part of the Zod env schema), because the license verifier runs before env validation. When set, it overrides the auto-derived machine fingerprint used for hardware-bound licenses.

The license verifier runs before the Zod env validator and Winston logger because both depend on environment that has not yet been validated at bootstrap time. For that reason LICENSE_* and GATEWYSE_LICENSE_FINGERPRINT are read straight from process.env and do not appear in the Zod env schema. See packages/server/src/services/license.service.ts for the boot sequence.

API Documentation

VariableRequiredDefaultDescription
ENABLE_SWAGGERNofalseWhen true, exposes the Swagger UI at /docs. In production this is off by default; set to true to enable.

Provider API Keys

Provider API keys are managed through the admin dashboard (or the admin API) and stored in the deployment provider catalogue, encrypted at rest with AES-256-GCM — the gateway resolves them from the database at request time. There is no runtime code path that reads OPENAI_API_KEY, ANTHROPIC_API_KEY, etc. from the environment for live routing.

The variable names below are listed for reference only (e.g. for local development scripts, seeding, or smoke tests); setting them does not configure a provider for the gateway:

Terminal window
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_AI_API_KEY=AIza...
AZURE_OPENAI_API_KEY=...
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
GROQ_API_KEY=gsk_...
MISTRAL_API_KEY=...
COHERE_API_KEY=...
DEEPSEEK_API_KEY=...
TOGETHER_API_KEY=...
FIREWORKS_API_KEY=...
PERPLEXITY_API_KEY=pplx-...
AI21_API_KEY=...
HUGGINGFACE_API_KEY=hf_...
XAI_API_KEY=...
CEREBRAS_API_KEY=...
SAMBANOVA_API_KEY=...
REPLICATE_API_TOKEN=r8_...
ELEVENLABS_API_KEY=...
ASSEMBLYAI_API_KEY=...

Production Security Checks

When NODE_ENV=production, the server enforces additional validation at startup:

  1. JWT_SECRET must not contain known placeholder strings
  2. JWT_REFRESH_SECRET must not contain known placeholder strings
  3. ENCRYPTION_KEY must not use sequential hex patterns (e.g., 0123456789abcdef repeated)
  4. REDIS_PASSWORD must be set (non-empty)

If any check fails, the server exits with a descriptive error message.