robisson/build-like-amazon-agent-skills/api-contract-first
Claude Code and agent skill by robisson/build-like-amazon-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Designing APIs contract-first with backward compatibility guarantees, clear versioning strategy, error semantics, idempotency, and pagination. The API is a promise—never break existing clients.
Install
npx vskill@latest install robisson/build-like-amazon-agent-skills/api-contract-firstSKILL.md
The same SKILL.md was published earlier as robisson/build-like-amazon-agent-skills/api-contract-first.
Contract-First API Design
Overview
Contract-first means you design the API before you write implementation code. The API contract is a binding agreement with your clients: once published, it cannot be broken. This approach forces you to think from the client's perspective, establish clear semantics upfront, and create a stable interface that enables independent evolution of client and server.
At scale, APIs are used by clients you don't know, in ways you didn't anticipate, depending on behaviors you never documented. Hyrum's Law is absolute: "With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody." This means every response header, every error format, every ordering behavior becomes part of your contract whether you intended it or not.
What counts as an API
An API is any contract through which a client consumes functionality. The protocol does not change the rule — but the standard you use to express the contract does change with the protocol. Picking the right standard matters. OpenAPI is not the universal answer; it is the answer for one of the protocols below.
Pick the right contract standard for the protocol
| Protocol / surface | Recommended contract standard | Artifact filename example | |
|---|---|---|---|
| REST / HTTP | OpenAPI 3.x (canonical for REST). Smithy if you're in the AWS service style and want SDK code-gen. | openapi.yaml, service.smithy | |
| GraphQL | GraphQL SDL — the schema is the contract; .graphql schema file with queries, mutations, subscriptions, types. Optionally publish via Apollo Federation / Schema Registry. | schema.graphql | |
| gRPC | Protocol Buffers (.proto). Use proto3. The .proto is the contract; everything else (clients, servers, docs) is generated from it. | service.proto | |
| Async / event-driven (SQS, Kinesis, MSK / Kafka, EventBridge, SNS, RabbitMQ) | AsyncAPI 3.x for the channel-and-operation level (the equivalent of OpenAPI for async). For the payload schema itself, pair with JSON Schema, Avro, or Protobuf depending on your serializer. EventBridge: also publish the event schema in the EventBridge Schema Registry. | asyncapi.yaml + schemas/payment-requested.avsc | |
| Data contracts (warehouse tables, lakehouse, topics, file formats consumed by downstream pipelines) | Open Data Contract Standard (ODCS) when available — the emerging standard for producer ↔ consumer agreements on data products. Otherwise use the schema-language native to the store: dbt contracts for warehouse tables, Iceberg / Delta schema for lakehouse, Avro / Protobuf / JSON Schema for topics. | data-contract.yaml (ODCS), model.yml (dbt) | |
| MCP tool surface | MCP server manifest — the tool definitions exposed by the server (name, parameters, return shape, side-effect declaration, JSON Schema for arguments). | mcp-tools.json | |
| AI agent tool definitions | Agent tool spec — provider-native (Anthropic tool use, OpenAI tools, Bedrock agent action groups). Underlying input shape is JSON Schema. | tools.json | |
| Webhooks (outbound events you publish to subscribers) | AsyncAPI (treats publisher-to-subscriber as first-class) or OpenAPI if you describe the receiver-side endpoint contract. JSON Schema for the payload. | webhooks.asyncapi.yaml | |
| CLI public surface | Commands, flags, exit codes, output schemas (JSON output: JSON Schema). No single industry standard — document explicitly. | cli-contract.md + output-schemas/ | |
| SDK public surface | Language-native interface definitions (Java interfaces, TypeScript .d.ts, Python .pyi). Generate from the underlying API standard when possible (OpenAPI / Smithy / Proto). | generated from upstream contract |
Choosing rules
When picking the standard, the agent applies these rules in order:
- Match the protocol's native standard. Don't write OpenAPI for a gRPC service; don't try to express GraphQL in OpenAPI; don't describe Kafka payloads with REST conventions.
- Pick the standard most clients can consume. If your clients already have a Schema Registry or a SDK code-generator, use the standard that feeds those tools.
- One protocol, one canonical artifact. If a service exposes both REST and events, produce both an
openapi.yamland anasyncapi.yaml— they describe different surfaces. Do not try to merge them. - Default standards (when the user has no preference and no existing tooling):
- REST → OpenAPI 3.x
- Async / events → AsyncAPI 3.x + JSON Schema (or Avro for Kafka environments)
- gRPC →
.proto(proto3) - GraphQL → SDL
- Data contracts → ODCS when both producer and consumer can adopt it; otherwise the store's native schema language
Who is the client
Anything that consumes the API: a web UI, a mobile app, a CLI, an SDK, an MCP server, an AI agent, another internal service, a partner integration, a batch ETL job. All clients are equivalent from the contract's point of view. The word "frontend" is too narrow — use "client" or "API consumer".
This is the direct application of Amazon's 2002 API Mandate: every team exposes its functionality only through APIs, and there is no other way to consume what another team built.
When to Use
- Before writing any implementation code for a new service
- Before any client (UI, CLI, SDK, MCP, AI agent, partner) is built
- When adding new endpoints, tools, events, or messages to an existing service
- When modifying existing API behavior (to verify backward compatibility)
- When designing inter-service communication contracts
- When building APIs that will be consumed by external customers
- When creating event schemas for async communication (events are APIs too)
- When exposing tools to AI agents or MCP clients (agent tools are APIs too)
Amazon Context
Amazon services are decoupled and communicate through well-defined APIs. A team owns its API surface completely and is responsible for never breaking clients. AWS public APIs are forever—once released, they cannot be removed or have their behavior changed. This discipline applies internally as well: internal APIs have clients you've never met, in organizations you've never heard of. Breaking them causes cascading failures.
The principle "APIs are forever" drives extreme care in API design. It's far better to ship a minimal API and extend it than to ship a broad API and discover parts of it are wrong. You can always add; you can never remove.
The Process
1. Define the Contract First
Before any implementation:
- Write the API specification (OpenAPI/Swagger, Smithy, Protocol Buffers, or GraphQL schema)
- Write example requests and responses for every operation
- Write error cases — every way a request can fail and what the client receives
- Review the contract with at least one client team (or simulate a client)
- Generate client mocks from the spec so client teams can integrate immediately
The implementation serves the contract. Never let implementation convenience dictate API shape.
Record the set of contracts in .bla/design/<feature-name>/api-contracts.md — <service-name> when /onboard Path A produces it off existing code — following skills/api-contract-first/templates/api-contracts-template.md; that file is the shape of the index, never its destination. api-contracts.md is an index and decision record, never a substitute for the artefacts above: one row per surface with its protocol, the standard chosen, the artefact path and the reason, plus the clients, the versioning stance per surface and what is frozen since when. It is the file /design Step 2 and /onboard Path A produce alongside the protocol-native artefacts.
2. Backward Compatibility Rules
What You Can Do (Non-Breaking)
- Add a new optional field to a request body
- Add a new field to a response body (clients MUST ignore unknown fields)
- Add a new endpoint/operation
- Add a new optional query parameter
- Add a new enum value (if clients handle unknown values gracefully)
- Loosen a validation constraint (accept more inputs than before)
- Add a new error code (clients must handle unknown error codes)
What You Cannot Do (Breaking)
- Remove or rename a field from a response
- Remove or rename a request parameter
- Change the type of a field
- Make an optional field required
- Change the semantic meaning of a field
- Tighten a validation constraint (reject previously accepted inputs)
- Change the default value of a field
- Change error codes for existing failure modes
- Remove an enum value
- Change the URL/path of an endpoint
- Change authentication requirements
Hyrum's Law in Practice
Even these "safe" changes can break clients in practice:
- Adding a response field can break clients that do strict deserialization
- Changing response ordering (even if undocumented) breaks clients that depend on position
- Changing timing characteristics breaks clients with tight timeouts
- Changing the format of a string field (even if the schema says "string") breaks parsers
Mitigation: Use integration tests with real client traffic patterns. Monitor error rates after every deployment. Use canary deployments for API changes.
3. Versioning Strategy
Choose one strategy and apply it consistently:
URL Path Versioning (Recommended for REST)
- When to create v2: Only when a breaking change is absolutely necessary
- v1 lifetime: Minimum 12 months after v2 GA; 24 months preferred
- Migration support: Provide automated migration tooling for clients
Header Versioning
- Keeps URLs clean but harder to debug and cache
- Use when you need fine-grained versioning per-resource
Additive Versioning (Preferred at Amazon)
- Date-based versions
- Each version is a snapshot of behavior
- New clients get latest; existing clients are frozen at their declared version
- Server maintains backward compatibility for all declared versions
Key principle: Never require clients to migrate. If they're on v1 and it works, it should keep working indefinitely.
4. Error Semantics
Standard Error Response Format
Error Design Principles
- Use HTTP status codes correctly: 4xx for client errors, 5xx for server errors. Never return 200 with an error body.
- Machine-readable error codes: Clients switch on
error_code, not onmessagetext. - Human-readable messages: For debugging, not for display to end users.
- Request ID in every response: Enables correlation for debugging.
- Retry guidance: Tell the client if and when to retry (
retry_after_ms). - Stable error codes: Once published, an error code's semantics cannot change.
Error Categories
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-contract-first/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/robisson/build-like-amazon-agent-skills/api-contract-first)