API-36Recommended
Tell clients their rate limit
Limit requests per client, and tell clients the limit, what is left and when it resets.
How to do it
Answer 429 with Retry-After when the limit is hit. The RateLimit and RateLimit-Policy headers come from the IETF draft draft-ietf-httpapi-ratelimit-headers, so mark them as such and follow its latest version. The website playbook's rate limits rule covers the mechanics.
How to check
Send requests past the limit. Answers carry the limit headers, and the first refused one is 429 with Retry-After.
Sources
Related rules
- APS-49 Limit how often anyone can call your APIs in Application security
- API-77 Stay under their rate limits in API design
- AGT-24 Set quotas per agent grant in Agents as users
- AGT-72 Answer bursts with 429 instead of a stall in Agents as users
- MED-28 Limit how many uploads each account starts in Files and media
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/reliability/rate-limit-headers">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.