Skip to content

Repository files navigation

LLM Margin Lab

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.

LLM Margin Lab showing an autonomous workflow scenario

What you can model

  • 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.

Run locally

Requires Node.js 20.9 or newer.

npm install
npm run dev

Open http://localhost:3000.

Share a scenario

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.

Optional aggregate telemetry

The calculator works without analytics. If you set TELEMETRY_API_KEY, copied scenario links emit one aggregate event through the server route using Telemetry. 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.

Verify

npm run typecheck
npm test
npm run build

License

MIT

About

An interactive calculator for AI product unit economics: tokens, caching, routing, retries, and gross margin.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages