Resources / Guides
API rate limit best practices: 10 rules for limits callers can live with
Practical API rate limit best practices: what to count, where to enforce, which headers to send, and how to keep limits fair for every client.
A rate limit is part of your API's contract. Set it carelessly and you either get knocked over by one noisy caller or frustrate the good ones. These ten rules cover what most APIs need.
1. Decide what you're protecting
Limits exist for three different reasons, and each suggests a different number:
- Capacity — your database or a downstream API can only take so much.
- Cost — every call costs compute, model tokens or third-party fees.
- Fairness — one client shouldn't crowd out the rest.
Write the reason down next to the limit. It makes the number defensible and easy to revisit.
2. Count per client, not just globally
A single global limit lets one caller use up everyone's allowance. Count per client: per API key when callers authenticate, per IP address otherwise. Keep a global ceiling on top as a safety net.
3. Use two windows: a burst limit and a daily quota
"60 requests per minute" stops bursts; "5,000 per day" caps total volume. Most real abuse — scrapers, runaway loops, agents retrying forever — gets past one of them but not both.
4. Enforce before your code runs
A limit checked inside your handler still costs a full invocation for every rejected call. Enforce limits at the gateway or platform edge, so rejected calls are nearly free.
5. Answer with 429 and Retry-After
When a client is over the limit, return 429 Too Many Requests with a Retry-After header in seconds. Never answer 500 or 503 for a limit: clients treat those as your outage, not their mistake.
HTTP/1.1 429 Too Many Requests
Retry-After: 18
RateLimit-Limit: 60
RateLimit-Remaining: 0
RateLimit-Reset: 18
6. Tell clients where they stand on every response
Send RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset on successful responses too. Well-written clients slow down before they hit the wall, and you get fewer 429s overall.
7. Give expensive endpoints their own limit
A search or report endpoint can cost a hundred times more than a lookup. One limit for the whole API is either too tight for cheap calls or too loose for expensive ones. Set a default, then override it for the heavy endpoints.
8. Expect agents and retries
AI agents and job runners retry aggressively. Combine limits with idempotency keys on writes and short response caching on reads, so retries don't multiply your work.
9. Document the limits
Put the numbers, the windows, the headers and an example 429 in your API docs. Undocumented limits look like random failures to the people calling you.
10. Watch the 429s
Track how often each client is limited. A steady trickle is healthy; a sudden spike means a bug, an attack, or a limit that's too tight for real use. Revisit numbers with data, not guesses.
Choosing an algorithm
How you count matters too — fixed windows, sliding windows and token buckets behave differently at the edges. See API rate limiting algorithms.
In Wisp
Project settings → Limits set a per-minute and per-day maximum for the whole project, for every endpoint, or for one endpoint — counted for everyone or per client (per API key when keys are required, otherwise per IP). Wisp enforces them before your code runs and answers 429 with retry-after and ratelimit-* headers. You can also ask the assistant: "at most 100 calls a day per client".
Build it with Wisp — describe an API, get it live.