# How to Reverse Engineer an API with AI (mitmproxy, HAR to OpenAPI)

> Terms check, capture via DevTools or mitmproxy, mitmproxy2swagger to OpenAPI, AI client.

Use when someone wants to document or build a client for an undocumented web or mobile API they're entitled to use (their own account, their own app, a service whose terms allow it), by capturing traffic with browser DevTools (HAR) or mitmproxy and turning it into an OpenAPI spec and client with an AI agent. Gives the terms-of-service check, capture, mitmproxy2swagger, AI-assisted spec and client writing, and handling auth safely.

- Page: https://ss33.ai/skills/skillstore33/how-to-reverse-engineer-an-api-with-ai-32298174885
- Publisher: skillstore33
- Category: [Software Development](https://ss33.ai/skills/category/software-development-t44z8z) › [APIs & backend](https://ss33.ai/skills/category/software-development-t44z8z/apis-and-backend-t0x840)
- License: MIT

## Skill

SKILL.md: https://ss33.ai/api/v1/ss33/download/skillstore33/how-to-reverse-engineer-an-api-with-ai-32298174885

# How to Reverse Engineer an API with AI (mitmproxy, HAR to OpenAPI)

**Rule for using this skill:** First check whether there's an official API and what the service's terms say about automated access; use only the user's own account and data. Then capture, convert to OpenAPI, and have the agent write a small client. Never help with bypassing paywalls, rate limits, other users' data, or access controls.

## 0. Check before you start

- **Is there an official API?** Use it if there is.
- **Read the terms of service** for automated access, scraping and reverse engineering. If they forbid it, stop, or ask the provider for access.
- Work only with **your own account and data**, at a **human-like request rate**.
- Never share captured **tokens, cookies or personal data**, and don't commit them to git.

## 1. Capture the traffic

**Web app: browser DevTools**

1. Open DevTools > **Network**, tick **Preserve log**, and filter to **Fetch/XHR**.
2. Use the feature you want to document (log in, list items, save a setting).
3. Right-click the request list > **Save all as HAR**.

**Mobile or desktop app: mitmproxy**

1. Install mitmproxy and run `mitmweb` (a web UI) or `mitmdump -w flows` (to save to a file).
2. Point the device's Wi-Fi proxy at your computer, and install mitmproxy's certificate on the device (open `mitm.it` on the device).
3. Use the feature, then stop the capture.
4. Apps with **certificate pinning** won't send traffic through the proxy. For your own app, use a debug build without pinning; don't defeat pinning in someone else's app.

## 2. Convert to an OpenAPI spec

`mitmproxy2swagger` turns captures into an OpenAPI (Swagger) spec:

1. First pass: `mitmproxy2swagger -i flows -o api.yml -p https://api.example.com` (use the HAR file as input for browser captures).
2. Open `api.yml`: it lists the discovered paths with `ignore:` in front. Remove `ignore:` from the endpoints you want, and replace IDs in paths with parameters (`/items/{id}`).
3. Second pass with the same command fills in the methods and example requests and responses.
4. Add `--examples` to include example bodies (check them for personal data first).

## 3. Let the agent finish the spec and write the client

Give the agent the spec (with tokens and personal data removed) and ask:

- "Infer request and response schemas from the examples. Mark fields you're unsure of as optional."
- "Group endpoints by resource and name the operations."
- "Write a minimal client in Python (or TypeScript) with typed models, retries with backoff, and a configurable rate limit."
- "Read the auth token from an environment variable; never hard-code it."

Tools such as Integuru (AI-generated integration code from captures) and agent skills like reverse-api-engineer follow the same pattern.

## 4. Test gently

- Test **read-only** calls first with your own account.
- Keep the rate low, and stop on 4xx or 429 responses: don't retry in a tight loop.
- Expect undocumented APIs to **change without notice**: pin a date in your client and fail loudly when the schema changes.

## Sources

- mitmproxy2swagger: https://github.com/alufers/mitmproxy2swagger
- Integuru: https://github.com/Integuru-AI/Integuru
- Reverse engineering undocumented APIs with Claude: https://dev.to/kalil0321/reverse-engineering-undocumented-apis-with-claude-1l33
- "I pointed Claude at mitmproxy and it reverse-engineered my gym app's API": https://dev.to/dtterastar/i-pointed-claude-at-mitmproxy-and-it-reverse-engineered-my-gym-apps-api-1a4h
- skills.sh, reverse-api-engineer: https://www.skills.sh/kalil0321/reverse-api-engineer
