Back to Prompt Library
Coding
APIdocumentationdeveloper docscodereference

API Documentation Generator from Code

Complete, structured API reference documentation generated directly from source code with examples and error docs.

Best For

  • Developers shipping a public SDK who need reference docs to match the actual code, not a stale hand-written version.
  • Teams onboarding new engineers who need documented function signatures and examples for internal libraries.
  • Open-source maintainers preparing a release who want consistent, standards-compliant docs across every exported function.

Prompt Template

Generate complete API reference documentation for the following [LANGUAGE] code: [CODE_BLOCK]. For each public function, method, or endpoint, produce a documentation block containing: (1) a one-sentence description of what it does, (2) Parameters table with columns: Name, Type, Required, Default, Description, (3) Return value, type and description, (4) a practical usage example with realistic sample data, (5) possible errors or exceptions thrown and when they occur. Format the output in [FORMAT, e.g., Markdown, JSDoc, OpenAPI YAML]. Follow the [DOCUMENTATION_STANDARD, e.g., Google Style Guide, Microsoft Docs style] conventions. If any function behavior is ambiguous from the code alone, note it with a [CLARIFICATION NEEDED] flag rather than guessing.

Pro Tip

Include the actual return types and any custom error classes the code throws, since undocumented exceptions are the most common gap the model will otherwise guess at or skip.

Example Output

A sample of what this prompt produces once you fill in the placeholders.

For a getUserById(id, options) function, the output produces a Markdown block with a one-line description, a parameters table listing id (string, required) and options (object, optional, default {}), a return type of Promise<User>, a usage example with a sample user object, and a note that it throws UserNotFoundError, flagged [CLARIFICATION NEEDED] on whether options.includeDeleted is documented correctly in the source.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.