Budgets & quotas
Budgets & quotas
Per-user and per-org limits enforced on a Redis hot-path with a Postgres ledger.
Budgets are enforced in real time on every request, with Postgres as the source of truth.
What you can set
- Per-user monthly budget (
monthly_budget, USD) - Per-org monthly token quota (
monthly_token_quota) - Usage caps per org and per team
How enforcement works
On each request the gateway:
- Checks the budget — sums the month's spend from Postgres.
- Checks the org quota — cached briefly in Redis, falling back to Postgres.
- Reserves the estimated cost atomically in Redis (with a short TTL).
- Dispatches the request.
- Commits the actual cost — or rolls back the reservation on error.
This two-tier design keeps the hot-path sub-millisecond while a durable Postgres
ledger (usage_logs, user_balances) remains authoritative.
Source of truth
Redis holds reservations for speed; the Postgres ledger is always authoritative. Balances are only mutated by the usage-logging worker in a single transaction per request.