mimic: The Tool That Turns Private API Traffic Into a Python Client

It intercepts mobile and web requests, extracts durable auth state, and uses an LLM to generate code that can replay the app’s behavior, then heal itself when credentials expire.

8 min read • View on GitHub • More from littledivy

A workbench scene where tangled request traffic enters a compact compiler machine and exits as a neat Python notebook. A phone, proxy tower, and raw logs sit on one side, while a script, retry loop, and key hang together on the other. The image explains how the project turns captured traffic into a maintainable client.
mimic’s core trick is not interception. It is translation from wire protocol to reusable code.
Key Takeaways

From Packet Sniffer to Python Library

Most proxy tools stop at visibility. `mimic` is trying to cross a line: it takes private API traffic and emits something you can edit, import, and keep using. That turns interception into a kind of compiler pass, where the output is not a trace, but a client.

That is why the project feels odd in a good way. The capture step matters, but the payoff is the generated library. It is the difference between reading the wire and shipping code.

Most apps authenticate every request with the same bundle of values: a bearer token, some device ids, a session id, cookies. They're stable across calls. Capture them once from a real request you made, and you can replay them on new requests to the same API.

Divy Srivastava, Author/Maintainer · littledivy/mimic README

The Core Bet: Most Apps Have a Stable Identity

The project rests on a practical hypothesis: many apps send the same identity bundle over and over. Bearer tokens, cookies, device identifiers, and `x-` prefixed metadata often stay stable enough to replay requests successfully. `mimic` leans into that reality instead of pretending every request is unique.

A narrow gate where a bundle of header cards passes through intact while one volatile token slips away and gets replaced from a side drawer labeled live proxy. The image shows how stable identity survives while changing auth is refreshed. It explains why the generated client can reuse most session state without becoming brittle.
The generated client only works if it can separate durable identity from volatile credentials.

How the Generated Client Stays Alive

The smartest part of `mimic` lives in `session.py`. The generated client is not a thin wrapper around `requests`. It parses JSON, raises on failures by default, and when a request comes back with 401, it reaches back into the capture layer for fresh headers and retries.

The generated client is resilient because runtime recovery is built into the request path, not bolted on after the fact.

That is the crucial move. A lot of tools can replay traffic once. Fewer can keep going after credentials age out. Here, the code generator and the runtime session layer are designed to cooperate, so the output behaves more like a living client than a disposable script.

How Traffic Becomes a Prompt

`mimic` does not feed raw network noise straight into an LLM and hope for the best. The traffic pipeline normalizes input from live proxying or HAR files, extracts endpoints, trims oversized bodies, and packages the result into a prompt that asks the model to produce readable code.

# Conceptual flow from the repository
flows = load_flows(source)
endpoints = normalize(flows)
endpoints = truncate_large_bodies(endpoints, limit=4000)
prompt = build_prompt(endpoints)
client_code = run_generator(prompt)

The design choice matters. The model is not acting like an oracle. It is one stage in a deterministic pipeline. The surrounding code decides what gets preserved, what gets dropped, and how the output should be shaped.

ToolWhat it gives youWhat it does not give you
mitmproxyLive interception and inspectionA reusable Python client
Postman / InsomniaManual replay and API organizationAutomation from captured traffic
mitmproxy-mcpAI access to live traffic for agentsA standalone human-editable library
mimicCaptured traffic plus generated client codeA general-purpose proxy UI

Why SSL Pinning Is the Real Gate

Before code generation matters, interception has to work. That is why `unpin.py` exists. SSL pinning is the wall that blocks standard MITM flows in many mobile apps, so the bypass path is not a bonus feature. It is the entry fee.

mimic unpin
mimic record
mimic hosts
mimic gen <host>

The repo does not make pinning sound glamorous, because it is not. It is just the obstacle you have to clear before the interesting part can begin.

What mimic Is For, and What It Is Not

`mimic` sits in a narrow lane. It is not a replacement for mitmproxy, Charles, Postman, or Insomnia. Those tools help you inspect, replay, and document traffic. `mimic` tries to take the next step and produce a maintainable Python client for ongoing use.

ToolPrimary modeOutput
mitmproxyInspect and interceptTraffic view and scripts
Charles ProxyDebug and replayManual session analysis
Postman / InsomniaOrganize and call APIsCollections and requests
mimicCompile traffic into codeEditable Python client

That niche is the point. It fills the gap between seeing a private API and living with it in code.

The Limits of the Magic

The Ethics Are Part of the Design

`mimic` is interesting because it is useful and uncomfortable at the same time. It is built for personal automation, testing, and reverse engineering, which means it lives close to terms-of-service risk. That tension is not a side note. It is part of the product shape.

The project’s appeal is that it makes the user feel powerful without hiding the trade-offs. It gives you a path from private traffic to code, but it also asks you to think hard about what you are automating, and why.