Example result: Write API documentation from code
AI-generated example · API Docs
Updated

Write API documentation from code

This prompt writes API documentation from the routes, handlers or OpenAPI snippet you paste in.

text-api-docs-from-code — chatgpt — 44 words

Write API documentation for these endpoints:

[PASTE ROUTES, HANDLERS OR OPENAPI SNIPPET]

For each endpoint include purpose, method and path, parameters, request body, example request, example response, error codes and authentication requirements. Organise them into sections and start with a short "getting started" guide.

Generate a working curl example for each endpoint and test it before publishing.

Get a better result

What you will get

Documentation for each endpoint with purpose, method and path, parameters, body, example request and response, error codes and authentication, in sections with a short getting-started guide at the start.

Common mistake

The docs describe behaviour that the code does not have.

Fix: Paste the real handler code, not only the route names, and ask “mark anything you are inferring from names alone”.

Also watch for
  • Example responses use made-up field names. Paste an actual response or the schema, and say “use these exact field names”. Run each example request before publishing.
  • Authentication is described vaguely. State the scheme, such as a bearer token in the Authorization header, and ask for a table of which endpoints need it.
Try a variation: add a changelog stub

Ask for “a short changelog section with a date, a version and breaking changes noted”. Developers who rely on your API will look for it first.

Still not right? Reply with this

Rewrite the error section as a table with status code, when it happens and the body returned, using only errors found in the code I pasted.

Guides that use this prompt

More chat & writing prompts

See all 465 →