kmaruthi2002/universal-llm-skills/api-design
Claude Code and agent skill by kmaruthi2002/universal-llm-skills
- community
Checking that the SKILL.md file is still in the repository.
Design interfaces between software components that are easy to use correctly, hard to misuse, and safe to evolve: REST/HTTP, GraphQL, gRPC and other RPC, and event/message contracts. Covers resource and operation modelling, naming, request/response shapes, errors, pagination, filtering, idempotency, concurrency control, authentication and authorization at the API surface, rate limiting, versioning, backward compatibility, deprecation, and machine-readable specs (OpenAPI, protobuf, GraphQL SDL, AsyncAPI as examples). Use when creating or changing an endpoint, schema, or message format, reviewing an API proposal, choosing between API styles, planning a breaking change, or writing an API spec. For consuming third-party APIs use api-integrations-and-webhooks; for implementing handlers use backend-development.
Install
npx vskill@latest install kmaruthi2002/universal-llm-skills/api-designSKILL.md
The same SKILL.md was published earlier as kmaruthi2002/universal-llm-skills/api-design.
API Design
An API is a promise. Once someone depends on it, every name, field, status code, and quirk becomes something you have to keep working. Good API design is therefore mostly about two things: making the right usage obvious to the caller, and leaving room to change without breaking them.
Scope
Covers designing the contract of an interface: HTTP/REST-style APIs, GraphQL schemas, gRPC and other RPC services, and asynchronous event or message schemas. Applies to public APIs, partner APIs, and internal service-to-service APIs (internal APIs deserve the same care; "we can just update the callers" stops being true faster than expected).
Not covered here:
- Implementing the handlers, validation, and data access —
backend-development. - Calling and integrating someone else's API, webhooks —
api-integrations-and-webhooks. - Detailed authentication and authorization mechanisms —
authentication-and-authorization. - Library/function-level API design within one codebase is touched on, but its structure is mostly
software-architecture. - MCP tool and resource design —
mcp-server-development(the principles here still apply).
Core principles
1. Design from the caller's use cases, not your data model
An API that mirrors internal tables forces callers to understand your storage and makes every schema change a breaking change. Start from what callers need to accomplish: "list a customer's unpaid invoices", "cancel a subscription at period end". Model resources and operations around those tasks. Internal structure can then change freely behind the contract.
2. Consistency beats cleverness
Callers learn an API's patterns once and apply them everywhere. One endpoint that paginates differently, names IDs differently, or reports errors in another shape costs every caller time and bugs. Pick conventions — naming, casing, pagination, errors, timestamps, IDs — and apply them uniformly. In an existing API, the existing conventions win over your preferences.
3. Make correct use easy and incorrect use hard
- Required things are required; optional things have safe defaults.
- Dangerous operations are explicit (a
DELETEor a clearly namedcancelaction, never a side effect of an innocuous-looking update). - Types are precise: enums instead of free strings, structured money (amount in minor units plus currency) instead of floats, timestamps with time zones.
- Names say what things are.
expires_atbeatsexp;amount_centsor a typed money object beatsamount.
4. Every addition is forever; additions are cheap, removals are expensive
You can add optional fields, new endpoints, and new enum values (if clients were told to expect them) without breaking anyone. You cannot remove, rename, retype, or change the meaning of anything without a migration. So: start small. Expose the minimum that serves the known use cases. It is easy to add a field later and nearly impossible to remove one.
5. Assume the network fails and callers retry
Requests time out after the server has acted. Clients retry. Messages arrive twice or out of order. An API that is unsafe to retry will cause duplicate charges, duplicate emails, and duplicate orders. Design idempotency in from the start (see below).
6. The contract is the spec, not the implementation
Write the contract down in a machine-readable form when the ecosystem supports one (e.g. OpenAPI for HTTP, protobuf for gRPC, SDL for GraphQL, AsyncAPI or JSON Schema for events). A spec enables review before code, generated clients and docs, contract tests, and breaking-change detection. Whether the spec is written first or generated from code is a team choice; what matters is that it is accurate and reviewed.
Discovering existing conventions
Before designing anything in an existing system:
- Find existing APIs and specs: spec files, generated clients, route definitions, schema files, API docs, gateway configuration.
- Extract the conventions actually in use: URL structure, casing (
snake_casevscamelCasein payloads), ID format, timestamp format, pagination style, error envelope, auth scheme, versioning scheme, how list filters are expressed. - Look for a style guide or linting rules for specs (many organisations publish one; spec linters often encode it).
- Check who consumes the API: web front end, mobile apps (which cannot be force-upgraded — old versions live for years), partners, internal services. Consumer type sets how conservative you must be about change.
- Follow what you find. If existing conventions are inconsistent, follow the most common or most recent pattern and note the inconsistency rather than introducing a third variant.
Process
- List the use cases with the caller: who calls, what they are trying to do, how often, with what latency and data-volume expectations.
- Choose the style (see decision table) — usually already decided by the existing system.
- Model the resources or operations: nouns, their relationships, their lifecycle states, and the transitions between states.
- Define the shapes: request and response bodies, field names and types, required vs. optional, nullability, enums.
- Define behaviour at the edges: errors, pagination, filtering and sorting, limits, idempotency, concurrency, partial failure.
- Define security: authentication, per-operation authorization, which fields are sensitive, rate limits.
- Write the spec and examples, including error examples.
- Review against the checklist at the end, ideally with an actual consumer, and by writing a short piece of client code against the spec.
- Plan evolution: what is likely to change, and how it can change compatibly.
Choosing a style
| Style | Strengths | Weaknesses | Choose when | |
|---|---|---|---|---|
| REST-style HTTP + JSON | Universal tooling, caching via HTTP semantics, easy to explore and debug, works everywhere | Over/under-fetching for complex UIs; verbs can be awkward for non-CRUD operations | Public and partner APIs, CRUD-heavy domains, broad client diversity | |
| GraphQL | Clients fetch exactly the shape they need in one round trip; strongly typed schema; good for many UI variants | Harder HTTP caching; query cost control needed; authorization per field; N+1 risk on server | Many clients with differing data needs over a rich graph of related data, usually first-party UIs | |
| gRPC / protobuf RPC | Compact binary, fast, strongly typed, streaming, codegen in many languages | Less browser-friendly (needs a proxy/bridge), harder to inspect manually | Internal service-to-service calls, low latency, polyglot back ends, streaming | |
| JSON-RPC or simple RPC over HTTP | Simple, action-oriented | Fewer shared conventions; caching and semantics are up to you | Action-heavy internal APIs, tool/agent interfaces | |
| Events / messages (pub-sub, streams) | Decouples producers from consumers in time and availability; multiple consumers | Eventual consistency; harder to trace; schema evolution must be managed carefully | Notifying others that something happened; async workflows; integration between systems | |
| Webhooks | Push notifications to external parties over HTTP | Delivery, retries, security (signatures) and ordering are your problem | Telling external integrators about events in your system |
Mixing is normal: REST for the public surface, gRPC internally, events for integration.
Modelling resources and operations
- Resources are nouns with stable identity:
customers,invoices,invoices/{id}/line-items. Use plural collection names consistently. - Nest only for true containment, and rarely more than one level deep.
/customers/{id}/invoicesis fine for "invoices of this customer"; deep nesting like/a/{id}/b/{id}/c/{id}makes URLs brittle. Provide top-level access by ID when the child has global identity. - Model state transitions explicitly. For a domain action that is not simple field editing (cancel, approve, refund, publish), prefer either an action sub-resource (
POST /orders/{id}/cancel) or creating a resource that represents the action (POST /refunds). Letting callersPATCH status: "cancelled"hides business rules, side effects, and validation behind a field write. - Long-running operations return quickly with an operation resource (
202 Acceptedplus a status URL, or an operation ID) that callers poll or are notified about. Do not hold connections open for minutes. - Bulk operations: if callers need to act on many items, provide a batch endpoint with per-item results rather than forcing thousands of calls. Define whether the batch is atomic (all-or-nothing) or partial, and report per-item outcomes either way.
- IDs: opaque strings to the caller, even if numeric inside. Opaque IDs let you change generation schemes and avoid callers doing arithmetic on them. Avoid sequential IDs in public APIs where enumeration is a risk; prefixed IDs (
inv_...) help humans and logs.
Shapes and naming
- One casing convention for fields across the whole API.
- Timestamps: an unambiguous format with time zone (e.g. RFC 3339 / ISO 8601 in UTC). Name them for what they mean:
created_at,cancelled_at,expires_at. - Money: integer minor units plus currency code, or a decimal string plus currency. Never binary floating point.
- Enums: strings, not integers, so they are readable. Document that new values may be added and clients must handle unknown values.
- Booleans: name positively (
is_active, notis_not_disabled). If a boolean is likely to grow a third state, use an enum from the start. - Null vs. absent: define the meaning. Commonly: absent = not provided / unchanged (in PATCH),
null= explicitly cleared. Be consistent. - Envelopes: decide whether responses are bare resources or wrapped (
{ "data": ..., "meta": ... }). Wrapping lists is valuable because it leaves room for pagination metadata; wrapping single resources is optional. Be consistent. - Expansion: if callers often need related objects, consider an
expand/includeparameter rather than always embedding (which bloats responses) or never embedding (which forces many calls). - Response for writes: return the resulting resource from create and update; it saves a round trip and shows server-computed fields.
Errors
Errors are part of the contract and the part callers most often handle badly because the API was vague.
- Use the transport's status semantics correctly (for HTTP): 400 malformed/invalid input, 401 not authenticated, 403 authenticated but not allowed, 404 not found (also used to avoid revealing existence of resources the caller may not see), 409 conflict with current state, 412 precondition failed (version mismatch), 422 semantically invalid (if your convention distinguishes it from 400), 429 rate limited, 5xx server-side failures. gRPC has its own status codes with similar categories; map consistently.
- One error body shape everywhere, containing at least: a stable machine-readable code (
card_declined,insufficient_funds), a human-readable message for developers, and where relevant the field(s) at fault. A standard such as RFC 9457 "problem details" is one option. - Codes are the contract, messages are not. Callers branch on codes; messages can be reworded. Document the codes each operation can return.
- Validation errors list every invalid field at once, not just the first, so clients can show all problems in one pass.
- Say whether to retry. Distinguish transient (retry with backoff; include
Retry-Afterwhen known) from permanent errors. - Never leak internals: no stack traces, SQL, internal hostnames, or messages that reveal whether an account exists (for login and password-reset flows). Log details server-side with a correlation ID and return the ID to the caller.
Pagination, filtering, sorting
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-design/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/kmaruthi2002/universal-llm-skills/api-design)