How to Write API Documentation with AI (Step by Step)
Learn how to write API documentation step by step, with AI drafting from your code or OpenAPI file, plus a copyable prompt, template and review checklist.
For Product Management and Managers

How do you write API documentation?
You write API documentation by starting from what the API actually does, then describing each endpoint (a URL that does one job) the same way: what it is for, what you send, what you get back, what can go wrong, and one working example. Add a short getting-started guide for authentication and a first successful call. AI can draft most of this from your code or an OpenAPI file. A person who knows the product still has to check it.
TL;DR
- Document from the code, not from memory. Give AI the real source, route definitions or an OpenAPI file, and it will draft accurate first versions faster than any person can type them.
- Use the same structure for every endpoint. A fixed template makes docs scannable, and it makes AI output consistent and easy to review.
- Write a "first call in five minutes" guide before the reference. Most readers want to make one successful request, and the reference alone does not get them there.
- AI is good at structure and bad at intent. It can read what the code does, but it cannot know why, what is deprecated, or what you promised customers.
- Run every example. An example that looks right and returns an error is worse than no example.
- Give the docs an owner and a trigger. Docs go stale when nobody is responsible for updating them when the API changes.
What should API documentation include?
Good API docs have five parts. Reference pages are only one of them.
| Part | What it answers | Who needs it |
|---|---|---|
| Overview | What can I do with this API, and is it for me? | Product, managers, evaluators |
| Getting started | How do I authenticate and make my first call? | New developers |
| Reference | What does each endpoint accept and return? | Developers, daily |
| Guides | How do I accomplish a real task across several endpoints? | Developers, integrators |
| Changelog and errors | What changed, and what does this error mean? | Everyone who already uses it |
If you only have time for two, write getting started and the reference. If you can add a third, write the error list. Most support tickets about APIs are about authentication and errors.
How do you write API documentation with AI, step by step?
1. Decide who the reader is and what they want to do
Write one sentence: "A developer at a customer company wants to [do X] using our API." For example: "wants to create an invoice and check whether it was paid." That sentence decides what goes in getting started and which guides you write.
If you are a product manager or team lead and not an engineer, this step is yours. Engineers know how the API works. You know what readers are trying to get done.
2. Collect the source of truth
AI drafts well when it can read the real thing. Gather, in order of preference:
- An OpenAPI file (also called a Swagger file). This is a structured description of every endpoint, in YAML or JSON. If your team has one, it is the best input.
- The route and handler code for the endpoints you are documenting, plus the data models or schemas they use.
- Real example requests and responses from a test environment.
- Existing material: tickets, a design doc, Slack explanations, an old wiki page.
Ask an engineer for the first item. If one does not exist, the second works. Remove secrets first. Never paste real API keys, customer data or internal passwords into an AI tool. Check your company's policy on which AI tools are approved for source code.
3. Fix the template before you write anything
Use one structure for every endpoint. Copy this one.
## [Method] [Path]
Example: ## POST /invoices
**What it does**
One or two sentences in plain language. Start with a verb.
**Authentication**
What credential is needed and which permission or role.
**Request**
- Path parameters: name, type, required or optional, description
- Query parameters: name, type, required or optional, default, description
- Headers: any beyond the standard authentication header
- Body: field name, type, required or optional, allowed values, description
**Example request**
A complete, copyable request (curl or the language your readers use).
**Response**
- Success status code and what it means
- Field list: name, type, description
- Example response body
**Errors**
Table: status code, error code or message, what caused it, how to fix it
**Notes**
Rate limits, pagination, idempotency, side effects, deprecation, related endpoints
Teams skip the Errors and Notes sections, and those are the ones readers need when something breaks.
4. Ask AI for a draft of one endpoint first
Start with one endpoint, not the whole API. You will learn what the AI gets wrong and can correct the prompt before you multiply the mistakes across fifty pages.
Paste this prompt, then paste your code or OpenAPI snippet below it:
You are a technical writer documenting a REST API for developers who have
never seen it before.
Below is the source for one endpoint (code or OpenAPI). Write the reference
page using exactly the template I give you. Rules:
1. Use only what is in the source. If something is not in the source (for
example a rate limit, a permission name, or the meaning of a field), write
"UNKNOWN: ask the owning engineer" in that spot. Do not guess.
2. Describe every parameter and field, including type and whether it is
required.
3. List every error the code can return, with the status code and the
condition that causes it.
4. Write one complete example request and one example response. Use obviously
fake values (for example inv_12345, test@example.com). Never use anything
that looks like a real key or real customer data.
5. Plain language. Start the "What it does" sentence with a verb. No marketing
words.
6. After the page, give me a list titled "Questions for the engineer" with
anything ambiguous or inconsistent you noticed in the source.
TEMPLATE:
[paste the template from above]
SOURCE:
[paste code or OpenAPI for one endpoint, plus the schemas it uses]
The "UNKNOWN" instruction matters. Without it, AI fills gaps with plausible-sounding guesses. The "Questions for the engineer" list turns the AI into a reviewer that tells you where the code and the intent might disagree.
5. Read the draft against the source
Do this check yourself, line by line, for the first few endpoints:
- Does every parameter in the docs exist in the code, with the right name and capitalization?
- Are required and optional correctly marked? AI often marks everything required or nothing required.
- Are the status codes real? Compare against the code paths that return errors.
- Is the default value in the docs the default in the code?
- Does the description say what the endpoint does, or only repeat the field name? "The invoice ID: the ID of the invoice" is filler. Ask for the real meaning.
- Are there any invented features, such as filters, sorting options or webhooks that are not in the source?
6. Run every example
Copy each example request into a terminal, Postman or a similar tool against a test environment. Does it work? Does the response match the example? If you are not technical, ask an engineer to run them with you for ten minutes. This catches more errors than any other step.
Examples are what developers copy first. A broken example costs trust before they read anything else.
7. Write the getting-started guide
This is where human judgment matters most. It should take a new reader from nothing to one successful call. A good structure:
- What you need (an account, a test key, a tool for sending requests)
- How to get credentials, and where to put them
- The simplest useful request, with the full example
- What a successful response looks like
- The three most common errors at this stage, and what they mean
- Where to go next
Use this prompt to draft it:
Using the endpoint pages below, write a getting-started guide for a developer
who wants to [your one-sentence goal from step 1]. They should be able to
complete it in about ten minutes. Use numbered steps. Each step needs one
action and the expected result. Include the exact example request for each
step, and the first thing to check if it fails. Do not mention any feature
that is not in the pages below.
PAGES:
[paste the reviewed endpoint pages]
Then follow your own guide from a blank state, as if you were a new customer. Every place you get stuck is a gap in the doc.
8. Add the error list and a changelog
Ask AI to collect every error from the reviewed endpoint pages into one table: status code, error message, cause, fix. Review it for duplicates and conflicts. Then start a changelog with dates and a plain description of each change, marked as new, changed, deprecated or removed. A changelog is easiest to keep up to date when it starts on day one.
9. Get two reviews
Ask an engineer to check accuracy. Ask someone who has never used the API to do the getting-started guide cold. The first finds wrong facts. The second finds missing steps. You need both.
What does a filled-in example look like?
Say the source is a small handler for retrieving an invoice. The code tells the AI the path is /invoices/{id}, the method is GET, an unknown id returns a 404, and a caller without the right role gets a 403. The draft might read:
## GET /invoices/{id}
**What it does**
Returns one invoice, including its line items and payment status.
**Authentication**
Requires an API key with the "invoices:read" permission.
UNKNOWN: confirm the permission name with the owning engineer.
**Request**
- Path parameter: id (string, required). The invoice ID, for example inv_12345.
**Example request**
curl https://api.example.com/invoices/inv_12345 \
-H "Authorization: Bearer YOUR_API_KEY"
**Response**
200 OK. Returns the invoice.
- id (string): unique invoice ID
- status (string): draft, sent, paid or void
- total (number): invoice total in the smallest currency unit
- line_items (array): items on the invoice
**Errors**
| Status | Cause | Fix |
|---|---|---|
| 401 | Missing or invalid API key | Check the Authorization header |
| 403 | Key lacks permission | Use a key with read access to invoices |
| 404 | No invoice with that ID | Check the ID |
Notice the draft flagged the permission name instead of inventing one. The "total in the smallest currency unit" line is the kind of detail to verify. If the code stores cents and the AI says dollars, a customer will overcharge someone. That is why you run the examples and check the fields.
Where should you not trust AI with API documentation?
AI reads code well. It does not know your business. Do not rely on it for:
- Intent and behavior it cannot see. Rate limits set in a gateway, permissions enforced elsewhere, and behavior that depends on configuration do not appear in the handler code.
- Deprecation and promises. Whether an endpoint is going away, or is stable enough to recommend, is a product decision.
- Security guidance. Have a security reviewer read the authentication and permissions sections.
- Real data. Never let it produce examples from real customer records, and never paste secrets into a prompt.
- Consistency over time. A model has no memory of what you documented last month. Re-feed the template and the style rules each time.
- Anything you did not verify. Treat the draft as written by a fast, confident new hire who has never spoken to the team.
Who should own API documentation: engineers, writers or product?
All three contribute, and one person should own the result.
- Engineers know what is true. They review for accuracy and answer the "UNKNOWN" items.
- Technical writers shape structure, clarity and consistency, and maintain the template and style guide.
- Product managers and team leads decide who the reader is, what the guides cover, what is deprecated, and when docs must be ready. A launch should not be "done" until its docs are published.
If you manage people, the most useful thing you can do is add documentation to the definition of done: no endpoint ships without a reference page, and no breaking change ships without a changelog entry.
How do you keep API documentation from going stale?
Most docs fail because they were written once and never touched again. Three habits help:
- Generate from the source where possible. If your reference pages come from an OpenAPI file, a change to the file updates the docs. Tools such as Swagger UI and Redoc render an OpenAPI file into a browsable reference. Have AI draft the human parts (descriptions, guides) and let the file drive the rest.
- Tie docs to pull requests. Ask engineers to update the relevant page in the same change as the code. A reviewer can ask for it. You can also have AI compare a code change against the existing page and list what is now out of date:
Here is the existing documentation page and a code diff for the same
endpoint. List every statement in the page that is now wrong or incomplete,
and propose the corrected text. If the diff does not tell you enough, say so.
- Review on a schedule. Once a quarter, have someone do the getting-started guide from scratch. It takes under an hour and finds drift fast.
Could you build a docs tracker instead of using a spreadsheet?
Many teams track documentation in a spreadsheet: which endpoints are documented, who reviewed them, which are stale. It works until nobody updates it. With Remy, you can describe that tracker in plain English (endpoints, owner, reviewer, status, last verified date, a "needs update" flag, and a simple request form for support to report a wrong page) and get a deployed app with a database and sign-in, which your team owns as standard code in a git repo. It is a small internal tool, not a documentation generator, and you would still write and review the docs themselves.
Frequently Asked Questions
What is the best format for API documentation?
Most REST APIs use an OpenAPI file as the machine-readable source and a rendered reference site on top of it, plus hand-written guides. The format matters less than consistency: every endpoint should follow the same template, with a runnable example and a list of errors.
Can AI write API documentation by itself?
AI can produce a solid first draft when it has your code or OpenAPI file, and it is fast at repetitive structure. It cannot confirm that its statements are true, and it does not know your rate limits, deprecations or business rules. Treat the output as a draft that an engineer reviews and that you test by running the examples.
How long does it take to document an API?
It depends on the number of endpoints and how clean the source is. A reasonable approach is to document one endpoint end to end first, including review and running the example, and then time it. Multiply by the number of endpoints, then add time for getting started and the error list. AI shortens the drafting, not the review.
Do I need to be a developer to write API documentation?
No, but you need access to a developer for review and for the questions the AI cannot answer. Product managers and team leads often do the most valuable parts: defining the reader, writing the use-case guides and checking that the getting-started steps work for a newcomer.
What is the most common mistake in API documentation?
Skipping working examples and error explanations. Readers copy the example first and look up the error when something fails. If both are missing or wrong, they open a support ticket instead.
Useful for
How we source, write, and correct our articles. Editorial standards
Related articles

Should You Rewrite Your Codebase With AI? Octar's Lessons

What to Do When AI Gives a Surprising Answer (Not Retry)

RICE Prioritization Framework: Template and AI Scoring Prompt
