Skip to content
mentoor

Topic 2 of 5 · 5 min read

Staying under request and token rate limits

Goal: Read rate-limit headers and tier limits to size a client-side throttle that keeps a workload under its quota.

Rate limits cap how much you can send per minute, in requests and in tokens, so size your client to stay under both and read the response headers to see how close you are. Providers set limits per account tier. A higher tier, reached through spend or an account request, gives higher limits.

Check yourself · 1 of 3

A batch job sends short prompts but hits 429 even though it is far below its requests-per-minute limit. What is the most likely cause?

Choose one answer

Why it matters

Hitting a 429 is not a crash, but it costs you. Calls pause, queues grow, and a burst of retries makes it worse. A small throttle in your own code keeps a batch job smooth and keeps interactive users from seeing errors.

Two limits, not one

Providers measure more than one thing. Claude documents requests per minute and input and output tokens per minute. OpenAI documents requests per minute and tokens per minute. You can hit either one first:

  • 50 short requests can use few tokens and trip the request limit.
  • 5 requests with huge prompts can trip the token limit alone.

Claude says it uses a token bucket model: capacity refills continuously up to your maximum rather than resetting once a minute. A short burst can use your whole bucket, and then you wait for it to refill. Do not assume you may send a full minute of quota in the first second.

Read the headers

Responses carry the state of your limits. Claude sends headers such as anthropic-ratelimit-requests-remaining, anthropic-ratelimit-tokens-remaining and matching -reset headers with an RFC 3339 time. OpenAI sends x-ratelimit-remaining-requests and similar. A 429 also carries a retry-after header on Claude, telling you how long to wait.

How to size a throttle

  1. Take your limits from the console for your tier: say 1,000 requests per minute and 80,000 input tokens per minute.
  2. Estimate tokens per request: a 2,000-token prompt plus a 500-token reply.
  3. Divide: 80,000 / 2,000 gives 40 requests per minute from tokens, far below the request limit. Tokens are the binding limit.
  4. Throttle to about 80 percent of that, so that estimate errors do not push you over.
import asyncio

# 40 requests/min from the token limit, run at 80 percent
INTERVAL = 60 / (40 * 0.8)   # about 1.9 seconds between calls

async def paced(calls):
    for call in calls:
        asyncio.create_task(call())
        await asyncio.sleep(INTERVAL)

Before and after

Before: a script fires 500 requests in a loop with asyncio.gather and gets 429 on most of them. After: it sends at the paced rate, watches remaining in the headers and slows down when it drops near zero.

What goes wrong

  • Counting only requests. The token limit is usually the one you hit first.
  • Ignoring output tokens. Long replies count against output limits.
  • Many workers, one quota. Ten processes sharing one key each think they have the whole limit.
  • Hardcoding numbers. Limits change by tier and over time, so read the current values.

Examples

Which limit binds

Limit Value Per request Max requests per minute
Requests per minute 1,000 1 1,000
Input tokens per minute 80,000 2,000 40

The token limit allows only 40 requests per minute, so a throttle built on the request limit would trip 429s at once.

Reading the headers

A response arrives with anthropic-ratelimit-tokens-remaining: 4000. The client sees 4,000 tokens left in the window and a next request costs 2,500, so it pauses until the -reset time instead of sending a call it expects to fail.

Key points

  • Providers limit both requests per minute and tokens per minute, and either can be the one that blocks you.
  • Rate-limit response headers show how much quota remains and when it resets, so a client can slow down before a 429.
  • Divide the token limit by tokens per request to find the real ceiling, then run at about 80 percent of it.
  • Workers that share one API key share one quota, so a throttle must be shared too.
  • Limits depend on your usage tier, so read the current values instead of hardcoding them.

Common mistakes

  • Throttling on requests per minute when the token limit is the lower ceiling.
  • Running several workers on one key without a shared throttle.
  • Sending a full minute of quota in the first seconds of a batch.
  • Hardcoding limits from a blog post instead of reading the current tier values.

Check yourself · 2 of 3

Your tier allows 60,000 input tokens per minute and each request uses 3,000. About how many requests per minute can you send?

Choose one answer

Check yourself · 3 of 3

What is the most useful thing in response headers for avoiding 429 errors?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic