Craft · November 28, 2026 · 7 min read

Rate limits in agent loops: read the headers before the 429 shows up

Claude, OpenAI and Gemini all meter requests and tokens per minute, but they count different tokens, report them in different formats and throw different 429s. Here's how an agent loop should pace itself on each one.

Some links are affiliate links; we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Disclosure

A chatbot rarely hits a rate limit. One person types, the model answers, the person reads. Agents don't work like that. An agent fires a request, runs a tool, fires again a second later with a slightly longer transcript, and if you let it fan out into subagents it does that ten or twenty times in parallel. That traffic pattern is exactly what rate limiters are built to catch, so sooner or later your agent meets a 429.

Most code handles that with one generic retry wrapper: catch the 429, sleep, try again. Fine for a demo. The trouble is that the three big APIs count different things against your limit, tell you how much room you have left in different formats, and use the same status code for problems that need very different fixes. This post goes through what each provider actually meters and how a loop can pace itself off the response headers instead of waiting to get slapped. Everything here comes from the official docs as of November 28, 2026.

Claude: cached reads are free, as far as the limiter cares

Anthropic's rate limits page meters the Messages API in requests per minute (RPM), input tokens per minute (ITPM) and output tokens per minute (OTPM), per model class. On the Start tier, Claude Sonnet 5.5 gets 4,000 RPM, 2,000,000 ITPM and 400,000 OTPM. Limits are set for the whole organization, and the page says they work as a token bucket, so capacity refills continuously instead of resetting on the minute. It also warns that a 60 RPM limit might be enforced as one request per second, which means a burst can trip it even when your per-minute total looks fine.

The detail that matters most for agents is what Anthropic calls cache-aware ITPM. Only input_tokens and cache_creation_input_tokens count toward the input limit. Tokens read from the cache don't count at all. The docs give their own example: with a 2,000,000 ITPM limit and an 80 percent cache hit rate, you could push 10,000,000 total input tokens a minute.

Run that on a typical tool loop turn. Say the turn carries 40,000 cached tokens of transcript and tool definitions, writes 2,000 new tokens to the cache and adds 300 fresh ones. Without caching, every turn charges 42,300 tokens against ITPM, and 2,000,000 divided by 42,300 is about 47 turns a minute across your entire org. With caching, the same turn charges 2,300, which works out to roughly 870 turns a minute. At that point input isn't your ceiling anymore. If each turn writes 1,200 output tokens, 400,000 OTPM caps you around 333 turns a minute. So on Claude, caching does more than cut your bill. It's also the easiest way to squeeze a lot more turns a minute out of the tier you're already on.

Output works the other way from what you might expect. Anthropic says OTPM is evaluated in real time on the tokens actually generated, and that max_tokens doesn't factor into it, so "there is no rate limit downside to setting a higher max_tokens value." Keep that in mind, because OpenAI says close to the opposite.

Claude's ramp limit is a separate trap

There's a second kind of 429 on Claude that has nothing to do with your published limits. A ramp limit caps how fast your org's usage of a model can grow. It sits at your recent peak per-minute usage plus a step, so you can climb one step a minute until you reach your real rate limit. The page says a burst of requests within a few seconds can count as a sharp increase, which is a pretty good description of an orchestrator launching a dozen subagents at once.

You can tell it apart from a regular rate limit. The error type is still rate_limit_error, but on the Messages API error.details.error_code is ramp_limit_exceeded. Anthropic's advice is to wait at least the retry-after seconds, hold traffic at a level that works, then raise it by no more than one step per minute. The Message Batches API isn't subject to ramp limits, which is one more reason bulk jobs belong in batch instead of a giant parallel loop.

For pacing, every response carries headers like anthropic-ratelimit-input-tokens-remaining and anthropic-ratelimit-output-tokens-remaining, rounded to the nearest thousand, plus matching -reset headers in RFC 3339 timestamps. One gotcha: the docs say the spend-cap 429 never carries retry-after. If a 429 shows up without that header and the message talks about your monthly usage threshold, sleeping won't fix anything. Our budget caps post covers how to treat those as a stop.

OpenAI: your max_output_tokens can count against you

OpenAI's rate limits guide meters RPM, requests per day, tokens per minute (TPM) and tokens per day, and limits apply at both the organization and project level. Long-context models get a separate rate limit for long-context requests, and some model families share a single limit, so two models can drain the same bucket.

Here's the line agent builders should read twice: "Your rate limit is calculated as the maximum of max_tokens and the estimated number of tokens based on the character count of your request." The guide's advice is to set max_tokens as close to your expected response size as you can. If your loop sends every turn with a huge output cap out of habit, you may be eating TPM headroom you never use. On Claude that habit costs nothing. On OpenAI it can.

The headers use different names and a different time format. You get x-ratelimit-remaining-requests and x-ratelimit-remaining-tokens, and the reset headers are durations like 1s or 6m0s, not timestamps. When a project-scoped token limit applies, there's also x-ratelimit-remaining-project-tokens. A shared limiter that parses Anthropic's RFC 3339 resets will choke on these, so give each provider its own parser.

OpenAI has its own version of the ramp problem. A 429 with error code slow_down means your request rate went up too quickly, and the guide says it can happen even when you're inside your RPM and TPM limits. Its rule of thumb is that once you're past 1 million input TPM, grow by no more than 50 percent every 15 minutes. Model overload is a separate case, a 503 with server_is_overloaded. The guide also points out that unsuccessful requests count toward your per-minute limit, so hammering retries just digs the hole deeper.

Two more things from that guide that bite people in practice. If you write your own retry logic, turn off the SDK's built-in retries or count them in your budget, because nested retry loops multiply requests. And for streaming, these HTTP errors only apply before the stream starts. An error after streaming begins can arrive as a stream event, and OpenAI says not to automatically replay a request after you've consumed output. That matters a lot if the stream already emitted a tool call your code acted on.

Gemini: per project, input only, plus a spending speedometer

Google's Gemini rate limits page meters RPM, input TPM and requests per day (RPD). Limits apply per project, not per API key, so handing each agent its own key doesn't buy you anything. RPD resets at midnight Pacific time, which is easy to forget if your batch kicks off at 11:30 PM on the West Coast.

Gemini also has spend-based rate limits on a rolling 10-minute window: $10 per 10 minutes on Tier 1 and $200 on Tiers 2 and 3, applied depending on billing history and account standing. Blow past it and you get 429 RESOURCE_EXHAUSTED, the same code you'd see for a plain token limit. So a Tier 1 project running an expensive agent can hit a wall on dollars per minute while its TPM looks fine. Priority inference gets its own default limit of 0.3x the standard rate limit, which we touched on in the service tiers post.

For retries, Google's troubleshooting guide says the official SDKs retry 429s and 5xx errors automatically. The Python SDK tries up to four times with roughly a 1-second initial delay and a 60-second max. It says to retry only transient errors like 429, 408 and 5xx, never 400, 402 or 403, since those mean things like a bad key or depleted Prepay credits.

Pacing a loop instead of reacting to it

Put all that together and a decent rate-limit layer for an agent looks like this. Run one shared limiter per org or project, not per agent, since none of these providers scope limits to a single key or process. Before each call, estimate what the request will charge against the bucket using that provider's own rules. On Claude, that's uncached input plus cache writes. On OpenAI, the larger of your output cap and the input estimate. On Gemini, input tokens. After each response, overwrite your estimate with what the headers say is actually left.

When a fan-out is coming, stagger it. Launching twenty subagents over twenty seconds instead of in one burst costs you almost nothing in wall time and keeps you clear of ramp limits on Claude and slow_down on OpenAI. When a 429 does land, read the body before you sleep. Treat retry-after as a minimum, which is how both Anthropic and OpenAI describe it, and add jitter the way OpenAI and Google recommend. Back off and ramp up again on ramp_limit_exceeded or slow_down. And stop outright on spend caps and quota errors. The tool errors post covers keeping these retries below the model, so the agent never burns a turn reasoning about a 429.

Log the headers next to the usage fields you already store. A week of remaining values tells you which limit is actually binding, and whether a higher tier or a better cache hit rate would help more. If you want the bigger picture of running LLM systems in production, AI Engineering by Chip Huyen is worth a read, though it predates the specific headers above.

Newsletter

The daily agent toolkit.

New tools, MCP servers and frameworks, in one short email every morning. Free, no spam. Sign up and get the free AI agent cost cheat sheet (PDF).