agentleFS
MohOneXMohOneX/claude-opus-skills/api-contract-design/SKILL.md

api-contract-design

Skill0 starsChanged 5 months agoMITView on GitHub

Designs and reviews API contracts (REST, RPC, GraphQL, library interfaces) for evolvability, backward compatibility, and failure semantics. Use when defining new endpoints/interfaces, versioning an API, reviewing a schema, or deciding how breaking changes propagate to clients.

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Failure: every error the caller must distinguish, retriability, partial-success behavior.

    line 14
  2. Distinctive:

    Default values are part of the contract.

    line 24

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Contract Design

An API is a promise enforced by other people's code. The cost of a bad contract is paid forever by every caller; design for the version you cannot recall.

Model the contract as four coupled surfaces

  1. Shape: types, required vs optional fields, nullability, enums (open vs closed).
  2. Semantics: what each call means, idempotency, ordering guarantees, side effects, consistency level.
  3. Failure: every error the caller must distinguish, retriability, partial-success behavior.
  4. Evolution: what can change without breaking callers, and how clients discover capabilities.

A change is "compatible" only if it is safe across all four — a field that is shape-compatible can still be semantically breaking.

Compatibility rules that actually hold

  • Adding an optional field: safe. Making an optional field required: breaking.
  • Widening an accepted input: safe. Narrowing output guarantees: breaking.
  • Closed enums break when you add a variant clients must handle; prefer open enums + documented "unknown" handling.
  • Default values are part of the contract. Changing a default is a silent breaking change.
  • Tightening validation breaks existing valid-but-sloppy callers. Loosen freely, tighten via new version.

Failure semantics (the part most designs skip)

  • Make idempotency explicit: which calls are safe to retry, and is there an idempotency key?
  • Distinguish retryable (5xx, timeout) from terminal (4xx) at the type level so clients don't retry into duplication.
  • Define partial success precisely — batch endpoints must say which items succeeded, not just "200 OK".
  • Errors are an API. Stable codes + machine-readable detail beat prose messages clients will regex.

Adversarial validation

  • A hostile client sends nulls, unknown enum values, huge payloads, out-of-order calls, and double-submits. Does the contract still have defined behavior?
  • A future you adds a feature. Does the schema have room, or does it force a v2?
  • Two clients on different versions hit the same backend. Does data written by one corrupt the view of the other?
  • Network dies mid-request. Can the client tell whether the write happened?

Non-obvious tradeoffs

  • Versioning strategy (URL vs header vs field-level) trades discoverability against routing complexity; field-level evolution usually beats hard version cuts.
  • Rich, nested responses reduce round-trips but couple clients to internal structure — every field you expose is a future migration constraint.
  • Strong typing at the edge (codegen) catches shape breaks but can mask semantic breaks that look type-identical.

Output structure

Deliver: the contract (typed schema), an explicit compatibility statement (what's frozen vs evolvable), the full error taxonomy with retriability, and a migration path for the next likely breaking change.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.