{
  "markdown": "# LLM Cost & Token Estimator\n\n> See how many tokens your prompt uses — and what it'll cost on **GPT-4o vs. Claude vs. Gemini** — right inside VS Code. No API key, no billing dashboard, no guessing.\n\n[![CI](https://github.com/waqarulwahab/llm-cost-estimator/actions/workflows/ci.yml/badge.svg)](https://github.com/waqarulwahab/llm-cost-estimator/actions/workflows/ci.yml)\n[![Version](https://img.shields.io/badge/version-0.3.2-blue.svg)](CHANGELOG.md)\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n\n## Why this exists\n\nWhen you're building an LLM-powered app, two questions come up constantly: _how\nmany tokens is this prompt?_ and _what will this call cost?_ Today you either\nguess, paste into a web tokenizer, or check the provider's billing console after\nthe fact — all of which pull you out of your editor.\n\nThis extension answers both questions **inline**, and it answers them for\n**several models at once**, so you can make a real price/quality trade-off\n(\"~$X on GPT-4o, ~$Y on Claude Sonnet, ~$Z on Claude Haiku\") without leaving the\nfile you're working in. It's local-first and works with zero configuration — no\nAPI key required.\n\n## Demo\n\n![LLM Cost & Token Estimator — hover a prompt to compare token count and cost across GPT-4o, Claude, and Gemini](images/demo.png)\n\n> Hover any prompt (or select text) to see its token count and cost across your\n> models, side by side — cheapest first. Same comparison powers the CodeLens, the\n> live status bar, and the Comparison Panel. _([animated version](images/demo.svg))_\n\n\n\n## Features\n\n- **🔀 Multi-model cost comparison** — token count + estimated cost across all\n  your configured models, side by side. This is the whole point.\n- **🛈 Hover tooltip** — hover over a selection or a string literal (JS/TS/Python,\n  plus Markdown/JSON/YAML/plaintext) to see the comparison inline.\n- **🔎 CodeLens on prompts** — a token-count + cost lens appears right above\n  detected prompt strings in your code. Click it for the full breakdown.\n- **📊 Live status bar** — select any text and its token count + cost appear in\n  the status bar instantly (no command needed); the tooltip shows every model.\n- **🗔 Comparison Panel** — a visual dashboard comparing the **whole catalog**\n  with a live **output-token slider** (recomputes instantly), sortable columns,\n  and a \"configured models only\" filter.\n- **⌨️ Commands** — `Estimate Selection`, `Estimate Clipboard`, `Open Comparison\n  Panel`, and `Select Models to Compare`.\n- **🗂 25+ models** — GPT-4o/4.1/o-series, Claude 4/3.7/3.5, Gemini 2.5/2.0/1.5,\n  DeepSeek, Mistral, Llama, Grok. Pick what you care about.\n- **📁 Workspace scan** — one command finds every prompt in your project and\n  reports the total estimated cost per run, with a clickable per-file breakdown.\n- **➕ Custom models** — add your own models/prices (or a negotiated rate) in\n  settings; no need to edit bundled files.\n- **⚠️ Context-window warnings** — a `⚠` appears when a prompt exceeds a model's\n  context window.\n- **📋 Copy as Markdown** — drop a ready-to-paste comparison table on your\n  clipboard.\n- **🔒 Local-first, zero config** — exact OpenAI tokenization runs entirely on\n  your machine; pricing is bundled. No network calls, no API key.\n\n### A note on accuracy\n\n- **OpenAI** models use **real** BPE tokenization (`o200k_base` for the GPT-4o\n  family, `cl100k_base` for GPT-4 / GPT-3.5) via\n  [`js-tiktoken`](https://github.com/dqbd/tiktoken).\n- **Anthropic, Google, and everyone else** (DeepSeek, Mistral, Llama, Grok, …)\n  do not publish reliable local tokenizers, so their counts are **approximated**\n  using an OpenAI encoding and are clearly marked with a `~` and a disclaimer in\n  the UI. They're great for ballpark cost comparison, not for exact billing. (An\n  optional API-based accurate mode is a candidate for a future release.)\n\n## Also available as an MCP server (use it in Claude / Cursor)\n\nThis repo also ships an **[MCP server](mcp-server/)** that exposes the same\ntokenizer + pricing engine as tools (`estimate_cost`, `count_tokens`,\n`list_models`) to Claude Desktop, Claude Code, Cursor, or any MCP client — so you\ncan ask _\"what does this prompt cost on GPT-4o vs Claude vs Gemini?\"_ right in\nyour chat. See **[mcp-server/README.md](mcp-server/README.md)** for setup. Same\nlocal-first, no-API-key core — just a different front end.\n\n## Install\n\n**From the Marketplace** (once published):\n\n1. Open the Extensions view (`Ctrl+Shift+X` / `Cmd+Shift+X`).\n2. Search for **\"LLM Cost & Token Estimator\"**.\n3. Click **Install**.\n\n**From a `.vsix`:**\n\n```bash\ncode --install-extension llm-cost-estimator-0.3.2.vsix\n```\n\n**From source (for development):** see [Contributing](#contributing).\n\n## Usage\n\n- **Hover:** hover over a string literal — or select text — in a supported file.\n  A tooltip shows the per-model token count and cost.\n- **CodeLens:** open a JS/TS/Python file with prompt strings; a `N tokens · ~$X ·\n  compare` lens sits above each one. Click it for the full breakdown.\n- **Live status bar:** select any text — the status bar instantly shows its token\n  count and cheapest cost; hover the item for the full comparison. Click it to\n  open the Comparison Panel.\n- **Comparison Panel:** Command Palette → **LLM Cost: Open Comparison Panel** (or\n  the editor toolbar icon). Drag the **output-token slider** to see costs update\n  live, sort by any column, or filter to your configured models.\n- **Commands** (Command Palette, `Ctrl+Shift+P`):\n  - **LLM Cost: Estimate Selection** — selection, or the whole file if nothing is\n    selected. Also on the editor right-click menu.\n  - **LLM Cost: Estimate Clipboard** — estimate whatever you've copied.\n  - **LLM Cost: Open Comparison Panel** — the visual dashboard.\n  - **LLM Cost: Scan Workspace for Prompts** — project-wide prompt cost report.\n  - **LLM Cost: Copy Comparison as Markdown** — table to clipboard.\n  - **LLM Cost: Select Models to Compare** — pick models from the catalog.\n  - **LLM Cost: Refresh Pricing from the Web** — pull current prices (see below).\n  - **LLM Cost: Reset Session Total** — clear the running total.\n\n> **How \"total\" is calculated:** cost = input tokens + an _assumed_ number of\n> output tokens (output pricing is usually higher than input, so it matters).\n> The assumption is configurable and always shown in the tooltip.\n>\n> ```\n> cost = (inputTokens  / 1e6) * inputPer1M\n>      + (outputTokens / 1e6) * outputPer1M\n> ```\n\n## Settings\n\nAll settings live under `llmCostEstimator.*`:\n\n| Setting | Type | Default | Description |\n| --- | --- | --- | --- |\n| `llmCostEstimator.models` | `string[]` | `[\"gpt-4o\", \"claude-sonnet\", \"claude-haiku\"]` | Models to compare. Each entry must be a key in [`pricing.json`](src/pricing/pricing.json). |\n| `llmCostEstimator.outputTokenAssumption` | `number` | `500` | Assumed output (completion) tokens used for the total-cost calculation. |\n| `llmCostEstimator.currency` | `string` | `\"USD\"` | Currency label shown next to costs. Display only — does **not** convert (pricing is in USD). |\n| `llmCostEstimator.enableHover` | `boolean` | `true` | Show the hover tooltip. |\n| `llmCostEstimator.enableCodeLens` | `boolean` | `true` | Show a CodeLens above detected prompt strings (JS/TS/Python). |\n| `llmCostEstimator.enableStatusBarSelection` | `boolean` | `true` | Show the live token count + cost of the current selection in the status bar. |\n| `llmCostEstimator.customModels` | `object` | `{}` | Add or override models without editing `pricing.json` (see [Custom models](#custom-models)). |\n| `llmCostEstimator.refreshPricingOnStartup` | `boolean` | `false` | Fetch current prices from the web on startup (cached; falls back to bundled prices offline). See [Live pricing](#live-pricing). |\n| `llmCostEstimator.pricingSourceUrl` | `string` | LiteLLM data | URL of the live pricing source (LiteLLM-compatible JSON). |\n\n**Available model keys** (out of the box) — run **LLM Cost: Select Models to\nCompare** to pick from these visually:\n\n- **OpenAI:** `gpt-4o`, `gpt-4o-mini`, `gpt-4.1`, `gpt-4.1-mini`, `gpt-4.1-nano`,\n  `o3`, `o4-mini`, `gpt-4-turbo`, `gpt-4`, `gpt-3.5-turbo`\n- **Anthropic:** `claude-opus`, `claude-sonnet`, `claude-haiku`,\n  `claude-3.7-sonnet`, `claude-3.5-sonnet`, `claude-3-opus`\n- **Google:** `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.0-flash`,\n  `gemini-1.5-pro`, `gemini-1.5-flash`\n- **Others:** `deepseek-chat`, `deepseek-reasoner`, `mistral-large`,\n  `mistral-small`, `llama-3.3-70b`, `llama-3.1-405b`, `grok-2`\n\nExample `settings.json`:\n\n```jsonc\n{\n  \"llmCostEstimator.models\": [\"gpt-4o\", \"gpt-4o-mini\", \"claude-sonnet\", \"gemini-1.5-flash\"],\n  \"llmCostEstimator.outputTokenAssumption\": 800,\n  \"llmCostEstimator.currency\": \"USD\"\n}\n```\n\n### Custom models\n\nAdd your own models — or override a built-in price with a negotiated rate —\nwithout touching the bundled files, via `llmCostEstimator.customModels`:\n\n```jsonc\n{\n  \"llmCostEstimator.customModels\": {\n    \"my-finetune\": {\n      \"label\": \"My Fine-tune\",\n      \"provider\": \"openai\", // \"openai\" = exact tokenization; anything else = estimate\n      \"inputPer1M\": 1.0,\n      \"outputPer1M\": 2.0,\n      \"contextWindow\": 128000 // optional, enables the ⚠ over-limit warning\n    },\n    \"gpt-4o\": { \"label\": \"GPT-4o (our rate)\", \"provider\": \"openai\", \"inputPer1M\": 2.0, \"outputPer1M\": 8.0 }\n  }\n}\n```\n\nThen add the key to `llmCostEstimator.models` (or pick it via **Select Models to\nCompare**). Invalid entries are reported and skipped, not silently dropped.\n\n## Live pricing\n\nThe bundled prices are representative placeholders. Run **LLM Cost: Refresh\nPricing from the Web** (or enable `llmCostEstimator.refreshPricingOnStartup`) to\npull **current** prices from a maintained source — by default\n[LiteLLM's pricing data](https://github.com/BerriAI/litellm). The result is\ncached, so it keeps working offline and falls back to bundled prices on error.\n\nEach model in [`pricing.json`](src/pricing/pricing.json) declares a `liveId` (the\nsource's key for that model); models without one keep their bundled price. Point\n`llmCostEstimator.pricingSourceUrl` at any LiteLLM-compatible JSON to use a\ndifferent source. User `customModels` always win over live prices.\n\n## Updating pricing (bundled defaults)\n\n> ⚠️ **The bundled prices are representative placeholders and change\n> frequently. Verify them against each provider's official pricing page before\n> relying on them.**\n>\n> - OpenAI — <https://openai.com/api/pricing/>\n> - Anthropic — <https://www.anthropic.com/pricing>\n> - Google — <https://ai.google.dev/pricing>\n\nPrices live in [`src/pricing/pricing.json`](src/pricing/pricing.json), keyed by\nmodel alias. Each entry looks like:\n\n```json\n\"gpt-4o\": {\n  \"label\": \"GPT-4o\",\n  \"provider\": \"openai\",\n  \"encoding\": \"o200k_base\",\n  \"inputPer1M\": 2.5,\n  \"outputPer1M\": 10.0\n}\n```\n\n- `inputPer1M` / `outputPer1M` are **USD per 1,000,000 tokens**.\n- `provider` is `openai`, `anthropic`, or `google` (determines the tokenizer and\n  whether the count is exact or an estimate).\n- `encoding` is the BPE used to count tokens — `o200k_base` or `cl100k_base`.\n  For Anthropic/Google it's only an approximation proxy.\n\nTo add a model or change a price, edit the JSON and rebuild\n(`npm run compile`). The pricing file is bundled into the extension, so changes\ntake effect after a rebuild/reinstall. Pull requests that keep prices current\nare very welcome.\n\n## Contributing\n\nContributions are welcome — bug reports, pricing updates, new providers, and\nfeatures alike. **New here?** Start with **[CONTRIBUTING.md](CONTRIBUTING.md)**,\nbrowse the **[ROADMAP](ROADMAP.md)**, or pick a\n[`good first issue`](https://github.com/waqarulwahab/llm-cost-estimator/labels/good%20first%20issue).\nBy participating you agree to our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n```bash\ngit clone https://github.com/waqarulwahab/llm-cost-estimator.git\ncd llm-cost-estimator\nnpm install\n\nnpm test           # run unit + load tests (Vitest)\nnpm run test:load  # just the load/performance suite\nnpm run e2e        # bundle + end-to-end test against a mocked VS Code\nnpm run lint       # ESLint\nnpm run typecheck  # tsc --noEmit\nnpm run compile    # bundle to dist/ with esbuild\n```\n\nThen press **F5** in VS Code to launch the **Extension Development Host** and try\nyour changes live.\n\n**Project layout:**\n\n```\nsrc/\n  tokenizer/   # Tokenizer interface + per-provider implementations\n  pricing/     # pricing.json + lookup & cost math\n  core/        # estimator, prompt detector, workspace scan, export, formatting (all pure)\n  ui/          # hover, status bar, CodeLens, QuickPick, comparison + scan webviews\n  commands/    # command handlers\n  extension.ts # activate() / deactivate()\ntest/          # Vitest unit + load tests for the core logic\nmcp-server/    # MCP server (reuses src/core, src/pricing) — use it in Claude/Cursor\n```\n\nThe `core/`, `tokenizer/`, and `pricing/` layers are intentionally free of any\n`vscode` import so they can be unit-tested directly.\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Packaging & publishing\n\nThe extension is bundled with [esbuild](https://esbuild.github.io/) and packaged\nwith [`@vscode/vsce`](https://github.com/microsoft/vscode-vsce); the MCP server is\npublished to npm. Both are automated via GitHub Actions on a version tag.\n\n```bash\nnpm run package       # production bundle -> dist/extension.js\nnpm run vsce:package  # create the .vsix\nnpm run mcp:build     # build the MCP server\nnpm run mcp:test      # build + stdio end-to-end test the MCP server\n```\n\n👉 **Full step-by-step guide — Marketplace, Open VSX, npm, GitHub Actions,\nsecrets, and how end users install each artifact — is in\n[PUBLISHING.md](PUBLISHING.md).**\n\n---\n\nBuilt with [`js-tiktoken`](https://github.com/dqbd/tiktoken). Not affiliated with\nOpenAI, Anthropic, or Google.\n",
  "bytes": 13796,
  "sha": "299a2f37945565b09d777bd45e84a74ab538517b7006b067b0b28b6034d812c2",
  "repo_slug": "waqarulwahab/llm-cost-estimator",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_waqarulwahab_llm_cost_estimato_f0c5d7a3/readme"
}