agentleFS
milad-ahmdmilad-ahmd/agent-skills/skills/api-to-sdk/SKILL.md

api-to-sdk

Skill5 starsChanged 15 days agoMITView on GitHub

Generates a clean, typed, idiomatic client SDK (TypeScript, Python, Go, or Dart) from an OpenAPI/Swagger spec, Postman collection, or existing backend routes, with auth, errors, retries, pagination, docs, and tests. Use when the user asks to generate an API client, SDK, or typed fetch layer, or to wrap a REST API.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    If the spec changes often, a regenerate script (npm run generate:sdk).

    line 41
  2. Distinctive:

    Don't invent endpoints or fields that aren't in the spec or code.

    line 45
  3. Very specific:

    Keep generated code separate from the hand-written layer (for example src/generated/) so it can be regenerated safely.

    line 46
  4. Distinctive:

    Run the type-check and tests before reporting that the work is done.

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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 to SDK

A client SDK that developers enjoy using, not 10,000 lines of generated noise.

1. Find the source of truth

In priority order: an OpenAPI 3.x/Swagger file (openapi.yaml, swagger.json, a /docs-json endpoint) → a Postman collection → the backend route definitions in the repo (Express, NestJS, FastAPI, Django, Go handlers) → the docs the user provides. Validate the spec and list any problems you find (missing operationIds, untyped responses).

2. Choose the approach

  • A generator exists and fits (openapi-typescript + openapi-fetch, orval, openapi-python-client, oapi-codegen): use it, then add a thin hand-written ergonomic layer on top.
  • Small API (≤ 30 endpoints) or no spec: hand-write a small client.
  • Match the language, HTTP library and style already in the project (fetch/axios/ky, httpx/requests, dio).

3. SDK design

const client = new AcmeClient({ apiKey, baseUrl, timeoutMs: 10_000, maxRetries: 2 });
const user = await client.users.get("u_123");            // resource-grouped methods
for await (const order of client.orders.list({ status: "paid" })) { ... } // auto-pagination
  • Types for every request and response model, with enums as unions or literal types, and dates documented.
  • Auth: API key, bearer token or OAuth token provider. Never log the credentials.
  • Errors: a typed error hierarchy (ApiError carrying status, code, requestId, body, with NotFoundError, RateLimitError...).
  • Retries with exponential backoff and jitter, but only for idempotent methods and 429/5xx responses. Respect Retry-After.
  • Timeouts, cancellation (AbortSignal, context) and a configurable base URL and headers.
  • Pagination helpers (cursor or page) exposed as async iterators.
  • Zero or minimal runtime dependencies.

4. Deliver

  • The SDK source, a README with install, auth, examples for 3–5 core operations, error handling and pagination, plus JSDoc or docstrings taken from the spec descriptions.
  • Tests with a mocked HTTP layer (msw, respx, httptest) covering success, error mapping, retries and pagination.
  • If the spec changes often, a regenerate script (npm run generate:sdk).

Rules

  • Don't invent endpoints or fields that aren't in the spec or code. Mark any gaps.
  • Keep generated code separate from the hand-written layer (for example src/generated/) so it can be regenerated safely.
  • Run the type-check and tests before reporting that the work is done.

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.