Concurrent requests overspend one allowance
Detect: Ledger totals exceed the configured limit under load tests.
Recover: Use atomic reservation or bounded partitioned quotas.
Enforce token-based admission and consumption budgets so individual requests and tenants cannot exhaust shared inference capacity or spend.
Token rate limiting controls how much input and output work a caller can consume over time. Request counts alone are insufficient because one long-context generation can cost far more than many short requests. A practical design combines request, token, concurrency, and total-budget limits according to the service's bottlenecks.
Reserve estimated capacity before dispatch and reconcile actual usage after completion. Streaming and tool loops make final consumption uncertain, so include output ceilings and a policy for interrupted or missing usage reports. Local limits must coordinate with provider quotas without assuming the provider measures the same units or time windows.
A prototype can log token usage by request and derive realistic demand distributions. Avoid setting limits solely from average prompt size.
Production applies per-user and per-tenant admission, bounded output, concurrency caps, and clear retry guidance. Accounting must be atomic enough to prevent concurrent requests overspending the same allowance.
At scale, distributed limiters balance consistency and latency. Allocate capacity fairly, protect critical workflows, and monitor reserved versus consumed tokens to avoid both overload and unnecessary rejection.
Predicts input and bounded output demand for admission decisions.
Maintains tenant, user, and global allowances with atomic reservation semantics.
Accepts, queues, or rejects requests according to token and concurrency capacity.
Collects actual usage from completed and interrupted model calls.
Releases unused reservations and charges actual consumption under documented accounting rules.
sequenceDiagram
participant A as Agent runtime
participant L as Admission limiter
participant Q as Quota store
participant M as Model service
A->>L: Estimated input and output budget
L->>Q: Atomic reservation
Q-->>L: Reservation granted
L-->>A: Dispatch allowance
A->>M: Bounded generation
M-->>A: Output and usage
A->>Q: Reconcile actual consumption
Q-->>A: Remaining allowanceBind the request to trusted tenant, user, application, and priority context.
Count input and reserve a bounded output allowance plus required follow-up capacity.
Check applicable windows and concurrency limits before allocating shared capacity.
Apply output limits and stop optional work when the reserved task budget is exhausted.
Capture actual provider usage and classify incomplete or missing reports.
Release excess reservation, retain correct charges, and expose understandable retry or queue status.
Enterprise SaaS · Illustrative enterprise scenario, not a reported customer outcome.
A SaaS provider serves tenants whose document sizes and user activity differ substantially.
A few bulk users can consume the provider quota and make ordinary interactive requests fail for every tenant.
The assistant must provide predictable service while keeping tenant spending and shared capacity within limits.
A token limiter combines tenant allowances with global concurrency and a separate pool for approved batch work.
If a worker crashes before reconciliation, a reservation lease expires into a documented conservative accounting path rather than remaining locked forever.
Track admitted tokens, rejected demand, reservation waste, queue delay, and fairness across tenants. Request count alone would conceal the largest consumers.
| Decision | Benefit | Cost |
|---|---|---|
| Conservative reservations | Capacity exhaustion becomes less likely. | Overestimation can reject work that would have fit. |
| Distributed quotas | Limits remain consistent across workers. | Strong coordination adds latency and an availability dependency. |
| Priority pools | Critical interactions remain responsive during batch load. | Capacity allocation requires explicit fairness decisions. |
Detect: Ledger totals exceed the configured limit under load tests.
Recover: Use atomic reservation or bounded partitioned quotas.
Detect: Reservation age exceeds its lease.
Recover: Reconcile from provider evidence or apply the documented fallback charge.
Include tokens and concurrency for variable-sized work.
Account for consumed work on failures and cancellations.
Derive retry behavior from actual limiter state.