API-22Recommended
Cap the page size
Set a default page size and a maximum. Clamp or reject anything above the maximum.
How to do it
Document both numbers in the contract, for example 50 by default and 200 at most, as default and maximum on the limit parameter. This also protects the server, as in resource limits.
How to check
Request ?limit=100000. The answer holds at most the maximum, or a 400 problem names the limit.
Sources
Related rules
- API-93 Cap the size of every request body in API design
- API-94 Let clients ask for only the fields they need in API design
- API-83 Page GraphQL lists as cursor connections in API design
- AGT-78 Limit bulk reads and scraping in Agents as users
- SRH-11 Cap the size of every search in Search
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/lists/page-size-limit">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.