Environment Variables
Environment variables are read once at startup from the process environment and a .env file in the current working directory. Changing them requires a restart. Runtime settings (providers, models, limits, logging policy, and security thresholds) are configured in the admin console and hot-reloaded without a restart.
User-facing
| Variable | Default | Effect |
|---|---|---|
DATABASE_URL | unset | Full database URL. Takes precedence over LLM_PROXY_DB_PATH. postgresql:// is rewritten to postgresql+asyncpg:// |
LLM_PROXY_DB_PATH | platform data dir + config.db | SQLite file path (used only when DATABASE_URL is unset) |
JWT_SECRET | auto-generated | JWT signing secret override; ignored if shorter than 32 chars. Changing it invalidates all sessions |
ENCRYPTION_KEY | auto-generated | Provider-key encryption override; ignored if shorter than 32 chars. Changing it makes existing stored provider keys undecryptable |
LOG_LEVEL | INFO | Application log level; --log-level overrides |
TRUSTED_PROXIES | RFC1918 + loopback + link-local ranges | CIDR list allowed to set X-Forwarded-For and X-Real-IP. Replaces the default list; empty trusts nobody; invalid CIDR fails startup |
REDIS_ENABLED | false | Master Redis switch; when false, rate limiting stays in-memory and config caching is off |
REDIS_URL | redis://localhost:6379 | Redis connection URL |
REDIS_RATE_LIMIT_ENABLED | false | Redis-backed sliding-window rate limiting (requires REDIS_ENABLED=true) |
REDIS_CACHE_ENABLED | false | Redis cache for provider and model config lookups |
REDIS_LOGGING_ENABLED | false | Reserved; no effect. Logs are always stored in the SQL database |
UVICORN_WORKERS | auto | Uvicorn worker count. Unset uses cgroup-aware CPU count capped at 16 on PostgreSQL, and always 1 on SQLite. --workers overrides |
UVICORN_TIMEOUT_KEEPALIVE | 600 | Keep-alive timeout in seconds |
UPDATE_CHECK__ENABLED | true | Double underscore. Controls whether /api/system/info checks GitHub for newer releases |
Advanced
Connection pools, timeouts, and background writer tuning. Change only when needed.
| Variable | Default | Effect |
|---|---|---|
HTTP_MAX_CONNECTIONS | 200 | Outbound HTTP connection pool size for provider calls |
HTTP_MAX_KEEPALIVE | 200 | Outbound HTTP keep-alive pool size |
HTTP_DISABLE_HTTP2 | true | Disables HTTP/2 on outbound provider calls by default |
HTTP_CLIENT_BACKEND | auto | Outbound HTTP backend: auto, httpx2, or aiohttp. auto selects aiohttp unless an outbound proxy (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY) is configured, in which case it uses httpx2 |
HTTP_ALLOWED_HOSTS | empty | Comma-separated hosts exempt from the SSRF private-address ban, for self-hosted providers on private networks and internal image hosts. Every entry weakens SSRF protection |
HTTP_MAX_DOWNLOAD_BYTES | 20971520 (20 MiB) | Maximum size buffered for a client-supplied image or file URL, enforced while streaming. Matches the 20 MB per-image ceiling of OpenAI and Gemini (Anthropic is 5 MB) |
HTTP_MAX_REQUEST_DOWNLOAD_BYTES | 67108864 (64 MiB) | Total inlined media a single request may retain across all URLs it references (matches the request body limit). Peak memory per request is this total plus at most four in-flight downloads |
HTTP_MAX_RESPONSE_BYTES | 67108864 (64 MiB) | Maximum buffered upstream response size. Larger responses fail with 502 |
DB_POOL_SIZE | min((cpu_count * 2 + 1) / workers, 80 / (2 * workers)), min 1 | PostgreSQL pool size per worker process (ignored for SQLite). The second bound caps total connections around 80 (overflow defaults to pool size) so workers do not exhaust max_connections. The DB_POOL_SIZE=10 and DB_MAX_OVERFLOW=10 lines in .env.example are examples, not defaults |
DB_MAX_OVERFLOW | same as pool size | PostgreSQL overflow connections per worker |
DB_POOL_RECYCLE_SECONDS | 3600 (min 60) | PostgreSQL connection recycle interval in seconds |
DB_POOL_TIMEOUT_SECONDS | 30 (min 1) | PostgreSQL pool checkout timeout in seconds |
REDIS_POOL_SIZE | 10 | Redis connection pool size |
REDIS_TIMEOUT | 5.0 | Redis socket and connect timeout in seconds |
REDIS_RATE_LIMIT_PREFIX | rate_limit: | Rate-limit key prefix |
REDIS_CACHE_PREFIX | cache: | Config-cache key prefix |
REDIS_CACHE_TTL_PROVIDER_CONFIG | 300 | Provider-config cache TTL in seconds |
REDIS_CACHE_TTL_MODEL_MAPPING | 300 | Model-mapping cache TTL in seconds |
REDIS_LOGGING_PREFIX / _TTL_DAYS / _BATCH_SIZE / _FLUSH_INTERVAL_MS | logs: / 30 / 50 / 250 | Reserved; no effect |
LOG_WRITE_QUEUE_SIZE | 2000 | Request-log writer queue depth; records are dropped when full |
LOG_WRITE_BATCH_SIZE | 100 | Request-log batch size |
LOG_WRITE_FLUSH_INTERVAL_MS | 500 | Request-log flush interval in milliseconds |
USAGE_WRITE_QUEUE_SIZE | 2000 | Usage writer queue depth |
USAGE_WRITE_BATCH_SIZE | 200 | Usage batch size |
USAGE_WRITE_FLUSH_INTERVAL_MS | 500 | Usage flush interval in milliseconds |
Not configurable here
These settings are stored in the database and managed from the admin console so changes apply without a restart:
- Logging policy: retention, body logging, raw stream capture, masking, sampling, sensitive keys
- Security: lockout thresholds, HSTS, request body size, auth failure delay, rate-limit buckets
- Network behavior: CORS origins, response keepalive
- Features: web search, smart routing, provider selection strategy, retry/fallback, circuit breaker, MCP security policy
- Providers, models, pricing, API keys, users, and MCP servers
.env.example
The repository includes a commented .env.example covering every variable above, plus TRUSTED_PROXIES examples for Docker/Traefik and Cloudflare.
Reserved (do not set)
LLM_PROXY_LOG_LEVEL, LLM_PROXY_LOG_FILE, and LLM_PROXY_WORKER_COUNT are set by the server launcher before starting uvicorn so worker processes inherit the resolved values. Use LOG_LEVEL, --log-level, --log-file, and --workers instead; values set directly in the environment are overwritten at startup.