$npx -y skills add DevelopersGlobal/ai-agent-skills --skill api-designDesign stable, versioned, self-documenting APIs. Easy to use correctly, hard to use incorrectly. Apply Hyrum's Law from day one.
| 1 | ## Overview |
| 2 | |
| 3 | APIs are contracts. Once published, every behavior — documented or not — becomes something users depend on (Hyrum's Law). This skill enforces the discipline of designing APIs that are stable, self-documenting, and difficult to misuse. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Creating any public API endpoint |
| 8 | - Designing function/library APIs |
| 9 | - Extending or versioning existing APIs |
| 10 | |
| 11 | ## Process |
| 12 | |
| 13 | ### Step 1: Design the Interface First |
| 14 | |
| 15 | 1. Write the usage examples before writing the implementation. |
| 16 | 2. Ask: Is this easy to use correctly? Is it hard to use incorrectly? |
| 17 | 3. Apply the principle of least surprise — the API should do what it looks like it does. |
| 18 | 4. Design for the caller, not the implementer. |
| 19 | |
| 20 | **Verify:** You can write 3 example usages without looking at the implementation. |
| 21 | |
| 22 | ### Step 2: Apply Hyrum's Law |
| 23 | |
| 24 | 5. Every observable behavior of your API will be depended upon by someone. |
| 25 | 6. Document what IS and IS NOT guaranteed: |
| 26 | - Stable: return type, error codes, semantic behavior |
| 27 | - Unstable: response time, field ordering, internal implementation |
| 28 | 7. Be conservative in what you expose — you can always add, never remove. |
| 29 | |
| 30 | **Verify:** Every public field and behavior is either documented as stable or marked as internal. |
| 31 | |
| 32 | ### Step 3: Versioning Strategy |
| 33 | |
| 34 | 8. Version from day one: `/api/v1/`, `Content-Type: application/vnd.myapi.v1+json` |
| 35 | 9. Breaking changes require a new version. |
| 36 | 10. Maintain old versions for at least 6 months with deprecation notices. |
| 37 | 11. Additive changes (new optional fields) are non-breaking. |
| 38 | |
| 39 | **Verify:** API version is in the URL or headers. Deprecation policy is documented. |
| 40 | |
| 41 | ### Step 4: Self-Documentation |
| 42 | |
| 43 | 12. Every endpoint: purpose, inputs, outputs, error codes — documented. |
| 44 | 13. Error messages tell the caller what went wrong AND how to fix it. |
| 45 | 14. Schema validation on all inputs with meaningful error messages. |
| 46 | 15. OpenAPI/Swagger spec generated (not hand-written). |
| 47 | |
| 48 | **Verify:** A new developer can use the API from documentation alone, without reading source code. |
| 49 | |
| 50 | ## Common Rationalizations (and Rebuttals) |
| 51 | |
| 52 | | Excuse | Rebuttal | |
| 53 | |--------|----------| |
| 54 | | "We'll document it later" | Undocumented APIs become black boxes. Document as you build. | |
| 55 | | "We can break it, it's internal" | Internal APIs become external. Design them well from the start. | |
| 56 | | "Versioning is premature" | Retrofitting versioning into an unversioned API is painful. Start versioned. | |
| 57 | |
| 58 | ## Verification |
| 59 | |
| 60 | - [ ] Interface designed before implementation |
| 61 | - [ ] Stable vs. unstable behaviors documented |
| 62 | - [ ] Versioning strategy in place |
| 63 | - [ ] All endpoints documented (OpenAPI/Swagger) |
| 64 | - [ ] Error messages actionable |
| 65 | - [ ] Breaking vs. non-breaking changes policy defined |
| 66 | |
| 67 | ## References |
| 68 | |
| 69 | - [security-hardening skill](../security-hardening/SKILL.md) |
| 70 | - Hyrum's Law: https://www.hyrumslaw.com/ |