Budget reservations
Prevents concurrent paid work from collectively overrunning a shared budget by reserving capacity before execution and settling actual cost afterward.
budget-reservation-enforcement
See how it helpsWhen is it useful?
Use when concurrent paid operations can all pass a budget check and collectively overspend.
What does it help you do?
- Reserves estimated cost atomically against committed spend and already held capacity.
- Settles reservations against actual cost or releases work stopped before provider execution.
- Defines expiring leases, recovery and distinct warning versus hard-stop policies.
Try asking this
Model twenty simultaneous AI requests so admitted work stays within one shared budget, with reservations recoverable after a worker crash. Crash one admitted worker before the provider call and another after it. Release only confirmed unused reservations; preserve uncertain spending for reconciliation.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Budget Reservation & Enforcement
Checking if (currentSpend < budgetLimit) before starting an expensive LLM run or batch job is vulnerable to classic Time-of-Check to Time-of-Use (TOCTOU) races: 20 concurrent requests all see $9.50 < $10.00 and together spend $25.00.
Workflow
- Two-phase budget reservation pattern (
Reserve -> Settle / Release):- Before launching a costly operation (LLM call, multi-step agent run, batch export), calculate a conservative upper-bound estimate (
estimatedCostMicrosfrom prompt token count +max_tokens* output rate). - Atomically check and reserve capacity against the budget window: $$\text{committedSpend} + \text{activeReservations} + \text{newReservation} \le \text{hardLimit}$$
- Persist a reservation record (
reservationId,tenantId,budgetId,reservedMicros,status: 'held',expiresAt). - When the operation finishes (or fails):
- Settle: Atomically record the actual ledger entry (
actualCostMicros) and transition the reservation to'settled'(releasingreservedMicros - actualCostMicros). - Release on abort: If the operation is rejected before reaching the provider, transition the reservation to
'released'.
- Settle: Atomically record the actual ledger entry (
- Before launching a costly operation (LLM call, multi-step agent run, batch export), calculate a conservative upper-bound estimate (
- Lease TTL and crash recovery:
- Every reservation must carry an
expiresAtlease TTL (e.g., 2–10 minutes for interactive calls, heartbeat-extended for long background jobs). - A background reaper or lazy expiration query automatically reclaims expired
'held'reservations from crashed workers so a process crash never permanently locks a customer's budget.
- Every reservation must carry an
- Multi-level budget scopes and policy actions:
- Support budgets scoped to
tenant,workspace,project,user,apiKey,agentRole, orsingleTaskRun(e.g., max$2.00per task run or max15agent turns). - Support graduated threshold policies:
- Soft warning thresholds (
50%,80%,100%): Emit deduplicated alert events (budget_threshold_crossedkeyed by(budgetId, periodStart, thresholdPct)) without interrupting execution. - Model downgrade / throttling policy: Automatically route non-critical tasks to a more economical model tier or lower concurrency when approaching the limit.
- Hard stop (circuit breaker): Reject new reservations with a clear, structured domain error (
BUDGET_EXCEEDED) and allow in-flight work to checkpoint cleanly rather than corrupting state mid-write.
- Soft warning thresholds (
- Support budgets scoped to
Anti-Patterns to Avoid
- Post-hoc-only budget checks: Only checking spend via an hourly cron job allows a runaway agent loop to burn hundreds of dollars in minutes before the next cron tick.
- Unbounded reservation locks: Holding reserved budget without an
expiresAtTTL permanently starves a tenant after a worker restart. - Spamming alert notifications: Firing a webhook on every single API call once spend exceeds
80%instead of recording that the80%threshold state was already notified for the current period.
Included files 1
SKILL.md
About this skill package
budget-reservation-enforcement
budget-reservation-enforcement: Make usage and AI costs explainable with consistent metering events, pricing, quotas, reconciliation and drill-down reports.
Show less
budget-reservation-enforcement
budget-reservation-enforcement: Make usage and AI costs explainable with consistent metering events, pricing, quotas, reconciliation and drill-down reports.
Includes the complete skill and its supporting files (1 files). The exact authored scope is preserved below.
Original skill description (source language)
Use when implementing pre-execution cost estimation, atomic budget reservations, soft warning thresholds, hard circuit breakers, and graceful lease expiration under concurrent load.
Install the skill, review its source and trust settings, then enable it for the relevant project or agent.
Requirements
- Orqestria installed on your computer.
