# Generate an API reference from your codebase

import { Aside, Steps, Tabs, TabItem } from '@astrojs/starlight/components';

<Aside type="note" title="Request access">
  Docs Agent is available to all plans, but we grant access on request. Contact support@ekline.io to request access.
</Aside>

This guide shows you how to generate an API reference directly from your source code. Docs Agent reads your function signatures, types, and comments, then produces reference documentation with parameters, response schemas, example requests, and error codes — no manual transcription from code to docs.

By the end, you have a review-ready API reference in a pull request.

## Before you begin

You need:

- An EkLine account with Docs Agent enabled.
- A repository [connected to EkLine](/agent/github-app-setup/) that contains the API source code you want to document.
- The path to the file or directory that defines your API — for example, `src/api/auth.ts` or `src/routes/`.

New to EkLine? [Connect GitHub to EkLine](/agent/github-app-setup/) first, then return here.

## Step 1: Open a session

<Steps>
1. Log in to your [EkLine dashboard](https://ekline.io/dashboard).
2. Click **Docs Agent** in the left navigation.
</Steps>

## Step 2: Point the agent at your API source

Reference the exact file or directory that defines your endpoints. Naming the source keeps the agent focused and improves accuracy.

<Tabs>
  <TabItem label="Single file">
    ```
    Document the endpoints in src/api/auth.ts. Include request
    parameters, response schema, example requests, and error
    codes.
    ```
  </TabItem>
  <TabItem label="Directory">
    ```
    Generate an API reference for every route in src/routes/.
    Group the endpoints by resource, and for each one include
    the HTTP method, parameters, response schema, and error
    responses.
    ```
  </TabItem>
  <TabItem label="Specific endpoints">
    ```
    Document the POST /users and GET /users/:id endpoints in
    src/api/users.ts. Include request and response examples
    with realistic values.
    ```
  </TabItem>
</Tabs>

For each endpoint, the agent extracts:

- Endpoint URLs and HTTP methods
- Request parameters with types and descriptions
- Response schema with field descriptions
- Example request and response bodies
- Error responses and status codes

## Step 3: Review the generated reference

The agent writes the reference to the editor panel as it works. Read through the output and confirm it matches your code:

- Endpoint paths and methods are correct.
- Every parameter your code accepts appears in the reference.
- Response fields match what your code returns.

## Step 4: Refine with follow-up prompts

Add detail or fix gaps by continuing the conversation. The agent keeps the context from your first prompt, so you can build on the reference incrementally.

<Tabs>
  <TabItem label="Add examples">
    ```
    Add a curl example and a JavaScript fetch example to each
    endpoint.
    ```
  </TabItem>
  <TabItem label="Document errors">
    ```
    Add an error table to each endpoint listing the status code,
    error message, and cause.
    ```
  </TabItem>
  <TabItem label="Match your style">
    ```
    Match the structure and tone of docs/api/payments.md.
    ```
  </TabItem>
</Tabs>

<Aside type="tip">
Point the agent at an existing reference page with `"Match the structure of docs/api/payments.md"` so new endpoints follow the same layout as the rest of your API docs.
</Aside>

## Step 5: Raise a pull request

<Steps>
1. Enable **View All Changes** in the toolbar to see a diff of the generated reference.
2. Make any final edits directly in the editor panel.
3. Click **Raise PR**. The agent prefills a prompt in the chat — press **Enter** to send it, or edit the prompt first to add instructions.
</Steps>

The agent opens the pull request and replies in the chat with a link to continue the review on GitHub.

## Verify the reference is accurate

Before you merge, confirm the reference reflects your code:

- **Signatures match.** Every parameter name, type, and required or optional flag matches the source.
- **Examples run.** Copy an example request and run it against your API. The response matches the documented schema.
- **Errors are complete.** Each documented status code corresponds to an error your code actually returns.
- **Nothing is missing.** Every endpoint in the referenced file or directory appears in the output.

## Troubleshooting

| Problem | Cause | Fix |
|---------|-------|-----|
| The agent misses endpoints | The prompt was too broad, or endpoints span several files | Name each file explicitly, or reference the parent directory: `"Document every route in src/routes/"` |
| Parameter descriptions are vague | Your source code lacks comments or type annotations for those parameters | Add doc comments or types in the source, then regenerate — or supply the descriptions in a follow-up prompt |
| Example values look generic | The agent had no sample data to draw from | Ask for realistic values: `"Use realistic example values based on the types in the code"` |
| The reference mixes in conceptual content | The prompt asked for explanation alongside reference | Keep the prompt reference-focused, and generate concepts separately with [Create documentation](/agent/create/) |

## Next steps

- [Update and review](/agent/update-review/) — Keep the reference in sync when your API changes.
- [Create documentation](/agent/create/) — Generate READMEs, guides, and more from the same codebase.
- [Set up automated style checks](/reviewer/quickstart/) — Catch style and terminology issues on every pull request with Docs Reviewer.