sdk-design
Skill0 starsChanged 5 months agoMITView on GitHub
Design Stripe-grade typed SDK clients for a developer-tool API — constructor config, resource-oriented methods, typed errors, auto-pagination, idempotency, built-in retries, and a README that converts. Use when the user wants to build, generate, or review an API client library, wrapper, or SDK. Also use when they mention "npm package for our API", "Python client", Stainless/Fern/Speakeasy, or complain that integration takes too many steps, even if they never say "SDK".
- Reads credentials
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- gridaco/gridatheir own version, first seen Oct 8, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- gridaco/grida★ 2.7ksame name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- api-keysSkill
- billing-entitlementsSkill
- devtool-contextSkill
- event-taxonomySkill
- integration-pagesSkill
- oss-to-hostedSkill
- security-pageSkill
- webhook-deliverySkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Check for .agents/devtool-context.md and read it if present (developer persona decides languages.
- Very specific: line 70
Default maxRetries: 2; settable per-client and per-request.
- Distinctive: line 71
Only retry non-mutating requests automatically *unless* idempotency keys make mutations safe, which is exactly why section 6 exists.
- Distinctive: line 93
Put no prose between a developer and their first 200 response.
- Very specific: line 105
No kitchen-sink helpers. createInvoiceAndSendEmail(), getOrCreateCustomer(): convenience composites freeze one workflow into the API …
- Very specific: line 106
No framework wrappers before demand.
- Very specific: line 107
No config for hypotheticals.
- Distinctive: line 108
No leaking internals. Exported helper utilities, public "internal" modules, and re-exported dependencies all become load-bearing the moment …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
SDK Design
The SDK is where a developer's first fifteen minutes with the product actually happen; nobody's first call is raw curl for long. The bar is Stripe and Resend: a client you can install, configure with one object, and get a typed, retried, paginated call from without reading past the README. This skill gets a client to that bar and, just as important, keeps it from bloating past it.
Before you start
Check for .agents/devtool-context.md and read it if present (developer persona decides languages; API surface shape decides resource naming; stage decides generated vs. handwritten). If absent, ask:
- Who integrates this: backend engineers, frontend/full-stack, data teams? What languages do they live in?
- What does the API surface look like: how many resources, is there an OpenAPI spec, is it still churning?
- Is there an SDK already, or is this greenfield?
The design, in order of consequence
Positions below are defaults. Deviate only with a reason.
1. Constructor: one options object, nothing positional
const acme = new Acme({
apiKey: process.env.ACME_API_KEY, // also the default if omitted
baseUrl: "https://api.acme.dev", // optional, for proxies/testing
timeout: 30_000, // optional
maxRetries: 2, // optional
});- A single object, no positional args. Positional constructors (
new Acme(key, url, timeout)) can never grow a parameter without breaking callers; an options object can. Stripe and Resend both settled here. - Fall back to an env var for the key (
ACME_API_KEY), so the zero-config path isnew Acme(). Name the variable after the product and document it in the README's first block. Key format and test/live modes are theapi-keysskill's territory; the SDK should surface which mode it's in, not hide it. - Everything beyond these four knobs starts life as "not configurable." See section 9.
2. Method naming mirrors the API's resource nouns
client.invoices.create({...}), client.invoices.retrieve(id), client.invoices.list({...}): resource namespace, then a small verb set (create / retrieve / update / list / del). The SDK is a typed projection of the API, not a second API: if the REST surface has /invoices, the SDK has .invoices, and a developer can translate between docs, SDK, and raw HTTP without a lookup table. The failure mode is RPC soup, client.createNewInvoiceForCustomer(...), where every method is its own vocabulary word and autocomplete stops being a map of the product.
3. Typed errors that tell the developer what to do
One base error, subclassed by category, thrown (never returned) with three things attached: a typed class to catch on, an actionable message, and the request ID for support:
class AcmeError extends Error { requestId?: string; status?: number; }
class AuthenticationError extends AcmeError {} // 401
class PermissionError extends AcmeError {} // 403
class NotFoundError extends AcmeError {} // 404
class ValidationError extends AcmeError { param?: string; } // 400/422
class RateLimitError extends AcmeError { retryAfter?: number; } // 429
class APIConnectionError extends AcmeError {} // network / timeoutThe message is the difference between a docs visit and a fixed bug: not "Invalid API key" but "Your API key sk_test_... is a test-mode key, but this request hit the live endpoint. Use a key starting with sk_live_ from the dashboard." Say what is wrong and what to do. Attach requestId on every error (and expose it on successes too); "include the request ID" is how Stripe support triages in one round-trip instead of five.
4. Pagination: auto-iterating, never hand-rolled
for await (const invoice of acme.invoices.list({ status: "open" })) {
// fetches next pages transparently
}list() returns an async iterable that follows cursors under the hood; the page object (with data, hasMore, cursor) stays reachable for anyone who genuinely needs raw pages. If users are writing while (hasMore) loops against your API, the SDK has failed at its one structural job. This is table stakes in every Stripe SDK; developers now expect it and read its absence as "v0.1".
5. Retries built in, configurable, honest
- Retry 429 and 5xx (plus connection errors) with exponential backoff and full jitter; respect
Retry-Afterwhen the server sends it. - Default
maxRetries: 2; settable per-client and per-request;maxRetries: 0is the off-switch. Never retry silently forever; surface the final error with attempt count. - Only retry non-mutating requests automatically unless idempotency keys make mutations safe, which is exactly why section 6 exists.
6. Idempotency keys on mutating calls
Accept idempotencyKey as a per-request option on every create/mutating method, sent as the Idempotency-Key header. Auto-generate one (UUID) for any mutating request the SDK is going to retry, so a timeout-then-retry can't double-charge or double-create. This is the Stripe move that makes maxRetries > 0 safe on POSTs. It requires the API to actually implement idempotency-key semantics; if it doesn't yet, that's the prerequisite, not an SDK workaround.
7. The README is the real quickstart
The docs site can go deep; the README must convert. Install → key → first successful call, runnable exactly as pasted, in under a minute:
## Quickstart
npm install acme
export ACME_API_KEY=sk_test_... # dashboard → API keys
import Acme from "acme";
const acme = new Acme();
const invoice = await acme.invoices.create({ customer: "cus_123", amount: 4200 });
console.log(invoice.id);Put no prose between a developer and their first 200 response. Resend's README is the calibration: shorter than you think it should be, and every line executes. Error-handling examples, pagination, and webhooks come after the first-call block, in that order.
8. Generated vs. handwritten
- Pre-v1, while the surface is still churning: a thin handwritten wrapper is fine and often faster, but structure it around sections 1-6 from day one so the generated successor is a drop-in.
- Once the OpenAPI spec stabilizes: generate. Stainless (what powers Anthropic's and OpenAI's SDKs), Fern, and Speakeasy all emit clients that already follow the patterns above and keep multiple languages in lockstep with the spec. Hand-maintaining three SDKs against a moving API is a full-time job nobody staffed.
- Either way, the ergonomics in sections 1-6 are non-negotiable. A generator that can't produce them is the wrong generator; a handwritten SDK that skips them isn't done.
9. What NOT to add
SDK work succeeds by removing steps from the integration, not by adding features. Every public method and config flag is a forever-support contract: semver'd, documented, impossible to delete without a major version and a migration guide. Growth is the default failure mode; hold the line:
- No kitchen-sink helpers.
createInvoiceAndSendEmail(),getOrCreateCustomer(): convenience composites freeze one workflow into the API surface and then diverge from the real API. If two calls compose, show the composition in the docs; don't mint a method. - No framework wrappers before demand.
@acme/nextjsand@acme/railsbefore anyone asked mean N more packages at v0.x forever. Ship them when support tickets prove the friction, not when a competitor's repo list looks longer. - No config for hypotheticals. Every option in section 1 exists because real integrations needed it (proxies →
baseUrl, CI →timeout). A flag added "in case someone needs it" is untested code with a compatibility promise attached. - No leaking internals. Exported helper utilities, public "internal" modules, and re-exported dependencies all become load-bearing the moment one customer imports them (Hyrum's Law). Export the client, the error classes, the types. Stop.
The review question for any proposed addition: does this delete a step from the median integration, or add an option to it? Only the first kind ships.
10. Language priority
Pick from the developer persona in devtool-context; absent a signal, TypeScript first, Python second, and stop there until demand is measured. Two excellent SDKs beat five half-maintained ones. An SDK whose last release predates your last API change is worse than no SDK, because it fails people who trusted it. Add Go/Ruby/Java when support volume or named customers justify the permanent maintenance cost, ideally via the generator route so the marginal language is cheap.
Artifacts to produce
- SDK design doc: the ten sections above with the user's actual decisions (languages, generated vs. handwritten, error taxonomy, retry defaults).
- Type/interface sketch of the client in the target language: constructor options, one full resource namespace, the error hierarchy.
- Ergonomics review of any existing SDK: sections 1-6 as a checklist applied to the real code, with file-level findings.
- README quickstart, written to run as pasted, tested against a real key.
- Deletion list: anything in an existing SDK that section 9 says shouldn't exist, with a deprecation path.
Related Skills
- api-keys: the constructor's first input; key prefixes and test/live modes shape the error messages in section 3.
- webhook-delivery: ship the signature-verification helper inside the SDK, one per language.
- oss-to-hosted: the SDK is often the open-source layer of a hosted product; its license and repo posture live there.
- devtool-context: developer persona decides SDK languages; create the file first if it doesn't exist.
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
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.

