API Rate-Limit Header Calculator

Design a rate-limiting policy and preview the X-RateLimit headers it would produce.

Ad placeholder (leaderboard)

Before you ship a rate-limiting policy, it helps to see exactly what your API will tell clients. This tool simulates a stream of requests against a fixed-window limiter and prints the precise X-RateLimit-* and Retry-After header values for every request — so you can verify the policy and explain it in your docs.

How it works

The simulator implements a fixed-window counter. Time is divided into windows of the duration you set. Within each window the limiter allows up to an effective cap equal to your base limit plus any burst allowance, and reports that cap in X-RateLimit-Limit.

For each simulated request at time t:

  1. Determine which window t falls in; if it has crossed into a new window, reset the counter to 0.
  2. If the in-window count is below the cap, the request returns 200 OK, the counter increments, and X-RateLimit-Remaining becomes cap - count.
  3. If the cap is reached, the request returns 429 Too Many Requests, X-RateLimit-Remaining is 0, and Retry-After is set to the number of whole seconds until the window resets (rounded up).

X-RateLimit-Reset is shown here as the seconds remaining until the current window ends; in production you may emit it as an absolute Unix timestamp instead.

Example

With a limit of 5 per 10 seconds, no burst, and a client sending one request per second: requests 1–5 return 200 with remaining counting down 4, 3, 2, 1, 0; requests 6–10 return 429 with Retry-After shrinking as the window reset approaches; at t = 10s the window resets and request 11 returns 200 again.

Notes and tips

  • Always return Retry-After on a 429 so well-behaved clients back off instead of hammering you.
  • Fixed windows can permit a burst of up to 2 × limit straddling a window boundary. If you need smoother enforcement, use a token bucket or sliding-window log.
  • Document your headers publicly. Clients that read X-RateLimit-Remaining can pace themselves and generate far fewer 429s.
  • Apply limits at the identity that matters (API key, user, or IP) and consider separate, tighter limits for expensive endpoints like search or auth.
Ad placeholder (rectangle)