Treat budgets as a runtime control, not a billing report
A billing report describes spend after it has happened. A runtime control decides, as each request is made, whether the spend is allowed. Enforcement therefore belongs in the request path, where cost can be estimated before the call, metered while the response streams, and recorded once the call completes.
Budget enforcement in the request path
- EstimateProject cost and reserve budget before the call leaves the enforcement point.
- MeterRecord usage in a normalized unit as the response streams and completes.
- DecideEvaluate the budget hierarchy and apply throttle, downgrade, block, or approval.
- RecordWrite an auditable entry for each enforcement decision.
Place one enforcement point in the request path
There are three common places to enforce budgets. They differ in how much control they give and what they cost to operate.
| Option | Strengths | Limitations |
|---|---|---|
| Gateway or proxy | Strongest central control and consistent metering. | Adds latency and becomes a critical dependency. |
| SDK middleware | Low latency and rich local context. | Coverage depends on adoption and version discipline. |
| Provider-native quotas | Useful as a coarse backstop per provider account. | Not a substitute for budgets by team, agent, or tool call. |
Normalize metering before you write policy
Budgets only compare across providers when usage is measured in one normalized unit. Once metering is normalized, each request follows the same five stages through the enforcement point:
- Identify: Resolve the caller to a user, application, and agent identity, and select the applicable budgets.
- Estimate and reserve: Estimate input tokens, assume a maximum output length, and reserve the projected cost against each budget in the hierarchy.
- Enforce on entry: If a reservation would breach a limit, apply the configured policy action instead of forwarding the call.
- Meter in flight: Track streamed output against the reservation and stop the stream if the budget is exhausted.
- Reconcile: Replace the reservation with actual usage, convert to normalized cost, and release any unused amount.
Structure budgets as a hierarchy with defined actions
Each request is checked against every budget level that applies to the caller, and the state of each level is evaluated at decision time. When a reservation would breach a limit, or a threshold is reached, the enforcement point applies a defined policy action instead of leaving the outcome to chance.
The available policy actions are:
- Throttle
- Downgrade
- Block
- Require approval
Plan for streaming, retries, loops, and delayed usage
Budget checks must hold up when a single request is not a single, instantaneous event. The stages above cover these cases as follows:
- Streaming: track streamed output against the reservation, and stop the stream if the budget is exhausted.
- Retries, tool calls, and agent runs: record a correlation identifier that links them in the audit log.
- Delayed usage: reconcile each reservation against actual usage, convert it to normalized cost, and release any unused amount.
Audit logging and rollout checklist
Every enforcement decision should be written to an audit log. Each entry should capture:
- Caller identity: user, application, and agent identity for every request.
- Budget path: each budget level evaluated and its state at decision time.
- Estimate, reservation, and final reconciled usage and cost.
- Policy action taken, the reason, and the policy version applied.
- Provider, model, and the price table version used for cost.
- Correlation identifier linking retries, tool calls, and agent runs.