API design playbook
Rules for HTTP APIs that people and AI agents can learn fast and trust. Clear resources, honest errors, safe retries and contracts that never surprise.
- Required 21
- Recommended 53
- Optional 4
An API design playbook for any HTTP and JSON API, public or internal. It covers resources and methods, data formats, errors, lists, change over time, reliability, security and contracts. Webhooks and events have their own integration and events playbook, and file uploads live in the files and media playbook. A chapter on live connections covers polling, server-sent events and WebSockets. Another chapter covers using other companies' APIs from your own code. The last chapter gives design rules for GraphQL schemas and gRPC services.
The rules rest on the HTTP standards, such as RFC 9110 and RFC 9457, and on guides that large API teams publish. Each rule has a check you can run with a single request, a contract test or a linter.
Some endpoints follow an outside protocol, such as MCP, A2A, JSON-RPC, NLWeb or the Reporting API. For those, the protocol's own schema and error format is the contract, and these rules apply to your own REST endpoints. GraphQL and gRPC APIs follow the rules of their own chapter, and the general rules on errors, lists and change over time.
AI agents call APIs more than they read pages. An API with predictable names, typed errors and a published contract lets an agent use it correctly on the first try.
Chapters
Resources and methods
Name resources as nouns, use each HTTP method for what it means, and answer with the status code that tells the client exactly what happened.
- Recommended 6
Requests and responses
Send JSON with one naming style, exact dates, safe money values and string IDs, so every field means the same thing everywhere in the API.
- Required 4
- Recommended 8
- Optional 1
Errors
Answer every error as RFC 9457 problem details. Give it a stable type, a plain message and the exact fields that failed.
- Required 1
- Recommended 4
Lists
Page through long lists with cursors, cap every page, and let clients filter and sort with plain, documented parameters that never change meaning.
- Recommended 5
- Optional 1
Changes over time
Grow the API by adding, never by breaking. When a break is unavoidable, ship a new version and give clients dates, headers and time to move.
- Required 1
- Recommended 4
Reliability
Make retries safe with idempotency keys, protect updates with ETags, set timeouts everywhere and tell clients plainly when to slow down.
- Required 2
- Recommended 4
API security
Authenticate every call with scoped tokens, authorise every object, and keep secrets out of addresses. Link to the security playbook for the attacks.
- Required 6
- Recommended 2
Contracts and docs
Make an OpenAPI file the single source of truth. Test the API against it, generate docs and clients from it, and publish it for people and agents.
- Recommended 6
- Optional 1
Live connections
Pick polling, server-sent events or WebSockets by need, check access for the whole connection, send heartbeats, resume after drops and cap each client.
- Required 2
- Recommended 3
Using other companies' APIs
Wrap each outside API in one module, write safely across timeouts, stay under its limits, survive its outages and notice its changes early.
- Required 2
- Recommended 4
GraphQL and gRPC
Design rules for GraphQL schemas and gRPC services. Mutations only by POST, deprecate before removing, batch loads, stable field numbers and deadlines.
- Required 3
- Recommended 7
- Optional 1
This is a lot to check. An Expert can check it for you.
Related playbooks
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">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.