tokencost is an LLM token calculator and token cost estimator for the command line. Count tokens, estimate API costs, and compare model pricing across OpenAI, Anthropic, Google, Meta, DeepSeek, and Alibaba β 20+ models from one CLI. A zero-config OpenAI cost calculator and multi-provider LLM cost estimator that runs entirely offline, with no API keys and no accounts.
- Every LLM call costs money β know exactly how much before you run. Count tokens, estimate cost, compare models, all before sending a single API request.
- One tool, 6+ providers β OpenAI, Anthropic, Google, Meta, DeepSeek, Alibaba. 20+ models with up-to-date pricing (June 2026).
- Pipe-friendly β
cat prompt.txt | tokencost count --model gpt-4ofits naturally into shell scripts and CI pipelines. - Zero config β install and run. No API keys, no accounts, no setup.
- π’ Token counting β accurate with tiktoken for OpenAI models, smart estimate for others
- π° Cost estimation β input/output pricing for 20+ models across OpenAI, Anthropic, Google, Meta, DeepSeek, Alibaba
- π Model comparison β side-by-side cost tables for any token count
- π‘ Budget suggestions β given text and budget, find the cheapest model
- π¨ Terminal UI β color-coded tables and charts
- π Pipe-friendly β works with stdin/stdout for shell pipelines
pip install tokencost# Direct text
tokencost count --text "Hello, world!" --model gpt-4o
# From file
tokencost count --file prompt.txt
# From pipe
cat prompt.txt | tokencost count --model gpt-4o# Single run
tokencost estimate --model claude-sonnet-4-6 --input-tokens 15000 --output-tokens 3000
# 1000 runs
tokencost estimate --model gpt-4o-mini --input-tokens 5000 --output-tokens 1000 --runs 1000tokencost compare --input-tokens 10000 --output-tokens 5000Output:
Model Input Output Cost Provider
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
gpt-5-nano 10,000 5,000 $0.0009 OpenAI
llama-4-scout 10,000 5,000 $0.0025 Meta
gpt-4o-mini 10,000 5,000 $0.0045 OpenAI
...
claude-opus-4-6 10,000 5,000 $0.5250 Anthropic
tokencost suggest --file my_prompt.txt --budget 0.50tokencost list
tokencost list --provider OpenAI
tokencost list --json| Provider | Models |
|---|---|
| OpenAI | GPT-5, GPT-5 Mini/Nano, GPT-4.1 series, GPT-4o series |
| Anthropic | Claude Opus 4.6, Sonnet 4.6, Haiku 4.5 |
| Gemini 2.5 Pro, Gemini 2.5 Flash | |
| Meta | Llama 4 Maverick, Llama 4 Scout |
| DeepSeek | DeepSeek V3 |
| Alibaba | Qwen3 235B |
git clone https://github.com/alvabillwu/tokencost.git
cd tokencost
pip install -e ".[dev]"
pytestAn honest comparison with related token-counting and LLM cost tools β pick what fits your workflow:
| Tool | Scope | Cost data | Offline | Notes |
|---|---|---|---|---|
| tokencost | 20+ models, 6 providers | β Bundled, CLI-first | β Yes | Count + estimate + compare in one command, no API keys |
| tiktoken | OpenAI tokenizers | β Tokenizer only | β Yes | The gold standard for exact OpenAI token counts β but OpenAI-only and has no pricing data |
| LiteLLM | 100+ models | β Extensive | β Yes | Full LLM gateway/SDK; cost lookup is one feature of a much larger library |
| AgentOps/tokencost | 400+ models | β Extensive | β Yes | Mature Python library for programmatic cost calc; broader model list, less CLI-focused |
When to use tokencost: you want a fast, zero-config CLI to count tokens and compare model costs across providers before you spend money. For exact OpenAI-only token counts inside Python, use tiktoken (tokencost uses it under the hood for OpenAI models). For a full multi-provider request gateway or a larger pricing database in code, look at LiteLLM or the AgentOps/tokencost library.
Part of the alvabillwu AI/LLM DevTools suite:
ctxpackβ Pack documents into an LLM context-window budgettoken-vizβ Token usage visualization toolkitllm-routerβ Intelligent LLM request routing and load balancingpromptdriftβ Detect prompt drift across model versions
MIT Β© alvabillwu
β Like this? Star the repo to support open-source LLM tooling!