How LLM Token Counting & API Pricing Work
Large language models do not bill by characters or words — they bill by tokens. A token is a chunk of text (often 3–4 English characters, or roughly 0.6–0.75 of an English word). For Chinese, Japanese, and Korean (CJK) text, a single character frequently maps to 1–2 tokens depending on the model's vocabulary size.
When building production AI apps, agents, or batch data pipelines, two numbers determine your real bill: output tokens (typically 3× to 5× more expensive than input tokens) and prompt caching (which can cut repeated system-prompt input costs by 50%–90%).
Why Estimate Locally Before Calling an API?
- Privacy by default: Proprietary code, customer tickets, and internal prompts stay inside your browser tab.
- Budget predictability: Test 10,000 or 1,000,000 monthly requests before committing to a model tier.
- Context window safety: Check whether a long system prompt plus expected output fits comfortably inside 128K, 200K, or 1M context limits.
Note on accuracy: Browser-side counts are calibrated estimates per model family (within a few percent of official BPE tokenizers). Always verify final billing against your provider's API usage response header.
Frequently Asked Questions
How many words are 1,000 tokens?
In English prose, 1,000 tokens is roughly 750 words (about 4,000 characters). Code, JSON, and non-English languages use more tokens per word.
How much does 1 million tokens cost?
Input pricing ranges from ~$0.15 per 1M tokens (GPT-4o mini) and $0.27 (DeepSeek V3) up to $3.00 (Claude Sonnet 4.5) and $15.00 (Claude Opus 4.5). Output tokens cost 3×–5× more.
Does this tool send my prompt to a server?
No. TokenCostHub calculates token counts and API costs entirely in JavaScript inside your browser. Nothing is uploaded or logged.
How does prompt caching affect API cost?
If you reuse the same system prompt or long context across requests, cached input tokens are billed at a 50%–90% discount on Anthropic, OpenAI, Google, and DeepSeek APIs.