Skip to content

Repository files navigation

LLM Token Cost Simulator

Live demo →  ·  GitHub

The spreadsheet you should build before committing to an LLM architecture — made interactive.

Every provider charges 4–8× more for output tokens than input. Most teams don't know this until the bill arrives. This simulator lets you model the token economics of your specific workload before you build it.


What it does

Set four moving parts and watch cost update live:

Control What it models
Total tokens Your workload volume (default 1M)
I/O ratio How many input tokens per output token your architecture generates
Provider / Model List pricing — all prices editable, "reset to source" available
Prompt caching Toggle on to model savings from prefix caching; set what % of your input is prefix-stable

Archetype chips (Extraction · Summarizer · RAG · Code gen · Agent) snap the slider to the matching workflow profile and show you what a given ratio means architecturally.


Cost model

inputTokens  = N × ratio / (ratio + 1)
outputTokens = N / (ratio + 1)

Cost (no caching):
  = inputTokens × inputPrice / 1M
  + outputTokens × outputPrice / 1M

Cost (with caching):
  = cacheableIn × cacheHitPrice / 1M
  + fullIn × inputPrice / 1M
  + outputTokens × outputPrice / 1M

The model is unit-tested against published figures from the tokenomics series — see src/lib/costModel.test.ts. For example:

  • AI agent on Claude Sonnet 4.6 (46,800 in / 4,000 out): $0.2004/task$0.10563/task with 75% caching (−47%)
  • Code generator (800 in / 1,200 out): $0.0204/task → caching saves only ~4%

Run the tests: npm test


Pricing sources (May 2026)

Model Input /1M Output /1M Cache read /1M Source
Claude Sonnet 4.6 $3.00 $15.00 $0.30 Anthropic
Claude Haiku 4.5 $1.00 $5.00 $0.10 Anthropic
Claude Opus 4.6 $5.00 $25.00 $0.50 Anthropic
GPT-4o $2.50 $10.00 $1.25 OpenAI · caching
GPT-5.2 $1.75 $14.00 OpenAI
Gemini 3.1 Pro $2.00 $12.00 Google
Grok 4.1 $0.20 $0.50 xAI

Prices are list prices as of the date above. Use the source links to confirm current pricing. All prices are editable in-UI.


Caveats

  • Simplified cache model: cache read only — the one-time write-premium is omitted. Real cost is slightly higher on first-request caching. See Anthropic docs for the write-premium.
  • Archetype token profiles are author estimates based on representative tasks, not instrumented measurements.
  • List prices only — volume discounts and committed-use pricing not modelled.
  • Caching disabled for models where cache-read pricing is unconfirmed (GPT-5.2, Gemini 3.1 Pro, Grok 4.1). Override in-UI if you have confirmed pricing.

Part of the LLM tokenomics series

This tool operationalizes three LinkedIn posts:

  1. Token economics: why architecture beats provider choice (95× cost gap)
  2. The output premium: why every provider charges 4–8× more for output tokens
  3. Prompt caching cuts agent costs 47% — but only 4% for code generation

Develop locally

npm install
npm run dev          # dev server at http://localhost:5173/llm-token-cost-simulator/
npm test             # Vitest — 8 regression tests against published post figures
npm run build        # production build → dist/
npm run preview      # preview the production build locally

If you rename the repo, update base in vite.config.ts to match the new GitHub Pages path (/<repo-name>/).


Deploy to GitHub Pages

  1. Push to a public GitHub repo
  2. Go to Settings → Pages → Source and select GitHub Actions
  3. The workflow in .github/workflows/deploy.yml runs on every push to main

MIT License

About

Interactive calculator for LLM token costs — model I/O ratio, prompt caching, and provider pricing before you commit to an architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages