Skip to main content
Codex-LB is configured using environment variables with the 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:
  1. System environment variables
  2. .env file (tracked in git, shared defaults)
  3. .env.local file (gitignored, local overrides)
The .env.local file takes precedence over .env, which takes precedence over system defaults.
For Docker deployments, use the -e flag or --env-file option to pass environment variables to the container.

Database Configuration

string
default:"sqlite+aiosqlite:///~/.codex-lb/store.db"
Database connection URL. Supports SQLite and PostgreSQL.SQLite (default):
PostgreSQL:
See Database Configuration for detailed setup.
boolean
default:"true"
Automatically run database migrations on startup. Recommended for most deployments.
boolean
default:"true"
Create a backup of the SQLite database before running migrations. Only applies to SQLite databases.
integer
default:"5"
Maximum number of SQLite backup files to retain. Older backups are automatically deleted.
integer
default:"15"
Maximum number of database connections in the connection pool. Only applies to PostgreSQL.
integer
default:"10"
Maximum number of connections that can be created beyond pool_size. Only applies to PostgreSQL.
float
default:"30.0"
Timeout in seconds when waiting for a database connection from the pool.

Upstream Configuration

string
default:"https://chatgpt.com/backend-api"
Base URL for the upstream ChatGPT backend API. Do not include the /codex suffix.
float
default:"30.0"
Connection timeout in seconds for upstream API requests.
float
default:"300.0"
Maximum idle time in seconds for streaming responses before timing out.

OAuth & Token Refresh

string
default:"https://auth.openai.com"
Base URL for the OpenAI authentication service.
string
default:"app_EMoamEEZ73f0CkXaXp7hrann"
OAuth client ID for OpenAI authentication. Do not change unless instructed by OpenAI.
string
default:"openid profile email"
OAuth scopes to request during authorization.
float
default:"30.0"
Timeout in seconds for OAuth authorization and token exchange requests.
string
default:"http://localhost:1455/auth/callback"
OAuth redirect URI for the authorization callback. Must match the registered redirect URI.See OAuth Configuration for details on redirect URIs.
string
default:"127.0.0.1"
Host address for the OAuth callback server. Defaults to 0.0.0.0 in Docker containers.
integer
default:"1455"
Port for the OAuth callback server.
Do not change this port. OpenAI has strict requirements for the callback port. Changing it may break authentication.
float
default:"30.0"
Timeout in seconds for token refresh requests.
integer
default:"8"
Interval in days between automatic token refreshes. Codex-LB automatically refreshes account tokens to keep them valid.

Encryption

string
default:"~/.codex-lb/encryption.key"
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:
The encryption key file is critical. If lost, encrypted data cannot be recovered. Back up this file securely.

Usage Tracking

float
default:"10.0"
Timeout in seconds for fetching usage data from the upstream API.
integer
default:"2"
Maximum number of retries when fetching usage data fails.
boolean
default:"true"
Enable automatic background refresh of usage data for all accounts.
integer
default:"60"
Interval in seconds between automatic usage data refreshes.

Firewall & IP Access Control

boolean
default:"false"
Trust X-Forwarded-For headers for client IP detection.
Only enable this when Codex-LB is behind a trusted reverse proxy (like nginx or Cloudflare). Enabling this without a trusted proxy allows clients to spoof their IP addresses.
See Firewall Configuration for setup details.
string
default:"127.0.0.1/32,::1/128"
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

boolean
default:"true"
Terminate the application if database migrations fail. Recommended for production.
boolean
default:"true"
Automatically remap legacy Alembic revision IDs during migrations.
boolean
default:"false"
Log the shape of proxy requests for debugging. Not recommended in production.
boolean
default:"false"
Log raw cache keys in request shape logs. Only applies if LOG_PROXY_REQUEST_SHAPE is enabled.
boolean
default:"false"
Log full request payloads for debugging. Not recommended in production due to sensitive data.
integer
default:"33554432"
Maximum size in bytes for decompressed request bodies (32 MiB).
integer
default:"2097152"
Maximum size in bytes for Server-Sent Events (2 MiB).
boolean
default:"true"
Enable inline fetching of images in requests.
string
default:""
Comma-separated list of allowed hosts for inline image fetching. Empty means all hosts are allowed.
boolean
default:"true"
Enable automatic model registry synchronization from upstream.
integer
default:"300"
Interval in seconds between model registry refreshes.
string
default:"0.101.0"
Client version to report to the upstream model registry.

Example Configurations

Local Development

Docker Deployment

PostgreSQL with Reverse Proxy