softspark/ai-toolkit/api-patterns
Claude Code and agent skill by softspark/ai-toolkit
- community
Checking that the SKILL.md file is still in the repository.
API design: naming, versioning, pagination, idempotency, OpenAPI, error contracts and safe retries. Triggers: API design, REST, GraphQL, OpenAPI, Swagger, error response, HTTP status, rate limit.
Install
npx vskill@latest install softspark/ai-toolkit/api-patternsSKILL.md
The same SKILL.md was published earlier as softspark/ai-toolkit/api-patterns.
API Patterns Skill
REST API Design
Resource Naming
HTTP Status Codes
| Code | Meaning | When to Use | |
|---|---|---|---|
| 200 | OK | Successful GET/PUT/PATCH | |
| 201 | Created | Successful POST | |
| 204 | No Content | Successful DELETE | |
| 400 | Bad Request | Malformed request or an established domain refusal | |
| 401 | Unauthorized | Missing/invalid auth | |
| 403 | Forbidden | No permission | |
| 404 | Not Found | Resource doesn't exist | |
| 405 | Method Not Allowed | Unsupported method; preserve Allow | |
| 409 | Conflict | Duplicate resource or current-state conflict | |
| 412 | Precondition Failed | Supplied concurrency version is stale | |
| 422 | Unprocessable | Validation error | |
| 428 | Precondition Required | Required concurrency precondition is missing | |
| 429 | Too Many Requests | Rate limited | |
| 500 | Internal Error | Server error | |
| 503 | Service Unavailable | Dependency temporarily unavailable |
Response Format
Follow the host's existing resource and collection contract. This envelope is illustrative; do not impose it on a framework that already defines another shape.
Error Response
Use the established error representation, which may be problem details, framework validation errors, or a domain-specific envelope like this example:
When implementing or reviewing failure paths, read Error contracts and safe retries. Classify from the original cause, preserve public codes and JSON types, and distinguish an unknown operation outcome from a confirmed refusal. Do not turn arbitrary server failures into invalid-input responses.
When adding client-side validation, read reference/input-validation.md from the installed security-patterns skill. Resolve that skill through the current client's catalog, since adapters may namespace skill directory names. Use one authoritative rule source and prove parity at the request boundary.
FastAPI Implementation
Parameter Documentation Conventions
The same rules apply to OpenAPI description fields, Pydantic Field(description=...), and MCP tool parameters: the description should encode the workflow, not just restate the type. A consumer (human or LLM) reads it to know how to supply a valid value, not what language primitive it is.
Prefer enums with per-value descriptions for closed sets
A free-form string for status forces the caller to guess valid values. Constrain it and document each one:
In OpenAPI, pair enum with the value meanings in the description (or x-enum-descriptions if your tooling renders it). Avoid documenting a closed set as plain string — the caller cannot tell INTERNAL is valid but internal is not.
Encode cross-field dependencies in the description
Document cross-field requirements where the dependent field is defined and encode them in the supported schema dialect. JSON Schema supports conditional requirements with dependentRequired or if/then; application state and opaque-token provenance still require prose and runtime checks. See conditional schema validation.
State the source call by name (next_cursor from the previous list response), not just "an opaque token".
Add provenance and exactness constraints for opaque IDs
Opaque identifiers (resource IDs, idempotency keys, cursors) are the most common source of bad calls because they look like something the caller can invent. Pin them down:
The two load-bearing phrases: where it comes from (from a search or list response) and how to handle it (copy verbatim, case-sensitive, do not type from memory). Both belong in the description, not a separate doc.
Descriptions encode workflow, not type
| Weak | Strong | |
|---|---|---|
id: The document id | id: Exact document id (e.g. doc_9f3a21), copied verbatim from a list/search response — case-sensitive | |
status: The status string | status: One of OPEN, MERGED, CLOSED (see per-value meanings); filters the result set | |
cursor: Pagination cursor | cursor: next_cursor from the previous page response; omit on first request | |
since: A timestamp | since: RFC 3339 UTC timestamp; returns records created strictly after it |
JSON-RPC 2.0 (MCP Pattern)
Request
Success Response
Error Response
Pagination
Offset-based
Cursor-based (Recommended for Large Datasets)
Rate Limiting
Headers
Implementation
Authentication
API Key (Simple)
JWT (Production)
Versioning
URL Path (Recommended)
Header
Common Rationalizations
| Excuse | Why It's Wrong | |
|---|---|---|
| "We'll version the API later" | Unversioned APIs break clients on every change — version from day one | |
| "Retries are the client's problem" | Server-side idempotency prevents data corruption — design for at-least-once delivery | |
| "We'll add rate limiting later" | Unprotected endpoints get abused within hours of deployment | |
| "Error messages are just for debugging" | Error responses are your API's UX — clients depend on consistent, parseable errors | |
| "PATCH and PUT are the same thing" | PUT replaces the resource, PATCH modifies it — wrong semantics cause data loss |
Hard Rules
- MUST version the API from day one (URL path or Accept header) — unversioned APIs break clients on every change
- MUST validate input type, format and size at the API boundary; enforce state-dependent domain invariants in business logic as well
- MUST use PUT for full replacement and PATCH for partial update — confusing the two causes silent data loss
- NEVER return unbounded list responses — pagination (offset or cursor) is mandatory
- NEVER expose private implementation details in ordinary API errors, including 4xx and background-job error fields; preserve the host's public error representation
- CRITICAL: idempotency on POST/PUT/PATCH is non-negotiable when retries are possible — accept an
Idempotency-Keyheader or design the endpoint to be naturally idempotent - CRITICAL: rate limits exist from the first deploy, not "later" — unprotected endpoints get abused within hours
Best Practices
- [ ] Use HTTPS only
- [ ] Version your API
- [ ] Validate all inputs
- [ ] Use proper HTTP methods and status codes
- [ ] Implement rate limiting
- [ ] Include pagination for lists
- [ ] Return consistent error format
- [ ] Document with OpenAPI/Swagger
- [ ] Log requests for debugging
- [ ] Set reasonable timeouts
Gotchas
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingapp/skills/api-patterns/SKILL.md
Popularity
- Repository stars
- 162
- Repository forks
- 21
- 7-day trend score
- 25
Stars and forks are for the whole GitHub repository, not this skill alone. 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/softspark/ai-toolkit/api-patterns)