CODEX_LB_ prefix. You can set these in your shell, a .env file, or a .env.local file in the project root.
Configuration Files
Codex-LB reads environment variables from:- System environment variables
.envfile (tracked in git, shared defaults).env.localfile (gitignored, local overrides)
.env.local file takes precedence over .env, which takes precedence over system defaults.
Database Configuration
Database connection URL. Supports SQLite and PostgreSQL.SQLite (default):PostgreSQL:See Database Configuration for detailed setup.
Automatically run database migrations on startup. Recommended for most deployments.
Create a backup of the SQLite database before running migrations. Only applies to SQLite databases.
Maximum number of SQLite backup files to retain. Older backups are automatically deleted.
Maximum number of database connections in the connection pool. Only applies to PostgreSQL.
Maximum number of connections that can be created beyond pool_size. Only applies to PostgreSQL.
Timeout in seconds when waiting for a database connection from the pool.
Upstream Configuration
Base URL for the upstream ChatGPT backend API. Do not include the
/codex suffix.Connection timeout in seconds for upstream API requests.
Maximum idle time in seconds for streaming responses before timing out.
OAuth & Token Refresh
Base URL for the OpenAI authentication service.
OAuth client ID for OpenAI authentication. Do not change unless instructed by OpenAI.
OAuth scopes to request during authorization.
Timeout in seconds for OAuth authorization and token exchange requests.
OAuth redirect URI for the authorization callback. Must match the registered redirect URI.See OAuth Configuration for details on redirect URIs.
Host address for the OAuth callback server. Defaults to
0.0.0.0 in Docker containers.Port for the OAuth callback server.
Timeout in seconds for token refresh requests.
Interval in days between automatic token refreshes. Codex-LB automatically refreshes account tokens to keep them valid.
Encryption
Path to the encryption key file. This file is used to encrypt sensitive data like access tokens and refresh tokens.Docker deployments: Override this to persist the key in a Docker volume:
Usage Tracking
Timeout in seconds for fetching usage data from the upstream API.
Maximum number of retries when fetching usage data fails.
Enable automatic background refresh of usage data for all accounts.
Interval in seconds between automatic usage data refreshes.
Firewall & IP Access Control
Trust
X-Forwarded-For headers for client IP detection.See Firewall Configuration for setup details.Comma-separated list of CIDR ranges for trusted proxy sources. Only requests from these IPs will have their
X-Forwarded-For headers trusted.Example (nginx on localhost + Cloudflare):Advanced Settings
Terminate the application if database migrations fail. Recommended for production.
Automatically remap legacy Alembic revision IDs during migrations.
Log the shape of proxy requests for debugging. Not recommended in production.
Log raw cache keys in request shape logs. Only applies if
LOG_PROXY_REQUEST_SHAPE is enabled.Log full request payloads for debugging. Not recommended in production due to sensitive data.
Maximum size in bytes for decompressed request bodies (32 MiB).
Maximum size in bytes for Server-Sent Events (2 MiB).
Enable inline fetching of images in requests.
Comma-separated list of allowed hosts for inline image fetching. Empty means all hosts are allowed.
Enable automatic model registry synchronization from upstream.
Interval in seconds between model registry refreshes.
Client version to report to the upstream model registry.