Why fan-out breaks per-minute limits
A subagent design turns one user request into a burst: a planner emits 30 research or review tasks and a worker pool fires them together. Provider limits are written in per-minute terms, but they are enforced over shorter intervals. Anthropic notes that a limit of 60 requests per minute might be enforced as one request per second, so short bursts can trigger rate limit errors even when the minute total is fine.1 It also says a sharp increase in usage can cause 429s on its own.1 A fan-out is exactly that shape.
The limit is also shared. Anthropic enforces limits at the organization level, with optional workspace limits you set yourself.1 On Azure, quota is scoped to the subscription, and Global Standard deployments of the same model and version share one pool across all regions in that subscription.2 So one tenant's run, a nightly batch and another team's agent all draw on the same bucket. Without a budget, whoever fires first wins and everyone else gets 429s.
This post covers the part that bounding agent loops and deciding which requests survive a quota shortfall do not: how many calls may be in flight, per run and per tenant, and what happens to the calls that do not fit.
Turn a tokens-per-minute limit into a slot count
You cannot schedule against "tokens per minute" directly, because you control how many calls are in flight, not how many tokens a minute contains. Convert in three steps.
- Find the binding limit: for your call shape, which of requests, input tokens or output tokens per minute runs out first.
- Divide it by tokens per call to get a sustainable calls per minute.
- Multiply by call latency in minutes. In-flight calls equal arrival rate times time in system, so that product is the number of slots.
Which limit binds depends on the provider. Anthropic limits requests, input tokens and output tokens per minute per model class, and only uncached input counts toward input tokens per minute: cache reads do not count, cache writes do.1 Output tokens are counted as they are produced, and max_tokens does not factor in.1 Azure publishes a requests-per-minute and tokens-per-minute pair per model, deployment type and quota tier. For some gpt-chat-latest versions the ratio is 1 RPM per 1,000 TPM, against 10 RPM per 1,000 TPM for others, so requests per minute can bind first on short calls.2 At Tier 1, for example, Global Standard gpt-6.2-sol lists 250 RPM and 250,000 TPM.2 Tiers and numbers change, so read your own limits page rather than a table copied into a runbook.
Treat the headroom as a parameter. Estimates are wrong in both directions: Anthropic estimates input tokens at the start of a request and adjusts as the request proceeds,1 and your own pre-call estimate will be looser than that. Reserve more headroom if other services share the key or the pool.
Split the slots: provider, tenant, run
One number is not a policy. Use three nested ceilings and choose each from a different question.
| Ceiling | Question it answers | Sizing rule |
|---|---|---|
| Provider budget | How much can the shared account sustain? | Binding limit minus headroom, per model |
| Tenant cap | How much of that may one customer or team hold? | A share of the slots, with a small guaranteed floor |
| Run cap | How wide may one fan-out go? | Small relative to the tenant cap, so one tenant can run several jobs |
Continuing the illustrative example with 26 slots: a tenant cap of 10, a run cap of 6, and a floor of 2 slots reserved for interactive work. Five busy tenants would oversubscribe the caps (50 against 26), which is intended. Caps are ceilings, not allocations; the shared pool is first-come within them. If you want guarantees rather than ceilings, make the floor a real reservation.
Keep two budgets per model, not one, if you run mixed traffic. A chat answer a person is waiting on should not queue behind a 200-call background audit. The simplest form is a reserved interactive floor plus a shared remainder; the audit can only ever use the remainder.
Acquire narrow to wide
The order of acquisition matters more than the numbers. If a call grabs a shared slot first and then waits on its tenant's cap, a saturated tenant parks calls on shared capacity and blocks everyone. Acquire the run limit, then the tenant limit, then the shared slot, and the token reservation last. A call waiting on its own run cap holds nothing that anyone else needs.
import asyncio, time
class TokenBucket:
"""Reserve estimated tokens; refund the difference after the response."""
def __init__(self, per_minute: int):
self.cap = float(per_minute)
self.level = float(per_minute)
self.rate = per_minute / 60.0
self.t = time.monotonic()
self.paused_until = 0.0
def _refill(self):
now = time.monotonic()
self.level = min(self.cap, self.level + (now - self.t) * self.rate)
self.t = now
async def take(self, n: float):
while True:
self._refill()
now = time.monotonic()
if now >= self.paused_until and self.level >= n:
self.level -= n
return
await asyncio.sleep(0.05)
def refund(self, n: float):
self.level = min(self.cap, self.level + n)
def pause(self, seconds: float):
# One shared pause on 429, not one retry loop per worker.
self.paused_until = max(self.paused_until, time.monotonic() + seconds)
class Admission:
def __init__(self, slots: int, otpm: int, tenant_cap: int, run_cap: int):
self.shared = asyncio.Semaphore(slots)
self.bucket = TokenBucket(otpm)
self.tenant_cap, self.run_cap = tenant_cap, run_cap
self.tenants: dict[str, asyncio.Semaphore] = {}
self.runs: dict[str, asyncio.Semaphore] = {}
async def call(self, tenant, run, est_out, send, deadline_s):
t = self.tenants.setdefault(tenant, asyncio.Semaphore(self.tenant_cap))
r = self.runs.setdefault(run, asyncio.Semaphore(self.run_cap))
async def go():
async with r, t, self.shared: # narrow to wide
await self.bucket.take(est_out)
resp = await send()
self.bucket.refund(max(0, est_out - resp.output_tokens))
return resp
# Queue with a deadline; the caller decides what a timeout means.
return await asyncio.wait_for(go(), timeout=deadline_s)Two properties to check. asyncio.Semaphore wakes waiters in order, so within a tier waiting is first-in-first-out; the run and tenant semaphores keep one tenant's backlog from filling the shared queue. And the bucket is sized on the binding limit from the worked example (output tokens), with the input side handled by the slot count; if input binds for your shape, put the bucket on input instead. For the weighted fairness described below, replace the plain semaphore with a deficit round-robin queue.
Queue, degrade or shed
Admission control needs an answer for the call that does not fit. The three answers cost different things, so choose per work class and write the choice down.
| Work class | On excess | Why |
|---|---|---|
| Interactive, user waiting | Queue briefly, then degrade | A long wait is worse than a thinner answer |
| Background, deadline in hours | Queue with a long deadline | Latency does not matter; completion does |
| Optional enrichment | Shed | Dropping it leaves a correct answer |
| Required step of a run | Queue, then fail the run cleanly | A half-finished run wastes the tokens already spent |
Degrade means narrowing the fan-out rather than failing it: run 8 subagents instead of 30, or send the long tail to a smaller model, or merge subtasks into one call. Decide the minimum viable width per run type in advance and let the planner read the width it was granted. Shed should be visible: return which subtasks were skipped, so the answer says "9 of 12 sources checked" rather than silently shrinking. Give every queued call a deadline, as deadline_s does above; a queue without deadlines turns a rate limit into unbounded latency.
Never convert a refused call into an immediate retry loop. When the provider does send a 429, honor the wait it names: Anthropic says to wait the retry-after seconds when the header is present.1 Apply that wait once to the shared bucket (pause above) so 26 workers do not each sleep and then fire together. After a 429, shrink the slot count and grow it back slowly, additive increase and multiplicative decrease, so the budget tracks what the provider actually admits.
One 429 should not be retried at all. Anthropic returns rate_limit_error with error_code enforced_spend_limit_reached when an organization hits its monthly spend cap, with no retry-after, and retries, including the SDK's automatic ones, fail until access resumes.1 Branch on the code, stop the run, and surface it. A limit you set yourself is reported differently, as a 400 rather than a 429.1
Keep one run from starving the others
Three failure modes show up once the caps exist.
- Slot hoarding by parents. A subagent that spawns children and then holds its own slot while waiting for them can fill every slot with waiting parents and deadlock the tree. Release a slot before waiting on children; only a call that is actually on the wire should hold one.
- Partial admission. If a run gets 3 of the 8 slots it asked for and holds them while it waits for the rest, two such runs can each hold half the pool and neither finishes. Grant a run its first wave all at once or at a reduced, fixed width.
- Retry amplification. A run whose calls keep failing consumes slots and tokens for nothing. Give each run a retry allowance and a token ceiling, then fail it. Bounding step, time and spend covers those limits.
For fairness across tenants, weight by plan or contract, not by arrival order. Deficit round-robin over per-tenant queues gives each tenant its share when all are busy and lets an idle tenant's share be used by others. The reserved interactive floor is what keeps a background tenant's backlog from delaying a person who is waiting.
What a gateway adds, and what it does not
Provider limits are the ceiling you design to. A gateway can enforce part of the same shape one hop earlier. INFRO's key limits are requests per minute per key, chosen from fixed tiers, and they belong to the key rather than the plan.3 A key can also carry a concurrency limit, the most requests in flight at once with streams included; one more is refused until one finishes. Giving each tenant or each agent service its own gateway key makes that a backstop behind your own scheduler. Two limits to plan around. These are request counts and in-flight counts, not tokens, so the token budget stays in your admission code. And X-RateLimit-Remaining is a best-effort upper bound, so the docs say to back off as it approaches zero but not to schedule against it.3
The gateway does not add capacity. INFRO's documentation says your own provider accounts keep their model, token and request quotas, and that it adds no shared pool of purchased capacity.3 Failover to another eligible connection you configured can move traffic to a second quota, which is useful but is a different mechanism from budgeting, and it does not treat throttling as an outage; see circuit breakers for LLM providers. A 429 from your own provider reaches you with the code provider_rate_limited, distinct from the gateway's own limit error, which lets your scheduler tell the two apart.4
To see which run is hogging a budget, send a shared trace_id and workflow on each call. GET /v1/runs then lists one row per run with requests, errors, duration, models and estimated provider cost, and sort=costliest surfaces the runs that burn the most.5 Request count per run is a direct check on whether your fan-out cap is being honored.
Checklist before you ship the budget
- The binding limit (requests, input or output tokens) is identified per model from your own limits page, not assumed.
- Slots are computed from measured tokens per call and p50 and p95 latency, with a stated headroom.
- Run, tenant and shared limits are acquired narrow to wide.
- Interactive and background work have separate floors or separate budgets.
- Every queued call has a deadline and every timeout has a defined outcome (degrade, shed or fail).
- A 429 pauses the shared bucket once and shrinks the slot count; a spend-limit 429 stops the run.
- Parents release slots before waiting on children.
- Each run has a retry allowance and a token ceiling.
- Queue wait, shed counts and per-run request counts are on a dashboard next to the 429 rate.
