agentleFS
swadhinbiswasswadhinbiswas/SKILLS/skills/docs/api-documentation/SKILL.md

api-documentation

Skill1 starsChanged 2 months agoMITView on GitHub

Document an API so an independent consumer can integrate against it without reading the server code - complete endpoint reference, real request/response examples, an error catalogue, auth, rate limits, pagination, versioning and deprecation. Use when writing or reviewing API docs, an OpenAPI spec, a "how do I call this" question, or when a consumer keeps getting 422s they did not expect.

  • Reads credentials
  • Sends data out

21 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use data-engineering, feature-flags and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • travisjneumanSkill

    data-engineering

    ETL/ELT pipelines, data warehousing (BigQuery, Snowflake, Redshift), stream processing (Kafka, Spark Streaming), orchestration (Airflow, Dagster, Prefect), dbt transformations, and data lake architecture. Use when building data pipelines, designing warehouse schemas, or implementing real-time data processing.

    Also in 4 projects that use this

  • SentrySkill

    feature-flags

    Gate a Sentry feature behind a FlagPole feature flag. Use when adding a feature flag, registering a flag in temporary.py, checking a flag from Python or the frontend, enabling a flag in tests, or asking where FlagPole rollout config lives. Trigger on "add a feature flag", "gate this behind a flag", "register a flag", "features.has", "api_expose", "OrganizationFeature", "ProjectFeature", "FlagPole".

    Also in 3 projects that use this

  • AnthropicSkill

    incident-response

    Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.

    Also in 3 projects that use this

  • xenitV1Skill

    clean-code

    Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

    Also in 3 projects that use this

  • SentrySkill

    security-review

    Finds exploitable application security vulnerabilities in code changes. Use for Warden security scans, appsec review, OWASP-style checks, authentication or authorization bugs, injection, XSS, SSRF, path traversal, secrets, unsafe crypto, webhook verification, open redirects, or sensitive data exposure.

    Also in 4 projects that use this

  • CloudflareSkill

    security-audit

    Security guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every error response has the same shape:

    line 116
  2. Very specific:

    message must not leak internals: No stack traces, no SQL, no hostnames, no "an unexpected error occurred" with a 500.

    line 148
  3. Distinctive:

    Never: document "contact us for an API key" without saying what the key can do and a test mode.

    line 171
  4. Distinctive:

    Document the numbers, the window, the scope, and the *response* to exceeding them.

    line 176
  5. Distinctive:

    Use cursor pagination for anything that can change while a consumer pages through it.

    line 196
  6. Distinctive:

    Document the compatibility contract explicitly:

    line 220
  7. Distinctive:

    Document whether a total is available, what the max page size is, and what happens on the last page.

    line 305

“Common” is measured: kept by at least 6 in 10 of the 17 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 Documentation

Success is measurable and binary: a competent developer who has never seen the service can integrate against it, unassisted, without reading server code or asking a question in a channel. Everything here serves that.

The most common failure is documentation that is descriptive (a list of fields) rather than operational (here is a call that works, here is what happens when it does not).

What a consumer needs, in the order they need it

  1. Can I call this at all? Base URL, auth (how to get a credential, what scope, where to send it), content types, and the smallest complete example.
  2. What does each endpoint do? One line per endpoint, method, path, purpose.
  3. How do I do my task? Per-endpoint: every parameter, a real request, a real success response, every error response, and the idempotency/retry contract.
  4. What will bite me? Rate limits, pagination, versioning, webhooks, known limitations.

The endpoint reference

One section per endpoint, in this order. Consistent shape is what makes a reference scannable.

POST /v1/orders — Create an order

Creates an order in pending_payment state. Idempotent when an Idempotency-Key header is supplied (see Idempotency).

Path parameters: none. Query parameters: none.

Request body (application/json):

FieldTypeRequiredConstraintsDescription
customer_idstringyes^cus_[A-Za-z0-9]{16}$Customer placing the order.
itemsarrayyes1–200 entriesLine items; see below.
items[].skustringyesmax 64 charsProduct SKU. Must be active.
items[].quantityintegeryes1–999Units of this SKU.
items[].unit_price_minorintegerno≥ 0Overrides the catalogue price. Requires items[].price_override=true on the customer.
currencystringyesISO 4217, lowercaseusd, eur, gbp. Must match the customer's settlement currency.
metadataobjectno≤ 20 keys, ≤ 4 KB totalEchoed back on the order. Not returned on list endpoints.

Example request:

curl -X POST https://api.example.com/v1/orders \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_a1b2c3d4e5f60718",
    "currency": "usd",
    "items": [
      {"sku": "TSHIRT-M-BLK", "quantity": 2},
      {"sku": "CAP-OSY", "quantity": 1, "unit_price_minor": 1500}
    ],
    "metadata": {"cart_id": "cart_9931"}
  }'

Response 201 Created:

{
  "id": "ord_01HZX4K2M9",
  "status": "pending_payment",
  "customer_id": "cus_a1b2c3d4e5f60718",
  "currency": "usd",
  "subtotal_minor": 4500,
  "tax_minor": 383,
  "total_minor": 4883,
  "items": [
    {"sku": "TSHIRT-M-BLK", "quantity": 2, "unit_price_minor": 1500, "line_total_minor": 3000},
    {"sku": "CAP-OSY", "quantity": 1, "unit_price_minor": 1500, "line_total_minor": 1500}
  ],
  "created_at": "2026-03-04T14:02:11Z",
  "links": {"self": "https://api.example.com/v1/orders/ord_01HZX4K2M9",
            "payment_intent": "https://api.example.com/v1/payment_intents/pi_3Qa"}
}

Response headers on 201: Location (order URL), X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Idempotency-Replayed: true|false.

Errors: see the error catalogue. This endpoint can return 400, 401, 403, 404 (unknown customer_id), 409, 422, 429, 500, 503.

Notes and constraints:

  • Prices are in minor units (cents). 1500 is $15.00. Never a float.
  • An empty items array returns 422, not 400 (it is structurally valid but semantically empty).
  • The order is created in pending_payment and holds inventory for 15 minutes. Payment is a separate call.

Real examples beat prose. The example above is copy-pasteable; the note about minor units is the kind of thing a schema cannot say.

The error catalogue

One page for the whole API. Consumers will read only this section.

Every error response has the same shape:

{
  "error": {
    "type": "invalid_request",
    "code": "item_sku_not_found",
    "message": "SKU 'CAP-OSY' does not exist or is inactive.",
    "param": "items[1].sku",
    "request_id": "req_01HZX4K2M9PQ",
    "docs_url": "https://docs.example.com/errors/item_sku_not_found",
    "retryable": false
  }
}
FieldMeaning
typeBroad category: invalid_request, authentication, permission, not_found, conflict, rate_limit, server. Stable.
codeSpecific, machine-readable, stable identifier. Switch on this, never on message.
messageHuman-readable, for developers. Not stable; may change. Never parse it.
paramThe offending field, in a path notation (items[1].sku). Absent when not field-specific.
request_idQuote this in support. Also the log correlation id.
retryableWhether an identical retry could succeed.

Code standards:

  • type → status mapping is fixed: invalid_request→400, authentication→401, permission→403, not_found→404, conflict→409, unprocessable→422, rate_limit→429, server→500/503.
  • Never a bare {"error": "Bad request"}. It forces the consumer to match on a string.
  • message must not leak internals. No stack traces, no SQL, no hostnames, no "an unexpected error occurred" with a 500. A 500 says code: "internal_error" and nothing else.
  • Add codes, never change them. A removed or repurposed code is a breaking change, because consumers switch on it.

Authentication and authorization

  • How to get a credential, with a real command:
    curl -X POST https://api.example.com/v1/tokens \
      -H "Authorization: Bearer $API_KEY" \
      -d '{"scope": "orders:write", "ttl": "3600s"}'
    # -> {"access_token": "tok_...","expires_at":"2026-03-04T15:02:11Z"}
  • Where it goes, and what happens if it is wrong: missing → 401 with code: "missing_authorization_header"; malformed → 401 invalid_token; expired → 401 token_expired with WWW-Authenticate: Bearer error="invalid_token".
  • Scopes, as a table: which scope each endpoint needs, and what a missing-scope 403 says. 403 means authenticated but not allowed; the message must distinguish it from 401 so the consumer knows whether to get a new token or ask for more access.
  • Never document "contact us for an API key" without saying what the key can do and a test mode.

Rate limits

Document the numbers, the window, the scope, and the response to exceeding them. Vagueness here is the single most common integration complaint.

  • Limit and window: 1000 requests per minute per API key, per endpoint group. Say which.
  • Headers on every response: X-RateLimit-Limit, -Remaining (requests left in the current window), -Reset (unix seconds when the window resets).
  • On 429: Retry-After in seconds; code: "rate_limit_exceeded"; retryable: true. Honour Retry-After; do not retry sooner.
  • Bursts: a short burst allowance (e.g. an extra 100) is fine — say so, or integrators will over-buffer and get a 429 for the wrong reason.
  • Concurrent-request cap, if you have one, and the 429 for it. This one catches people out badly because their load tests pass and production doesn't.
  • Behaviour under limit: is it a hard reject or a queue? A queued request that returns 201 eight seconds later is a different integration problem from a 429.

Pagination

Use cursor pagination for anything that can change while a consumer pages through it. Offset pagination on a mutable collection silently skips and repeats rows.

  • Default and maximum page size; what happens if the consumer asks for more (clamp, or 400? say which).
  • The response envelope:
    {"data": [ ... ], "has_more": true, "next_cursor": "eyJpZCI6Im9yZF8wMUhZWDRLMk09"}
  • next_cursor is opaque; never document its format or let consumers construct one. Cursors are often base64 — say "opaque" and mean it, or they will start parsing them and break when you change the encoding.
  • Stability: cursors are valid for 24 h; after that, 400 cursor_expired — restart from the beginning.
  • What order the results are in, explicitly, and that it is the only guarantee. "Insertion order" is a promise; "by created_at desc, id desc" is a promise. "Best effort" is a bug waiting to happen.

Versioning and deprecation

Default: URI major version (/v1/...), additive minor changes within a major. It is visible, routable, and trivially testable.

Document the compatibility contract explicitly:

ChangeBreaking?Policy
New endpoint, new optional field in a responseNoShipped immediately; announced in the changelog
New enum value in a responseYes, for strict clientsAnnounce ≥ 90 days ahead, or send the new value only behind a capability flag
New required request fieldYesNew endpoint version or a new endpoint; never silently
Removing/renaming a field, changing a type, tightening validationYesNew major version
Changing an error code or its meaningYesNever; add instead
Tightening rate limitsYes, effectivelyNever within a major version

Deprecation is a process, documented in advance. State, in the docs:

  1. Deprecation header on every response from a deprecated endpoint: Deprecation: true, Sunset: Tue, 04 Nov 2026 00:00:00 GMT, and Link: <https://docs.example.com/migrations/v1-to-v2>; rel="deprecation".
  2. A migration guide per deprecated version, with before/after code.
  3. A minimum notice period (90 days is a reasonable house default) and email + dashboard metric on usage, so you deprecate what nobody uses and can find the consumers who matter.
  4. Runtime warning for the partner, not just a doc page: log or return a Warning header naming the replacement. The consumers who will break are the ones who will not read your changelog.

Webhooks, if you have them

  • Event catalogue with a stable type string and a versioned payload schema (order.paid.v1).
  • Retry policy: how many attempts, over what period, with what backoff, and what the endpoint must do to acknowledge (return 2xx within N seconds; anything else is a retry).
  • Signature verification — a real snippet, not "verify the signature":
    # HMAC-SHA256 over the raw body, header Stripe-Signature: t=...,v1=...
    expected = hmac.new(secret.encode(), f"{t}.{raw_body}".encode(), hashlib.sha256).hexdigest()
    ok = hmac.compare_digest(expected, v1)
    And it must be over the raw body, before JSON parsing.
  • Ordering and duplicates are not guaranteed. Say so, and say the consumer must be idempotent on event.id.
  • Ordering of delivery versus the API's own eventual consistency — a consumer that gets order.paid then GETs the order and sees pending_payment is a real bug; document the propagation delay.

Tooling: OpenAPI as support, not the point

OpenAPI 3.1 (openapi.yaml) is the source of truth and is validated in CI. It is the substrate — but nobody integrates from a rendered schema page; they integrate from prose, examples, and the error catalogue. A spec with no examples and no error definitions is a spec nobody can use.

Rules:

  • openapi.yaml in the repo, linted in CI (spectral lint or redocly lint), with operationIds stable (consumers generate clients from them — changing an operationId breaks every generated SDK, so it is a breaking change even in a "no-breaking-changes" release).
  • Every schema has example; every operation has request and response examples with values copied from a real test run, not invented.
  • description fields written for a human (the param semantics, the "why"), not just the type.
  • Generate the SDK/docs from the spec, but keep the hand-written guides (quickstart, error catalogue, migration guides) in version-controlled markdown. Generated error tables are poor; hand-written ones are excellent.
  • Contract-test the spec against the running service (e.g. Schemathesis or dredd), so a documented-but-unimplemented status code fails CI rather than a consumer's week.

Gotchas

  • The documented error list is always optimistic. Docs are written when the happy path is built; the 500s and edge cases get added later and never documented. Reject an endpoint whose errors can't be enumerated.
  • Status code 200 for everything is common and destroys a consumer's ability to handle failure. 400 for a bad body, 401 unauthenticated, 403 authenticated-but-not-allowed, 404 missing, 409 conflict, 422 valid shape but invalid state, 429 throttled. Pick once and document it.
  • 401 vs 403 is ambiguous in most APIs and never documented. Say which one you return for an expired token versus a valid token lacking the scope. Consumers branch on this.
  • Timestamps without a timezone are a data-corruption bug waiting to happen. Say UTC, always, in ISO 8601 (2026-01-31T09:00:00Z).
  • Money as a float breaks silently at scale. Document minor units (cents), and whether the currency is fixed per endpoint or in a field.
  • Pagination with offset and no total count forces consumers to guess. Document whether a total is available, what the max page size is, and what happens on the last page.
  • Rate limits documented as "fair use" are unenforceable. Give numbers, the window, the scope (per key? per IP? per endpoint?), the headers you send, and exactly what to do on 429 — including whether Retry-After is present.
  • Examples that were never run are the single biggest source of wasted consumer time. Generate examples from recorded responses, or contract-test them. A pasted curl block that 404s is worse than no example.
  • A field's units or format is assumed, not stated. "duration: 300" — seconds or milliseconds? "size": bytes or KB? State it in the field description; a wrong guess can corrupt a client's data, not just display.
  • Deprecation announced in prose only is invisible to tooling. Add the Deprecation and Sunset headers, give a date, and link a migration guide. "Will be removed soon" is not a deprecation policy.
  • Generated reference docs are complete and useless. They document every parameter nobody needs and explain none of the task. Keep the generated reference for completeness, and hand-write the quickstart, the error catalogue, and the migration guides.
  • Documenting a webhook without the signature algorithm forces consumers to guess. Name the algorithm, show verification over the raw body (not a re-serialised object), and state whether delivery is at-least-once.

Review checklist

  • Base URL, auth (how to obtain, where to send, what failure looks like), and content types in the first screen.
  • A smallest-complete-example that works on a fresh machine.
  • Every endpoint: purpose, auth scope, every parameter with type / required / constraints / default, a real request, a real success response with headers, and every error it can return.
  • Prices/quantities/units stated (minor units, ISO codes, UTC timestamps).
  • Error catalogue: consistent envelope, type↔status mapping, stable codes, no internal leakage, request_id in every response.
  • Rate limits: numbers, window, scope, headers, 429 behaviour, concurrency cap.
  • Pagination: cursor opacity, page-size default and max, ordering guarantee, cursor expiry.
  • Versioning policy table, deprecation headers, minimum notice period, and a migration guide.
  • Webhooks: signature snippet over the raw body, retry schedule, at-least-once / idempotency statement.
  • openapi.yaml lints clean, examples are from real runs, and the contract test passes.

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.