{"version":"v1","id":"llm-token-cost-calculator","matrix":"workflows","status":"live","updated":"2026-11-22","title":{"en":"LLM Token Counter & API Cost Calculator","zh":"LLM Token 计数器与 API 成本计算器"},"h1":{"en":"LLM Token Counter & API Cost Calculator with Prompt Caching","zh":"LLM Token 计数器与 API 成本计算器：支持提示词缓存"},"description":{"en":"Count prompt tokens locally, check context limits, and compare cache-aware monthly API bills across OpenAI, Claude, Gemini, DeepSeek and Llama.","zh":"本地精确统计提示词 token、检查上下文上限，并对比 OpenAI、Claude、Gemini、DeepSeek 与 Llama 的缓存感知月度 API 账单。"},"answer":{"en":"Sogoh’s calculator counts prompt tokens locally with OpenAI’s o200k_base tokenizer (exact for text using that GPT encoding, including the GPT-4o/GPT-5 family) and prices 14 models across OpenAI, Anthropic, Google, DeepSeek and Meta with provider-specific cache rules. At 10,000 input + 500 output tokens, 1,000 requests/day, 90% cacheable at a 90% hit rate, GPT-6.1 Terra falls from $375 to $150.90 a month — 59.8% saved; Claude Sonnet 5.5 falls from $750 to $301.80. Claude, Gemini, DeepSeek and Llama token counts are labelled estimates because their tokenizers are not public.","zh":"Sogoh 用 OpenAI o200k_base 分词器在浏览器本地精确统计提示词 token（对使用该 GPT 编码的文本，包括 GPT-4o/GPT-5 系列，为精确值），并按各厂商缓存规则对 OpenAI、Anthropic、Google、DeepSeek 与 Meta 的 14 个模型计价。以 10,000 输入 + 500 输出、每天 1,000 次请求、90% 可缓存且命中率 90% 为例，GPT-6.1 Terra 从每月 $375 降到 $150.90，省 59.8%；Claude Sonnet 5.5 从 $750 降到 $301.80。Claude、Gemini、DeepSeek 与 Llama 的 token 数为估算值，因为官方分词器未公开。"},"keywords":{"en":["llm token counter","ai token counter","token counter online","openai token counter","gpt token counter","prompt token counter","token cost calculator","llm api cost calculator","claude token counter","gemini token counter","deepseek api pricing","prompt caching calculator","context window checker","gpt-6 token counter"],"zh":["LLM Token 计数器","AI Token 计数器","Token 计算器","在线 Token 统计","OpenAI Token 计算","GPT Token 计数","Prompt Token 计数器","Claude Token 计算","Gemini Token 计算","DeepSeek API 价格","大模型 API 成本计算","提示词缓存 费用","上下文窗口 检查","GPT-6 Token 计算"]},"formula":[{"title":{"en":"Count the prompt with the right tokenizer","zh":"先选对分词器再数 token"},"body":{"en":"OpenAI text uses o200k_base (GPT-4o/GPT-5 family and the o-series; GPT-6 rows assume the same GPT encoding) or cl100k_base for older GPT-4/GPT-3.5 models. Both run locally with gpt-tokenizer. Claude, Gemini, DeepSeek and Llama use different, non-public tokenizers, so the tool reuses the OpenAI count as a labelled proxy instead of pretending it is exact.","zh":"OpenAI 文本用 o200k_base（GPT-4o/GPT-5 系列与 o 系列；GPT-6 行假设沿用同一 GPT 编码），旧版 GPT-4/GPT-3.5 用 cl100k_base，两者都由 gpt-tokenizer 在本地运行。Claude、Gemini、DeepSeek 与 Llama 使用不同的非公开分词器，工具明确把它们标为代理估算，不假装精确。"}},{"title":{"en":"Check the window with output included","zh":"把输出一起算进上下文"},"body":{"en":"A request needs room for the input and the reserved output. The status compares prompt tokens + expected output tokens with the model window: green below 80%, amber from 80%, red above 100%. Leave extra headroom for tool results, RAG passages and the few structural tokens chat APIs add per message.","zh":"一次请求必须同时装下输入与预留输出。状态用「提示词 token + 预期输出 token」对比模型窗口：低于 80% 为绿色，80% 起为琥珀色，超过 100% 为红色。还要给工具结果、RAG 片段和聊天 API 每条消息增加的结构 token 留余量。"}},{"title":{"en":"Model a real month, not one call","zh":"按真实一个月建模，而不是一次调用"},"body":{"en":"Enter output tokens per request, requests per day, the share of input that is stable enough to cache, and the expected hit rate. Monthly totals are × 30 days. Cacheable input is usually the system prompt, RAG documents or few-shot examples; the user’s fresh message is not cacheable.","zh":"输入单次输出 token、每日请求量、可缓存的稳定输入占比与预期命中率，月度按 30 天计算。可缓存部分通常是系统提示词、RAG 文档或 Few-shot 示例；用户当次消息不可缓存。"}},{"title":{"en":"Read the cache rules, not just the discount","zh":"看缓存规则，不只看折扣"},"body":{"en":"Anthropic bills cache writes at 1.25× input and reads at 0.1× (5-minute TTL). OpenAI and DeepSeek use automatic caching with read discounts; Gemini uses implicit caching. Every miss is billed at the provider’s write price in this model, so a low hit rate can make caching more expensive. Below the provider minimum cache size, caching is ignored.","zh":"Anthropic 的缓存写入价为输入的 1.25 倍、读取价为 0.1 倍（5 分钟 TTL）；OpenAI 与 DeepSeek 使用自动缓存读取折扣；Gemini 使用隐式缓存。本模型把每次未命中都按写入价计费，所以低命中率下缓存可能更贵。可缓存 token 低于厂商最低要求时不应用缓存。"}}],"faq":[{"q":{"en":"Is the token count exact?","zh":"Token 数是精确的吗？"},"a":{"en":"Exact for OpenAI text under the selected encoding: o200k_base for the GPT-4o/GPT-5 family and o-series, cl100k_base for older GPT-4/GPT-3.5. GPT-6 rows assume OpenAI keeps the GPT/o200k encoding; if a model ships a new tokenizer, use the provider count endpoint. Claude, Gemini, DeepSeek and Llama do not publish compatible local tokenizers, so their rows are estimates based on the OpenAI count. The count covers the pasted text; chat APIs add a few structural tokens per message.","zh":"对使用所选编码的 OpenAI 文本是精确的：GPT-4o/GPT-5 系列与 o 系列用 o200k_base，旧版 GPT-4/GPT-3.5 用 cl100k_base。GPT-6 行假设 OpenAI 继续使用 GPT/o200k 编码；若新模型换了分词器，请改用厂商的计数接口。Claude、Gemini、DeepSeek 与 Llama 没有公开兼容的本地分词器，因此对应行是基于 OpenAI 计数的估算。计数只覆盖粘贴文本；聊天 API 还会为每条消息增加少量结构 token。"}},{"q":{"en":"How does prompt caching change the bill?","zh":"提示词缓存怎么改变账单？"},"a":{"en":"Cacheable input is split into hits and misses by your hit rate. Hits are billed at the cache-read price; misses at the provider’s cache-write price; the rest of the input at the normal input price. Anthropic’s 5-minute cache writes at 1.25× and reads at 0.1×; OpenAI and DeepSeek use automatic caching with read discounts; Gemini uses implicit caching. At a low hit rate, write premiums can make caching cost more, and the badge turns red instead of hiding it.","zh":"可缓存输入按命中率拆成命中与未命中：命中按缓存读取价，未命中按厂商缓存写入价，其余输入按普通输入价。Anthropic 的 5 分钟缓存写入为 1.25 倍、读取为 0.1 倍；OpenAI 与 DeepSeek 使用自动缓存读取折扣；Gemini 使用隐式缓存。命中率很低时，写入溢价会让缓存更贵，徽标会变红而不是隐藏。"}},{"q":{"en":"Why is my invoice different from this estimate?","zh":"为什么账单和估算不一样？"},"a":{"en":"This is a list-price planning model. Taxes, batch discounts, long-context surcharges, tool-call fees, retries, explicit cache storage, negotiated rates and DeepSeek peak/off-peak pricing are excluded. It also assumes a 30-day month and charges every cache miss at the write price, which is conservative for a stable prefix that is written once. Check the provider’s invoice line items before treating the number as a budget.","zh":"这是列表价的规划模型。税费、批处理折扣、长上下文加价、工具调用费、重试、显式缓存存储费、协议价与 DeepSeek 峰谷价都不包含。它固定按 30 天计算，并把每次缓存未命中都按写入价计费；对只写一次的稳定前缀来说偏保守。把数字当预算前，先核对厂商账单明细。"}},{"q":{"en":"What counts as cacheable input?","zh":"什么算可缓存输入？"},"a":{"en":"Stable text that repeats across requests: the system prompt, policy documents, RAG passages, tool schemas and few-shot examples. Do not count the user’s fresh message, timestamps, order numbers or anything that changes per request. Providers also enforce a minimum cache size (often 1,024–2,048 tokens); below it, caching is not applied.","zh":"在不同请求间稳定重复的文本：系统提示词、政策文档、RAG 片段、工具 schema 与 Few-shot 示例。不要把用户当次消息、时间戳、订单号或任何每次请求都变化的内容算进去。厂商还有最低缓存 token 数（常见为 1,024–2,048），低于它不会应用缓存。"}},{"q":{"en":"Is my prompt uploaded or logged?","zh":"提示词会被上传或记录吗？"},"a":{"en":"No. Tokenization and every calculation run in your browser. The tokenizer library is served from this site and loads on demand; no prompt text is sent to Sogoh, an LLM provider or an analytics service. Shared links contain only the model and billing settings, never the prompt.","zh":"不会。分词与全部计算都在浏览器内完成。分词库由本站按需加载；提示词不会发送给 Sogoh、任何大模型厂商或分析服务。分享链接只包含模型与账单设置，不包含提示词。"}},{"q":{"en":"Is there a Python package or VS Code extension?","zh":"有 Python 包或 VS Code 扩展吗？"},"a":{"en":"This is a browser tool, not an extension. For scripts, use OpenAI’s tiktoken in Python or gpt-tokenizer on npm; both implement the same OpenAI encodings. For editor-side counts, use an extension that wraps one of those encodings, and keep the same caveat: Claude, Gemini and other providers may tokenize differently.","zh":"这是浏览器工具，不是扩展。写脚本时，Python 用 OpenAI 的 tiktoken，npm 用 gpt-tokenizer；两者实现同一套 OpenAI 编码。编辑器内的计数可选封装这些编码的扩展，并保留同样的前提：Claude、Gemini 等厂商的分词可能不同。"}}],"sources":[{"label":"OpenRouter — Models API (pricing fields)","url":"https://openrouter.ai/api/v1/models"},{"label":"OpenAI — API pricing","url":"https://openai.com/api/pricing/"},{"label":"OpenAI — tiktoken (BPE tokenizer)","url":"https://github.com/openai/tiktoken"},{"label":"Anthropic — API pricing","url":"https://www.anthropic.com/pricing"},{"label":"Anthropic — prompt caching and cache pricing","url":"https://platform.claude.com/docs/en/build-with-claude/prompt-caching"},{"label":"Google — Gemini API pricing","url":"https://ai.google.dev/gemini-api/docs/pricing"},{"label":"Google — Gemini token counting","url":"https://ai.google.dev/gemini-api/docs/tokens"},{"label":"DeepSeek — API pricing and cache pricing","url":"https://api-docs.deepseek.com/quick_start/pricing"},{"label":"Meta — Llama models","url":"https://www.llama.com/"},{"label":"gpt-tokenizer — browser tokenizer (MIT)","url":"https://github.com/niieani/gpt-tokenizer"}],"localized":{"en":{"url":"https://www.sogoh.com/tools/llm-token-cost-calculator/"},"zh":{"url":"https://www.sogoh.com/zh/tools/llm-token-cost-calculator/"}},"license":"Free to reuse with attribution and a link to the source page."}