{"slug": "tokensaver-see-which-parts-of-your-llm-prompt-cost-money", "title": "Tokensaver, see which parts of your LLM prompt cost money", "summary": "A new open-source tool called tokensaver reports that it cut a sample customer-support system prompt from 834 to 665 tokens on gpt-4o, a 20.3% reduction worth $0.4225 per 1,000 calls and $422.50 per 1 million calls. tokensaver runs fully offline, counts tokens and compares costs across major AI models, and attaches a reason, token savings and dollar value to each suggestion; its default safe rules alone drop the same prompt from 834 to 772 tokens, with review suggestions worth 107 more tokens. The tool's token counting, cost comparison, JSON minification, whitespace cleanup and duplicate detection are tested in CI on 55 languages, though its filler-phrase rule currently covers only English.", "body_md": "**Find out what your prompt costs on every major AI model, and exactly which changes make it cheaper.**\n\nMost token counters stop at a number. tokensaver tells you **what to change**: every\nsuggestion comes with a reason, the tokens it saves, and what that is worth in dollars.\nIt runs 100% offline. Your prompt never leaves your machine.\n\n**tokensaver works with prompts in any language and any script.** Token counting, cost\ncomparison, JSON minification, whitespace cleanup and duplicate detection are\n**tested in CI on 55 languages** on every commit\n([see the test](https://github.com/behrouzbk/tokensaver/blob/main/tests/test_languages.py)):\n\nArabic · Bengali · Bulgarian · Burmese (Myanmar) · Chinese (Simplified) · Chinese (Traditional, Hong Kong) · Chinese (Traditional, Macau) · Chinese (Traditional, Taiwan) · Croatian · Czech · Danish · Dutch · English · Estonian · Finnish · French · German · Greek · Hebrew · Hindi · Hungarian · Indonesian · Italian · Japanese · Kannada · Khmer · Korean · Lithuanian · Malay · Malayalam · Marathi · Nepali · Nigerian Pidgin · Norwegian · Persian (Farsi) · Polish · Portuguese (Brazil) · Portuguese (Portugal) · Punjabi (Gurmukhi) · Romanian · Russian · Serbian (Cyrillic) · Slovak · Slovenian · Spanish · Swahili · Swedish · Tagalog (Filipino) · Tamil · Telugu · Thai · Turkish · Ukrainian · Urdu · Vietnamese\n\nRight-to-left scripts (Arabic, Hebrew, Persian, Urdu) and languages without spaces between\nwords (Chinese, Japanese, Thai, Khmer, Burmese) included. The `filler` rule still speaks\nonly English. **Native speakers: add your language's filler phrases in\n[#5](https://github.com/behrouzbk/tokensaver/issues/5).**\n\n`examples/messy_prompt.txt` is a typical customer-support system prompt: polite filler, a\nrule written twice, a paragraph pasted twice, and pretty-printed JSON.\n\n``` bash\n$ tokensaver optimize examples/messy_prompt.txt --apply all\n\n  #  Suggestion                                                    Tokens  $/1k calls  Status\n  1  Minify JSON block (140 chars, was 185)  line 13                  -18     $0.0450  applied\n  2  Minify JSON block (200 chars, was 392)  line 39                  -43     $0.1075  applied\n  3  Duplicate line: “- Never share internal information…”  line 30   -12     $0.0300  applied\n  4  Duplicate paragraph: “Please note that you must only…”  line 34  -41     $0.1025  applied\n  5  Repeated instruction: “Make sure you keep the answer…”  line 32  -12     $0.0300  applied\n  7  Filler: “I would like you to…” (×1)  line 4                      -6     $0.0150  applied\n ...\n 15  Long example (~198 tokens)  line 60                             ≤198     $0.4950  flag\n\n╭──────────────────────── Total savings on gpt-4o ─────────────────────────╮\n│ Before: 834 tokens                                                       │\n│ After:  665 tokens                                                       │\n│ Saved:  169 tokens (20.3%) = $0.000423 per call, $0.4225 per 1,000 calls, │\n│ $422.50 per 1M calls                                                     │\n╰──────────────────────────────────────────────────────────────────────────╯\n```\n\nWhat changed in the prompt:\n\n```\n-I would like you to please read the customer's message carefully and answer their question.\n-As an AI language model, you should always be polite, friendly and professional.\n+Read the customer's message carefully and answer their question.\n+You should always be polite, friendly and professional.\n...\n-{\n-    \"answer\": \"string\",\n-    \"category\": \"billing | technical | account | other\",\n-    ...\n-}\n+{\"answer\":\"string\",\"category\":\"billing | technical | account | other\",\"confidence\":0.0,...}\n...\n-- Never share internal information, discount codes or employee names.\n-- Make sure you keep the answer under 120 words.\n```\n\nWith only the default **safe** rules (no wording changes at all), the same prompt drops from\n834 to 772 tokens. tokensaver then tells you that the review suggestions would save\n107 more, so you decide.\n\n```\npip install prompt-tokensaver\n```\n\nThe command is `tokensaver`. Requires Python 3.10 or newer. Works on Windows, macOS and\nLinux.\n\n```\n# 1. How many tokens, and what does one call cost?\ntokensaver count prompt.txt --model gpt-4o\ntokensaver count \"Summarize this article in three bullet points.\"\n\n# 2. Which model is cheapest for this prompt?\ntokensaver compare prompt.txt\ntokensaver compare prompt.txt --models gpt-4o,claude-sonnet-5-5,gemini-2.5-flash\n\n# 3. What should I change? (safe changes are applied, others are suggested)\ntokensaver optimize prompt.txt\n\n# 4. Apply everything you agree with and save a copy (the original is never overwritten)\ntokensaver optimize prompt.txt --apply all --output prompt.optimized.txt\ntokensaver optimize prompt.txt --apply json,whitespace,filler -o prompt.optimized.txt\n\n# Pipe text in with \"-\", list models and prices\ncat prompt.txt | tokensaver count -        # PowerShell: Get-Content prompt.txt | tokensaver count -\ntokensaver models\n```\n\nWindows paths work as usual: `tokensaver optimize examples\\messy_prompt.txt`.\n\nRun `tokensaver <command> --help` for the same information in your terminal.\n\n`INPUT` can be any of:\n\n| You pass | tokensaver reads | \n|---|---|\n| `prompt.txt` or`C:\\prompts\\system.md` | the file (UTF-8; a byte-order mark is ignored) | \n| `-` | text piped in on stdin | \n| `\"Summarize this in 3 bullets.\"` | the text itself | \n\nA mistyped file name like `promt.txt` is an error, not silently counted as text.\n\nToken count and input cost on one model.\n\n| Option | What it does | \n|---|---|\n| `--model` ,`-m` | Model to price against. Default: `gpt-4o` . See`tokensaver models` for all names. | \n| `--prices FILE` | Use your own `prices.json` instead of the bundled one. | \n\nTokens and input cost on many models, cheapest first.\n\n| Option | What it does | \n|---|---|\n| `--models a,b,c` | Only these models (comma-separated). Default: all of them. | \n| `--prices FILE` | Use your own `prices.json` . | \n\nSuggestions with the tokens and dollars each one saves, a before/after diff and the total.\n\n| Option | What it does | \n|---|---|\n| `--model` ,`-m` | Model to measure savings on. Default: `gpt-4o` . | \n| `--apply safe` | **Default.** Applies only the safe rules (`json` ,`whitespace` ). Review rules are listed with their savings but not applied. | \n| `--apply all` | Applies every rule. Read the suggestions first. | \n| `--apply none` | Applies nothing; just shows the suggestions. | \n| `--apply json,duplicates` | Applies only the rules you list. Names: `json` ,`whitespace` ,`duplicates` ,`repeated-instructions` ,`filler` ,`long-examples` . | \n| `--output FILE` ,`-o FILE` | Saves the optimized prompt to `FILE` . Without it, nothing is written. The input file is**never** overwritten. | \n| `--force` | Lets `--output` replace a file that already exists. It still refuses to overwrite the input file. | \n| `--no-diff` | Hides the before/after diff (it is shown by default). | \n| `--prices FILE` | Use your own `prices.json` . | \n\nCommon combinations:\n\n```\ntokensaver optimize prompt.txt                                   # look first: safe fixes only, nothing saved\ntokensaver optimize prompt.txt --apply all -o prompt.min.txt     # apply everything, save a copy\ntokensaver optimize prompt.txt --apply json,whitespace,duplicates -o prompt.min.txt\ntokensaver optimize prompt.txt -m claude-sonnet-5-5 --no-diff    # savings on Claude, short output\ntokensaver optimize prompt.txt --apply all -o prompt.min.txt --force   # re-run and replace the copy\n```\n\n`models` lists every supported model with its prices and whether counts are exact.\n`version` prints the installed version.\n\nEach rule is a small module in [`src/tokensaver/optimizer/`](https://github.com/behrouzbk/tokensaver/tree/main/src/tokensaver/optimizer).\n**Safe** rules cannot change meaning and are applied by default. **Review** rules are shown\nwith their savings and applied only when you ask (`--apply all` or `--apply <rule,...>`).\nCode blocks are never changed. Few-shot examples are never reworded.\n\n| Rule | Risk | What it does | \n|---|---|---|\n| `json` | safe | Minifies pretty-printed JSON. Only whitespace outside strings is removed; the result is re-parsed and compared, so keys, values and number formats stay exactly the same. | \n| `whitespace` | safe | Removes trailing spaces, extra blank lines and blank lines at the start and end. Indentation and spaces inside lines are kept. | \n| `duplicates` | review | Finds duplicate lines and duplicate or near-duplicate (≥90% similar) paragraphs. | \n| `repeated-instructions` | review | Finds the same instruction given twice in different words, such as \"Always respond in JSON\" and \"Remember to always respond in JSON\". | \n| `filler` | review | Removes polite filler (\"I would like you to please…\", \"As an AI language model…\", \"Thanks in advance!\") and shortens wordy phrases (\"in order to\" → \"to\"). | \n| `long-examples` | review | Flags few-shot examples over ~150 tokens and prompts with more than 3 examples. Only flags them; it never edits. | \n\nEvery saving is **measured**: tokensaver counts the prompt before and after each change on\nthe model you chose. Changes that save nothing on that model are not listed. (Safe\nwhitespace fixes that save 0 tokens are still applied for a tidy file, and reported in one\nline.)\n\nPrices are USD per 1M tokens, standard tier, as of **2026-10-26**. They live in\n[`src/tokensaver/data/prices.json`](https://github.com/behrouzbk/tokensaver/blob/main/src/tokensaver/data/prices.json) with a source URL for\neach model. Edit that file, or pass your own with `--prices my_prices.json`.\n\n| Model | Provider | Input / 1M | Output / 1M | Token count | \n|---|---|---|---|---|\n| gpt-6-astra | OpenAI | $10.00 | $50.00 | estimated | \n| gpt-6.1-sol | OpenAI | $2.00 | $10.00 | estimated | \n| gpt-6-luna | OpenAI | $0.10 | $0.50 | estimated | \n| gpt-5.5 | OpenAI | $5.00 | $30.00 | **exact** | \n| gpt-5.4-mini | OpenAI | $0.75 | $4.50 | **exact** | \n| gpt-5-mini | OpenAI | $0.25 | $2.00 | **exact** | \n| gpt-4.1 | OpenAI | $2.00 | $8.00 | **exact** | \n| gpt-4.1-mini | OpenAI | $0.40 | $1.60 | **exact** | \n| gpt-4o | OpenAI | $2.50 | $10.00 | **exact** | \n| gpt-4o-mini | OpenAI | $0.15 | $0.60 | **exact** | \n| claude-fable-5-1 | Anthropic | $10.00 | $50.00 | estimated | \n| claude-opus-5-5 | Anthropic | $4.00 | $20.00 | estimated | \n| claude-sonnet-5-5 | Anthropic | $2.00 | $10.00 | estimated | \n| claude-haiku-5-5 | Anthropic | $0.10 | $0.50 | estimated | \n| claude-haiku-4-5 | Anthropic | $1.00 | $5.00 | estimated | \n| gemini-4-argon |  | $2.00 | $10.00 | estimated | \n| gemini-3.8-flash |  | $0.75 | $3.75 | estimated | \n| gemini-3.1-pro-preview |  | $2.00 | $12.00 | estimated | \n| gemini-2.5-flash |  | $0.30 | $2.50 | estimated | \n| gemini-2.5-flash-lite |  | $0.10 | $0.40 | estimated | \n\nRun `tokensaver models` to see the list for your installed version.\n\nPlease read this before relying on the numbers.\n\n- **Exact vs estimated.** Counts are exact only for OpenAI models that`tiktoken` maps to a\ntokenizer (shown as \"exact\"). Claude, Gemini and GPT-6 have no offline tokenizer, so\ntokensaver counts with OpenAI's`o200k_base` and multiplies by a per-model factor from`prices.json` . These are always shown with`~` and labelled \"estimated\". The factors are\nrough heuristics, not measurements; real counts can differ by 10–20% or more,\nespecially for code and non-English text. For exact counts, use the provider's own\ntoken-counting API.\n- **Input cost only.**`count` ,`compare` and`optimize` price the prompt you send. Output\ntokens, cached-input discounts, batch discounts and long-context surcharges (for example\nabove 200K tokens on Gemini 3.1 Pro or 100K on Claude Haiku 5.5) are not included.\n- **Prices go stale.** Check the`last_updated` date in the output. Some listed prices are\nscheduled to change (see the`notes` field in`prices.json` ).\n- **Languages.** Token counting and the`json` ,`whitespace` and`duplicates` rules work\nin every language (tested on 55, see above). The`filler` and`repeated-instructions` rules, and \"Example 1:\" detection, currently understand English only. Estimates for\nClaude and Gemini are less reliable for non-English text.\n- **Message overhead is not counted.** Chat APIs add a few tokens per message for roles\nand formatting. tokensaver counts the text you give it.\n- **Rules are heuristics.** Review suggestions can be wrong: a repeated sentence can be\nintentional emphasis, and \"duplicate\" lines can be real data. That is why they are never\napplied unless you ask.\n- **Offline by design.** tokensaver makes no network calls. The tokenizer files ship\ninside the package and are checked against their published SHA-256 hashes.\n\n- Calibrate the Claude and Gemini estimate factors against official token counters\n-  `--json` output for CI pipelines and scripts\n- Output-token and prompt-caching cost estimates\n- Directory mode: scan all prompts in a project\n- More rules: verbose markdown, long URLs, unused template variables\n- GitHub Action that comments token savings on pull requests\n\nIdeas and votes are welcome in the issues.\n\n⭐ **If tokensaver saved you tokens, a star helps other developers find it.**\n\nContributions are very welcome: new rules, better heuristics, price updates and bug\nreports. Read [CONTRIBUTING.md](https://github.com/behrouzbk/tokensaver/blob/main/CONTRIBUTING.md) for the 5-minute setup. Each rule is one\nsmall file with its own tests, so it is a good first contribution.\n\ntokensaver catches the easy wins. If your AI bill is growing and you want a deeper review of prompts, model choice, caching and architecture, I can help.\n\n👉 **[Get in touch](https://axieo.ca)** or email [info@axieo.ca](mailto:info@axieo.ca)\n\n☕ tokensaver is free and MIT licensed. If it saves you money, you can\n[buy me a coffee](https://buymeacoffee.com/jiq8aoqxeo).", "url": "https://wpnews.pro/news/tokensaver-see-which-parts-of-your-llm-prompt-cost-money", "canonical_source": "https://github.com/behrouzbk/tokensaver", "published_at": "2026-10-26 16:36:20+00:00", "updated_at": "2026-10-26 16:41:22.700056+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "developer-tools", "ai-infrastructure"], "entities": ["tokensaver", "gpt-4o", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/tokensaver-see-which-parts-of-your-llm-prompt-cost-money", "markdown": "https://wpnews.pro/news/tokensaver-see-which-parts-of-your-llm-prompt-cost-money.md", "text": "https://wpnews.pro/news/tokensaver-see-which-parts-of-your-llm-prompt-cost-money.txt", "jsonld": "https://wpnews.pro/news/tokensaver-see-which-parts-of-your-llm-prompt-cost-money.jsonld"}}