Create a budgeted key
Set both fields when creating the key:1d, 7d, and 30d. Budgets require Postgres persistence and reviewed pricing for every route the key can reach.
How enforcement works
- The gateway estimates input and maximum requested output tokens.
- It reserves the highest possible cost across weighted and fallback routes.
- Concurrent reservations lock the budget period, preventing oversubscription.
- After completion it settles using provider-reported cost, observed usage with reviewed pricing, or the reserved amount.
- Failed provider calls release their reservation when no spend occurred.
budget_exceeded with Retry-After pointing toward period reset.
View budgets
limit_usd, spent_usd, reserved_usd, available_usd, utilization, starts_at, and ends_at.
Existing-period summaries are advisory snapshots and do not lock budget keys or periods. At rollover, the endpoint briefly locks only keys missing a current period while it initializes that period. Concurrent reservations or settlements may complete immediately after a snapshot; admission enforcement remains authoritative.
Budget alerts
Settled spend creates deduplicated alerts at 80% and 100%. Self-managed deployments can configure one Slack or Google Chat destination through an environment variable or, preferably for containers, a read-only secret file:Stale reservations
A process crash can leave a reservation without final provider usage. Active provider operations heartbeat their reservation. After the configured stale window without a heartbeat, the reconciler charges the full reserved amount rather than silently allowing possible spend to bypass the cap.reconciliation_attempts, reconciliation_error_type, reconcile_after, quarantined, and reconciliation_quarantined_at; repair the underlying record and use the manual reconcile endpoint when immediate recovery is required.
The budget ledger is enforcement-grade. Reserved entries remain until settlement or reconciliation. Finalized per-request entries remain queryable until data_governance.budget_ledger_retention_days expires, while budget-period spend/reserved aggregates remain authoritative after that cleanup. The ledger is not an invoice, and it does not reconcile provider bills, taxes, credits, or negotiated pricing automatically.