# LLM Margin Lab

> Source: <https://github.com/telemetry-sh/llm-margin-lab>
> Published: 2026-07-21 14:29:22+00:00

An interactive calculator for the unit economics of AI features.

Most AI products can quote token prices. Fewer can answer the question that
matters: **how much usage can each customer consume before the business model
breaks?**

LLM Margin Lab combines pricing, tokens, retries, prompt caching, model routing, infrastructure, support, and target gross margin in one shareable scenario. It runs locally and does not require an API key.

- Revenue and contribution profit per active user
- Input and output token costs
- Retry amplification
- Prompt cache hit rate and cache discounts
- Routing a percentage of work to a cheaper model
- Infrastructure and support costs
- Maximum requests per user at a target margin
- Margin sensitivity as usage grows

The included presets are illustrative. Replace them with current model prices and the operating costs of your own stack.

Requires Node.js 20.9 or newer.

```
npm install
npm run dev
```

Open [http://localhost:3000](http://localhost:3000).

Use **Copy scenario** to put every assumption in the URL. The recipient can
edit the scenario without an account or backend. No prompt text, customer
data, or proprietary model configuration is included unless you type it into
a numeric field, which the app does not provide.

The calculator works without analytics. If you set `TELEMETRY_API_KEY`

, copied
scenario links emit one aggregate event through the server route using
[Telemetry](https://telemetry.sh/?utm_source=github&utm_medium=referral&utm_campaign=llm-margin-lab&utm_content=readme).
The event contains only the selected preset plus broad margin and spend bands;
it does not contain prices, token counts, URLs, IP addresses, or scenario
values.

```
cp .env.example .env.local
# Add your Telemetry API key, then restart the dev server.
npm run typecheck
npm test
npm run build
```

MIT
