Toolvito

Works on this device

API Rate Limit Calculator

Work out what a rate limit allows. Convert a limit between seconds, minutes, hours and days, see the burst and refill of a token bucket, the queue of a leaky bucket, the wait until the next request in a window, and the load of many users with their own limits.

Enter your values

Write a limit such as 100 requests per minute per second, hour and day, and see the spacing between requests.

Your values

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Calculate.

How to use this calculator

  1. Choose what you want: convert a limit, a token bucket, a leaky bucket, a fixed or sliding window, or quotas for many users.
  2. Type the numbers of your limit. Choose the unit of each time.
  3. Choose Calculate. The steps show the arithmetic with your numbers.

The formulas

  • Rate = requests allowed ÷ length of the window. Spacing = window ÷ requests.
  • Token bucket: the bucket holds at most B tokens and gets A tokens every period P, a rate r = A ÷ P. A full bucket lets B ÷ c requests through at once, where c is the tokens one request uses. The steady rate is r ÷ c. With smooth refill, n more requests take (n × c − tokens now) ÷ r. With refill in steps, the tokens come at the end of each period and the tool counts refill by refill.
  • Leaky bucket (a queue): a queue of Q requests leaves at a steady rate d. Of a burst of n, min(n, Q) wait and the rest are dropped; the last one leaves after min(n, Q) ÷ d. With steady arrivals a above d, the queue fills at a − d per second, and then a − d requests per second are dropped.
  • Fixed window: requests left = limit − requests made; with none left, wait until the window starts again. Around a reset, up to twice the limit can pass in one window length.
  • Sliding window (log): a request is allowed when fewer than N requests are younger than the window W. With the ages from the newest, a1 ≤ a2 ≤ ..., a full window waits W − aN.
  • Quotas: total load = limit per user × users × share active at once. A fair limit per user = what the server can take ÷ (users × share active).

Worked example

100 requests per minute is 1.667 requests per second, 6,000 per hour and 144,000 per day: one request every 0.6 s keeps an even pace.

A token bucket of 20 tokens that gets 5 tokens every second lets 20 requests through at once and then 5 per second. 50 requests take 6 seconds: 20 at once, and the other 30 need 30 ÷ 5 = 6 seconds of refill. An empty bucket is full again after 4 seconds.

A leaky bucket with a queue of 10 that handles 2 requests per second gets a burst of 25: 10 wait, 15 are dropped, and the last one leaves after 5 seconds.

A sliding window of 5 requests per 60 seconds, with requests made 2, 10, 18, 33, 58 and 75 seconds ago, has 5 requests in the window. The next request waits 60 − 58 = 2 seconds.

500 users with 60 requests per minute each, of whom 20% are active at once, can send up to 100 requests per second.

Limits you should know

  • The tool works out what a limit allows. It does not send requests and does not know the limits of any API: read them in the documentation of the API.
  • Rate limiters differ in details: when a window starts, whether tokens come smoothly or in steps, and whether a refused request uses tokens. Check how your limiter works.
  • A server that limits requests usually answers 429 Too Many Requests (RFC 6585), often with a Retry-After field (RFC 9110). An IETF Internet-Draft, "RateLimit header fields for HTTP" (draft-ietf-httpapi-ratelimit-headers), proposes fields that tell clients the limit; its versions have used different field names, so check the version your API follows.
  • For waits between retries after a 429, use the Retry Backoff Calculator and the HTTP Retry Policy Generator.

Related tools