PostgreSQL & Redis
Database
LLM Proxy stores providers, models, API keys, users, logs, usage, and generated secrets in a single SQL database. SQLite is the default; PostgreSQL is required for multi-worker or multi-replica deployments.
| Mode | When | Configuration |
|---|---|---|
| SQLite | Default, single process | LLM_PROXY_DB_PATH or --config (default: ~/.local/share/llm-proxy/config.db on Linux) |
| PostgreSQL | Production, scaling, compose | DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/db |
Bare
postgresql://andpostgres://URLs are rewritten topostgresql+asyncpg://automatically.SQLite runs in WAL mode with foreign keys enabled. Newly created SQLite databases also enable incremental auto-vacuum, so retention sweeps gradually reclaim disk space after deleting old rows. Existing SQLite files keep their original mode; to reclaim space from an existing file, stop the service and run a one-time
VACUUM(or use.backupinto a new file and swap it in):bashsystemctl stop llm-proxy # or however you stop the service sqlite3 ~/.local/share/llm-proxy/config.db "VACUUM;" systemctl start llm-proxyRun these commands against the main database file. SQLite manages the
-waland-shmsibling files automatically.PostgreSQL connections check liveness before reuse and support
DB_POOL_SIZE,DB_MAX_OVERFLOW,DB_POOL_RECYCLE_SECONDS, andDB_POOL_TIMEOUT_SECONDS. See Environment Variables.SQLite allows only one writer at a time. Do not use it with
--workers > 1or multiple replicas.
Migrations
Schema migrations are the only way tables are created and updated.
- At startup, the proxy runs
alembic upgrade headonce before binding the port. If the database is unreachable or a migration fails, the process exits with the migration error. alembic.inimust be present in the current working directory or the repository root. Starting without it fails withCould not find alembic.ini.- To run or inspect migrations manually, point the environment variables at the target database first:
uv run alembic upgrade head # apply migrations
uv run alembic current # show the current revisionMigrations run once per launch
With --workers N, the launching process runs alembic upgrade head before spawning workers, and the workers skip it. When deploying multiple replicas, run migrations once before scaling out, because each replica launches independently.
Redis
Redis is optional, but it is required for features that need shared state across workers or replicas.
| Feature | Requires |
|---|---|
| Shared rate limiting across workers/replicas | REDIS_ENABLED=true and REDIS_RATE_LIMIT_ENABLED=true |
| Config cache (provider/model lookups) | REDIS_ENABLED=true and REDIS_CACHE_ENABLED=true |
| Settings hot-reload on every worker/replica (web search, circuit breaker, MCP servers, MCP security policy) | REDIS_ENABLED=true |
| API-key and user-role changes across workers/replicas (revocation, role, activation, budget, model allowlist) | REDIS_ENABLED=true |
| Personal tracing config changes on every worker/replica | REDIS_ENABLED=true |
| Sticky provider routing | REDIS_ENABLED=true and provider selection strategy session_sticky (the global default); other strategies never read or write the sticky key |
Last-model continuity (smart routing auto/fast/best) | REDIS_ENABLED=true and smart routing enabled |
OpenResponses response store: GET/DELETE/cancel/input_items, and background: true | Redis connected |
| Log shipping | Not supported; logs are always stored in the SQL database |
Behavior details:
- If Redis is enabled (
REDIS_ENABLED=true) but unreachable at startup, the proxy exits with a configuration error rather than degrading silently. At runtime, cache lookups fall back with warnings. redis_rate_limit_fail_closed(defaulttrue) blocks requests when Redis errors. Set it tofalseto allow requests through on Redis failure.- Rate-limit keys use the prefix
REDIS_RATE_LIMIT_PREFIX(defaultrate_limit:). Cache keys useREDIS_CACHE_PREFIX(defaultcache:). - Sticky routing applies only with the
session_stickyprovider-selection strategy (the global default) and stores keys asrouting:conv:{conversation}:provider:{model}. Without Redis,session_stickystill pins conversations deterministically in-process. Last-model continuity is written only by smart routing (auto/fast/best) and expires after 30 minutes. - Stored Responses expire after 24 hours (TTL 86400 s) and are namespaced per API key so tenants cannot read each other's responses.
- Redis holds only reconstructible state. Flushing it is safe, though it clears sticky routing state and stored Responses.
Compose defaults
The shipped compose file sets REDIS_ENABLED=true and REDIS_URL=redis://redis:6379. To share rate limiting and config caching across workers, add these to .env if they are not already set:
REDIS_RATE_LIMIT_ENABLED=true
# Optional: cache provider/model lookups in Redis
REDIS_CACHE_ENABLED=trueRelated
- Environment Variables: database and Redis settings
- Upgrades & Backups: dump and restore procedures