Skip to content

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.

ModeWhenConfiguration
SQLiteDefault, single processLLM_PROXY_DB_PATH or --config (default: ~/.local/share/llm-proxy/config.db on Linux)
PostgreSQLProduction, scaling, composeDATABASE_URL=postgresql+asyncpg://user:pass@host:5432/db
  • Bare postgresql:// and postgres:// URLs are rewritten to postgresql+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 .backup into a new file and swap it in):

    bash
    systemctl stop llm-proxy            # or however you stop the service
    sqlite3 ~/.local/share/llm-proxy/config.db "VACUUM;"
    systemctl start llm-proxy

    Run these commands against the main database file. SQLite manages the -wal and -shm sibling files automatically.

  • PostgreSQL connections check liveness before reuse and support DB_POOL_SIZE, DB_MAX_OVERFLOW, DB_POOL_RECYCLE_SECONDS, and DB_POOL_TIMEOUT_SECONDS. See Environment Variables.

  • SQLite allows only one writer at a time. Do not use it with --workers > 1 or multiple replicas.

Migrations ​

Schema migrations are the only way tables are created and updated.

  • At startup, the proxy runs alembic upgrade head once before binding the port. If the database is unreachable or a migration fails, the process exits with the migration error.
  • alembic.ini must be present in the current working directory or the repository root. Starting without it fails with Could not find alembic.ini.
  • To run or inspect migrations manually, point the environment variables at the target database first:
bash
uv run alembic upgrade head   # apply migrations
uv run alembic current        # show the current revision

Migrations 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.

FeatureRequires
Shared rate limiting across workers/replicasREDIS_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/replicaREDIS_ENABLED=true
Sticky provider routingREDIS_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: trueRedis connected
Log shippingNot 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 (default true) blocks requests when Redis errors. Set it to false to allow requests through on Redis failure.
  • Rate-limit keys use the prefix REDIS_RATE_LIMIT_PREFIX (default rate_limit:). Cache keys use REDIS_CACHE_PREFIX (default cache:).
  • Sticky routing applies only with the session_sticky provider-selection strategy (the global default) and stores keys as routing:conv:{conversation}:provider:{model}. Without Redis, session_sticky still 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:

bash
REDIS_RATE_LIMIT_ENABLED=true
# Optional: cache provider/model lookups in Redis
REDIS_CACHE_ENABLED=true

MIT licensed