VCodeX
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:

  1. Checks the budget — sums the month's spend from Postgres.
  2. Checks the org quota — cached briefly in Redis, falling back to Postgres.
  3. Reserves the estimated cost atomically in Redis (with a short TTL).
  4. Dispatches the request.
  5. 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.

On this page