Every API documents its rate limit in whatever unit suits it: 10 requests per second, 60 per minute, 10,000 per day. To write code that stays inside the limit, you need it in one unit, and you need to know the delay to leave between calls.
Convert to requests per second
Requests per second (RPS) is the easiest unit to work with, because it converts directly into a delay between requests. Divide the limit by the number of seconds in its period: 60 for a minute, 3,600 for an hour, 86,400 for a day.
Add a safety buffer
Running at exactly the documented limit is asking for errors. Clocks drift, requests retry, and some APIs count a request when it starts while others count when it ends. Leaving 10 to 20% headroom avoids most of that trouble.
Requests per second
60 ÷ 60 sequals1
With safety buffer
1 × (1 − 15%)equals0.85/s
Gap between requests
1,000 ms ÷ 0.85equals1,176.5 ms
So instead of sending one request every 1,000 ms, send one roughly every 1,177 ms.
Daily limits are slower than they look
10,000 requests a day sounds like a lot. Spread evenly, it is only about 0.12 requests per second. With a 15% buffer, that means one request roughly every 10.2 seconds. If your job needs to finish in an hour, a daily limit like this is the real constraint, not the per-minute one.
Faster limits
At 500 requests per minute with a 10% buffer, the safe rate is 7.5 requests per second, or one every 133 ms. At this speed you are usually sending requests in parallel rather than one after another, so think of it as 7.5 requests in flight each second.
Other limits to check
- Token limits: AI APIs often limit tokens per minute as well as requests, and the token limit is frequently the one you hit first.
- Per-endpoint limits: some APIs give each endpoint its own limit. Convert each one separately.
- Burst limits: an API may allow short bursts above the average rate. Do not plan around bursts.
- Response headers: many APIs report your remaining quota in each response. Read them if they are there.
How long will a big job take?
Rate limits turn into time very quickly. Suppose an API allows 600 requests per minute, and you run at 80% of that to leave headroom: 8 requests per second. Processing 50,000 records then takes 50,000 ÷ 8 = 6,250 seconds, about 1 hour 44 minutes. If the job has to finish within a nightly window, that number tells you whether you need a higher limit, batching, or parallel accounts before you start.
Concurrency: how many requests in flight
Requests per second and requests in flight are different things. If each request takes 2 seconds and you want 8 per second, you need about 8 × 2 = 16 requests running at once. This relationship, known as Little's Law, explains why a slow API can hit a concurrency limit long before it hits a rate limit, and why a sudden slowdown on the provider's side can make your queue back up.
How providers count
- Fixed window: a count that resets at the start of each minute. Bursts at the edge of two windows can briefly double your real rate.
- Sliding window: counts the last 60 seconds continuously, which smooths that out.
- Token bucket: allows short bursts up to a bucket size, then refills at a steady rate. Many APIs work this way.
Many APIs report where you stand in response headers, often with names like X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Reading them lets your code slow down before it gets rejected rather than after.
Retrying the right way
When you get a 429 Too Many Requests error, check for a Retry-After header and wait at least that long. If there is none, back off exponentially (wait 1 second, then 2, then 4, and so on) and add a little random jitter so that many clients do not all retry at the same instant. Cap the number of retries and log failures, so a persistent problem is noticed instead of silently looping.
Tip: When you do get a 429 Too Many Requests error, wait before retrying and increase the wait each time. Retrying immediately just uses up more of the limit.
Questions people ask
- What is a token bucket rate limit?
- A limit that allows short bursts up to a bucket size, then refills at a steady rate. Many APIs work this way, so brief spikes succeed while sustained overuse is rejected.
- How do I know how close I am to a rate limit?
- Read the rate-limit headers many APIs return, often named like X-RateLimit-Remaining and X-RateLimit-Reset, and slow down before reaching zero.
- How do I convert requests per minute to requests per second?
- Divide by 60. For hourly limits divide by 3,600 and for daily limits by 86,400.
- How much headroom should I leave under an API rate limit?
- 10% to 20%. At 60 requests per minute with a 15% buffer, send one request about every 1,177 ms instead of every 1,000 ms.
- What should I do after a 429 Too Many Requests error?
- Wait before retrying and increase the wait each time. Retrying immediately uses up more of the limit.
- How long does it take to process 50,000 requests at 600 RPM?
- At 80% of the limit (8 requests per second), about 6,250 seconds, or 1 hour 44 minutes.
- How many concurrent requests do I need?
- Requests per second × average response time. At 8 per second with 2-second responses, you need about 16 in flight.