Coding
AI Prompt for API Documentation
Generate complete API docs with this AI prompt: endpoint references, request/response examples and error tables from your code — ready to publish.
The prompt
Role: You are a technical writer who creates API documentation developers love — clear, complete, and example-rich. Context: Language/framework: [LANGUAGE]. Audience: [AUDIENCE: external developers / internal team]. Output format: [FORMAT: Markdown / HTML / OpenAPI]. API code or spec: [CODE_OR_SPEC] Task: 1) Document every endpoint: method + path, description of what it does, parameters (path/query/body) with types, required/optional, and defaults. 2) Provide a request AND response example for each endpoint using realistic data. 3) Document all error responses with status codes and example bodies. 4) Add authentication/authorization notes. 5) Include a "quick start" section: the 3 calls a new developer makes first, in order. Format: One section per endpoint with consistent subsections, then errors, then auth, then quick start. Ask the AI to generate a breaking-change checklist alongside the docs: renamed fields, removed endpoints, and altered defaults. Docs that silently drift from the API are worse than no docs. Constraints: Every parameter documented — no undocumented fields. Examples must be realistic and internally consistent (IDs match across examples). Mark anything you inferred from code rather than explicit spec.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [AUDIENCE] [FORMAT] [CODE_OR_SPEC]
Example input
LANGUAGE=Python (FastAPI), CODE=3 endpoints: GET /products, POST /orders, GET /orders/{id}, AUDIENCE=external developers, FORMAT=Markdown with request/response examples
How to use this prompt
Paste the actual handler code or route definitions — docs generated from code stay truthful. Name the audience; internal and external docs need different depth.
Tips for the best results
- Ask it to verify every example field exists in the code — hallucinated fields are the #1 docs bug.
- Generate docs from code, then diff against the previous version to spot breaking changes.
- Have it write the quick-start as a runnable script developers can copy-paste.
Frequently asked questions
Will the examples be accurate?
It generates the docs skeleton plus examples; you verify the examples against the real API before publishing.
How often should I regenerate API docs?
Every release, generated from code. Diff the new output against the old to catch undocumented breaking changes before your users do.