# Turn traffic into API docs

> Capture an API's traffic, build an endpoint catalog in Insights, export OpenAPI, import it into the API client, and generate HTML documentation.

Source: https://docs.subcloak.com/cloak-proxy/guides/turn-traffic-into-api-docs/

An undocumented API is easier to describe once you've watched it run. This guide captures an API's traffic, lets Insights group it into an endpoint catalog, exports an OpenAPI document, imports it into the API client as a collection and editable spec, and generates HTML documentation from it.

## What you need

| | |
|---|---|
| Cloak Proxy capturing the API, with HTTPS decrypted | The catalog and OpenAPI export read decrypted requests |
| A thorough session covering the endpoints you want documented | Each endpoint needs at least one captured call |

> **Caution:**
> Document only APIs you own or are authorized to. Exercise the real endpoints with safe, non-destructive calls where you can — a documentation pass still sends real requests.

## Capture the API

1. Turn on capture and decrypt the API's host (see [SSL Proxying](https://docs.subcloak.com/cloak-proxy/capture/ssl-proxying/)).

2. Exercise each endpoint at least once, with realistic parameters. Hit the same endpoint with different IDs so Cloak Proxy can tell the variable part of the path from the fixed part.

## Build the endpoint catalog

Open **Insights** (`<kbd>⌥</kbd> <kbd>⌘</kbd> <kbd>I</kbd>`) and select the **Endpoints** tab. Cloak Proxy groups the traffic into endpoint templates, so `/users/1` and `/users/2` become one `/users/{id}`.

*[Screenshot: The Insights Endpoints tab listing method, host, path template, calls, errors, p50, p95 and average size, with an Export OpenAPI button. The API catalog: endpoints with calls, error rate, latency and size.]*

1. Read the table: method, host, path template, call count, error rate, p50/p95 and average response size. IDs, UUIDs, hashes and dates in paths are collapsed into `{id}`, `{uuid}`, and so on.

2. Select an endpoint to see its status codes, query parameters, content types and callers — the raw material for documentation.

## Export OpenAPI

1. Click **Export OpenAPI…** on the Endpoints tab to export every catalogued endpoint, or export a selection of requests with **Export Request → OpenAPI (YAML)…** from the traffic list's right-click menu.

2. The export templates paths, infers request and response schemas from the captured JSON, lists query and path parameters with examples, and records the servers it saw. Save the `.yaml` file.

> **Note:**
> The export is generated from what was captured, so its completeness depends on your session. Endpoints you didn't call won't appear, and a field that was always `null` is typed from what little was seen. Treat it as a strong first draft to refine.

## Import it into the API client and refine

1. In the API Client (`<kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>O</kbd>`), click **Import**, choose **Choose Files…**, and pick the exported YAML (or paste it).

   *[Screenshot: The Import sheet listing Postman, OpenAPI/Swagger, HAR, Insomnia and cURL as supported inputs. Import the OpenAPI file as a collection and a linked spec.]*

   Importing an OpenAPI document creates a collection (requests with example bodies) and adds the document to **Specs**.

2. Open the **Specs** view to edit the document. The linter flags missing descriptions, security and schemas, so you can see what to fill in.

   *[Screenshot: The Specs view with an OpenAPI editor, a Sync Collection button, and a Problems list of lint findings. The Specs editor with live linting and Sync Collection.]*

3. Add summaries, descriptions, security and missing schemas in the editor. Click **Sync Collection** to update the linked collection from the spec (your tests, scripts, auth and examples are kept). See [Specs](https://docs.subcloak.com/cloak-proxy/api-client/run/specs/).

## Generate documentation

1. From the Specs editor, click **Preview Docs** to render the documentation in your browser.

2. To save a shareable file, open the collection and choose **Export API Documentation (HTML)…** from its **More** menu, or generate it from the command line:

   ```bash title="Terminal"
   cloakctl docs Petstore --out docs.html
   ```

   The HTML is a single self-contained file with code samples and the collection's branding.

> **Tip:**
> You can go further with the same collection: generate a client SDK (**Generate SDK** → TypeScript, Python or Swift) or an MCP server (**Generate MCP Server…**) so assistants can call the API. From the command line, `cloakctl docs`, `cloakctl sdk` and `cloakctl mcp-server` do the same, so CI can rebuild them when the collection changes. See [Generate docs, SDKs and MCP servers](https://docs.subcloak.com/cloak-proxy/api-client/run/generate-docs-sdks-and-mcp-servers/).

## Clean up

1. Turn off capture and SSL Proxying for the API if you only needed the documentation pass.

2. Commit the collection and spec to Git if you want to keep them (the workspace is a folder of JSON files). See [Workspace and Git](https://docs.subcloak.com/cloak-proxy/api-client/workspace-and-git/).

## Related

  - [Endpoints (API catalog)](https://docs.subcloak.com/cloak-proxy/insights/endpoints/): How traffic is grouped into endpoint templates.
  - [Export](https://docs.subcloak.com/cloak-proxy/sessions/export/): HAR, CSV, Postman and OpenAPI export.
  - [Specs](https://docs.subcloak.com/cloak-proxy/api-client/run/specs/): The OpenAPI editor, lint and collection sync.
  - [Generate docs, SDKs and MCP servers](https://docs.subcloak.com/cloak-proxy/api-client/run/generate-docs-sdks-and-mcp-servers/): HTML docs, client SDKs and MCP servers from a collection.
