Skip to content
Software Engineering / API & Interface Design

Design API surfaces contract-first and evolve them without breaking clients

  • BP-0071
  • v1.0.0
  • draft
  • guideline
  • role: planner
  • role: implementer
  • role: reviewer
  • stage: plan
  • stage: build
  • stage: verify
  • stage: operate
  • updated 2026-11-25
  • reviewed 2026-11-25
  • next review 2027-05-25

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.

  1. 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
  2. MUST use one style per surface and keep it consistent; mixing conventions inside one API is a defect.

  1. 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.
  2. MUST lint the contract against a style guide (naming, casing, pagination, error format, security schemes) in CI.
  3. 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).
  1. MUST return errors in one machine-readable shape. For HTTP APIs, use Problem Details (RFC 9457) with a stable type per error, so clients and agents can branch on it.
  2. MUST make retried writes safe: idempotency keys (or naturally idempotent operations) for anything that creates, charges or sends.
  3. MUST bound responses: pagination (cursor-based for large or changing sets), field selection or sparse responses where useful, and documented maximums.
  4. MUST document and signal limits and quotas, and return a retry hint when a client is throttled.
  5. MUST secure every operation explicitly (authentication scheme, scopes per operation), least privilege by default, and never accept credentials in query strings.
  1. 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 breaking for OpenAPI, buf breaking for Protobuf).
  2. 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.
  3. MUST deprecate before removing: mark it deprecated in the contract, announce it with a migration guide and a date, send Deprecation (RFC 9745) and Sunset (RFC 8594) headers on HTTP responses, watch usage, and remove only after the sunset date when usage is gone or owners have agreed.
  4. SHOULD version only for breaking changes, and keep at most a small number of major versions live.
  5. MUST run contract tests for providers and their known consumers, and record API changes in a changelog generated from the contract diff (BP-0037).
  1. 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).
  2. MUST NOT let an agent remove, rename or retype a public operation or field without an approved deprecation plan.

Designing a new API, changing an existing one, generating tools or MCP servers from an API, and reviewing agent-written changes to service interfaces.

OpenAPI operation written for people and agents:

# author: Stephen Eaton
openapi: 3.2.0
info: { 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 OK
Deprecation: @1798761600
Sunset: Wed, 30 Jun 2027 23:59:59 GMT
Link: <https://developer.example.com/migrate/orders-v3>; rel="deprecation"; type="text/html"

CI gate:

Terminal window
# author: Stephen Eaton
oasdiff breaking released/openapi.yaml openapi.yaml --fail-on ERR
buf breaking --against '.git#branch=main'
  • Implementation first, contract generated afterwards and never reviewed.
  • “Get it working” summaries such as operationId: post2 with 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.
  • 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