Software Engineering / API & Interface Design
Design API surfaces contract-first and evolve them without breaking clients
An API is a promise to every client, including the agents that will call it, generate SDKs from it, or turn it into tools. Agents also write and change APIs quickly, which makes accidental breaking changes cheap to produce and expensive to discover. The contract has to be explicit, checked by machine, and changed deliberately.
Choose the style by the interaction
Section titled “Choose the style by the interaction”-
SHOULD choose the style deliberately:
Style Fits Contract REST over HTTP Resources with CRUD-like operations; public and partner APIs; caching OpenAPI (3.2.0 is current) gRPC Service-to-service, low latency, streaming, strong typing across languages Protobuf JSON-RPC Simple command-style calls; the base of MCP and some agent protocols JSON Schema per method GraphQL Clients that need flexible reads across many related types GraphQL schema Events / messages Asynchronous notifications, decoupled consumers AsyncAPI, CloudEvents -
MUST use one style per surface and keep it consistent; mixing conventions inside one API is a defect.
Contract first
Section titled “Contract first”- MUST write or update the contract before or with the implementation, keep it in version control, and treat it as the source of truth for docs, SDKs, mocks, contract tests and any tools or MCP servers generated from it.
- MUST lint the contract against a style guide (naming, casing, pagination, error format, security schemes) in CI.
- MUST make every operation understandable without reading the code, because agents select and call operations from these descriptions: a stable operation ID, a summary that says what it does and when to use it, documented parameters with types, formats and limits, examples for requests and responses, and every error it can return (BP-0024).
Standard behaviour
Section titled “Standard behaviour”- MUST return errors in one machine-readable shape. For HTTP APIs, use Problem Details (RFC 9457) with a stable
typeper error, so clients and agents can branch on it. - MUST make retried writes safe: idempotency keys (or naturally idempotent operations) for anything that creates, charges or sends.
- MUST bound responses: pagination (cursor-based for large or changing sets), field selection or sparse responses where useful, and documented maximums.
- MUST document and signal limits and quotas, and return a retry hint when a client is throttled.
- MUST secure every operation explicitly (authentication scheme, scopes per operation), least privilege by default, and never accept credentials in query strings.
Evolve without breaking
Section titled “Evolve without breaking”- MUST run breaking-change detection on every change in CI, comparing the proposed contract with the released one, and fail the build on breaking changes that have not been approved (for example
oasdiff breakingfor OpenAPI,buf breakingfor Protobuf). - MUST prefer additive change: new optional fields, new operations, new enum values only where clients are documented to tolerate unknown values. Renaming, removing, retyping, tightening validation or changing defaults is breaking.
- MUST deprecate before removing: mark it deprecated in the contract, announce it with a migration guide and a date, send
Deprecation(RFC 9745) andSunset(RFC 8594) headers on HTTP responses, watch usage, and remove only after the sunset date when usage is gone or owners have agreed. - SHOULD version only for breaking changes, and keep at most a small number of major versions live.
- MUST run contract tests for providers and their known consumers, and record API changes in a changelog generated from the contract diff (BP-0037).
When agents change APIs
Section titled “When agents change APIs”- MUST require agents to change the contract in the same change as the implementation, run lint and breaking-change checks, and explain any breaking change in the pull request for human approval (BP-0034).
- MUST NOT let an agent remove, rename or retype a public operation or field without an approved deprecation plan.
When to apply
Section titled “When to apply”Designing a new API, changing an existing one, generating tools or MCP servers from an API, and reviewing agent-written changes to service interfaces.
Examples
Section titled “Examples”OpenAPI operation written for people and agents:
# author: Stephen Eatonopenapi: 3.2.0info: { title: Orders API, version: 2.4.0 }paths: /orders/{orderId}/refunds: post: operationId: createRefund summary: Refund part or all of a paid order. Use only after the return is confirmed. parameters: - { name: orderId, in: path, required: true, schema: { type: string, pattern: '^ord_[a-z0-9]{12}$' } } - { name: Idempotency-Key, in: header, required: true, schema: { type: string, maxLength: 64 } } requestBody: required: true content: application/json: schema: type: object required: [amount, currency, reason] properties: amount: { type: integer, minimum: 1, description: Minor units (cents). Must not exceed the amount still refundable. } currency: { type: string, enum: [AUD, NZD] } reason: { type: string, enum: [returned, damaged, duplicate_charge] } example: { amount: 18450, currency: AUD, reason: returned } responses: '201': { description: Refund created } '409': { description: Refund exceeds refundable amount, content: { application/problem+json: { schema: { $ref: '#/components/schemas/Problem' } } } } '429': { description: Rate limited; retry after the Retry-After header } security: [{ oauth: [refunds:write] }]components: schemas: Problem: # RFC 9457 type: object properties: type: { type: string, format: uri-reference } title: { type: string } status: { type: integer } detail: { type: string } securitySchemes: oauth: type: oauth2 flows: { clientCredentials: { tokenUrl: https://auth.example.com/token, scopes: { 'refunds:write': Create refunds } } }Deprecation on the wire:
HTTP/1.1 200 OKDeprecation: @1798761600Sunset: Wed, 30 Jun 2027 23:59:59 GMTLink: <https://developer.example.com/migrate/orders-v3>; rel="deprecation"; type="text/html"CI gate:
# author: Stephen Eatonoasdiff breaking released/openapi.yaml openapi.yaml --fail-on ERRbuf breaking --against '.git#branch=main'Anti-patterns
Section titled “Anti-patterns”- Implementation first, contract generated afterwards and never reviewed.
- “Get it working” summaries such as
operationId: post2with no description. - Different error shapes per endpoint.
- Renaming a field because it reads better.
- Removing a deprecated endpoint with no notice, dates or usage check.
- Agents regenerating the contract from code and committing the diff unread.
Checklist
Section titled “Checklist”- Style chosen for the interaction; one style per surface
- Contract in version control, linted, source of truth for docs, SDKs, tools
- Operations described for people and agents: IDs, summaries, types, limits, examples, errors
- Standard errors (RFC 9457), idempotency keys, pagination, limits, explicit security
- Breaking-change detection in CI; additive by default
- Deprecation with notice, Deprecation/Sunset headers and usage tracking before removal
- Agents change contract and code together; breaking changes need human approval