# Bosskuai API Design

> Use when designing an API contract across REST, GraphQL, and event-driven interfaces: resource modeling, versioning, errors, pagination, idempotency, and integration-facing correctness.

- Skill: `wankimmy/bosskuai-api-design` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx get-skill add wankimmy/bosskuai-api-design`
- Raw SKILL.md: https://api.skillmd.com/api/skills/wankimmy/bosskuai-api-design/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: wankimmy (https://skillmd.com/u/wankimmy)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/wankimmy/bosskuai-api-design

---


# API design

Use when the open question is the shape of the contract between systems, not just the code behind it.

1. **Read the current contract surface** before proposing anything: docs, OpenAPI/GraphQL schema, event schemas, handlers, and their tests, plus every consumer and client version in use (access logs, SDK lists, partner list; say so if unknown).
2. **Model the domain**: name resources and operations after business concepts, not database tables, and make side effects explicit in the operation name.
3. **Pick the contract style on purpose** — REST, GraphQL, events, or mixed — matched to who actually consumes it, and say why.
4. **Design the unhappy paths as part of the contract, not an afterthought**: auth failure, validation errors, conflicts, timeouts, async completion, rate limits. Make errors structured and machine-readable, never a freeform string.
5. **Make the safe path the easy path**: idempotency keys for retry-safe operations (a reused key with different parameters gets an error, not the first response), stable pagination, predictable filtering and sorting.
6. **State what's additive vs breaking for every change**, and the versioning or deprecation path for the breaking ones.
7. **For events and webhooks**, settle ordering, replay, deduplication, and signature verification (over the raw body bytes; reject old timestamps) before calling the design done.
8. **When a requirement is ambiguous and nobody can confirm it**, default to the additive, backward-compatible reading and say so in one line rather than guessing at the breaking one.

For public or partner APIs, also settle these:

- **Contract first.** Review the spec for naming, resource model, and long-term fit before any implementation, and validate the whole document with an OpenAPI validator before generating clients. Generate SDKs and reference docs from the spec so they cannot drift.
- **Be consistent everywhere:** one field-naming style, one date format (ISO 8601), one ID format, one pagination style, one error shape.
- **Additive or breaking.** Safe: a new optional response field, a new endpoint, a new optional parameter, a new error code inside the existing shape, a looser validation rule, a new enum value (only if clients are documented to tolerate unknown values). Breaking: removing or renaming a field, changing a type or format, making an optional parameter required, removing an enum value, changing default behaviour or error structure, a tighter validation rule. Run a spec-diff in CI to block breaking changes without a version bump.
- **Deprecation runway:** announce with a migration guide, send `Deprecation` and `Sunset` headers, log who still calls it, contact the remaining callers, and remove only after usage is near zero and the date has passed.
- **Errors:** a stable machine-readable code, a readable message, a request id, and correct HTTP status. A 200 with an error body is a bug.
- **Rate limits are communicated:** return limit, remaining, and reset headers, and a 429 with `Retry-After`.

Check before you finish: no internal DB shape leaks into the public contract without a reason, no versioning was added without a named compatibility problem it solves, and every webhook/event flow has replay, idempotency, and authenticity. Walk each scenario that reaches the contract (each consumer, old and new versions side by side during rollout) per the shared bar, section 3, and name any you did not test.

REST conventions to check:

- **URLs:** plural, lowercase, kebab-case nouns; filters in query params; ownership via nesting (`/users/:id/orders`); non-CRUD actions as a sparing `POST /orders/:id/cancel`. No verbs in paths.
- **Status codes:** 201 with a `Location` header on create; 204 for no body; 400 malformed, 422 semantically invalid (field-level `details`), 401 unauthenticated, 403 unauthorized, 409 state conflict, 503 with `Retry-After`. Never leak stack traces or SQL in a 500.
- **Pagination:** offset for small admin/search lists (users want page numbers); cursor (opaque, fetch limit+1 to compute `has_next`) for feeds, large sets and public APIs, because offsets get slow and drift under concurrent inserts.
- **Query shape:** `sort=-created_at,price`, `price[gte]=10`, `fields=id,name` sparse fieldsets, `q=` for search.
- **Versioning:** do not version until needed; keep at most two active versions; after the `Sunset` date return 410.
- **Authorization:** check resource ownership per request, not only the role.
- Before shipping an endpoint: input validated by schema, auth required or explicitly public, rate limit set, spec updated.

Adding an integration or connector to an existing repo: read at least two existing connectors first and copy their layout, config schema, auth, retry/pagination, registry wiring and test style. Do not start from vendor docs alone or invent a second architecture; the result should look obvious in the codebase, with config validation, explicit auth and error handling, registration and tests in place.

For every outbound call, settle what happens when it goes wrong, and test each case: the endpoint down, slow or timing out (set a timeout); retries with backoff and jitter, capped at a maximum number of retries, only for calls that are safe to repeat (for example with an idempotency key); whether the caller can afford the delay, or the call belongs in a queue; the request and response logged with secrets and personal data masked; and a response with extra fields (ignore them), missing fields or a changed data type (validate and fail loudly, never coerce silently).

Full design-lens checklist and output template: `reference.md`. The shared quality bar: `../../references/checklists/engineering-quality-bar.md`.

Public API checks adapted in part from engineering/engineering-api-platform-engineer.md (agency-agents, MIT).
Adapted in part from ECC skills/api-design and api-connector-builder (affaan-m/ECC, MIT).

