Skip to content

alvabillwu/tokencost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ tokencost

PyPI PyPI downloads Python License

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.

Why tokencost?

  • 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-4o fits naturally into shell scripts and CI pipelines.
  • Zero config β€” install and run. No API keys, no accounts, no setup.

Features

  • πŸ”’ 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

Quick Start

pip install tokencost

Usage

Count tokens

# 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

Estimate cost

# 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 1000

Compare models

tokencost compare --input-tokens 10000 --output-tokens 5000

Output:

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

Suggest cheapest model

tokencost suggest --file my_prompt.txt --budget 0.50

List all models

tokencost list
tokencost list --provider OpenAI
tokencost list --json

Supported Models (June 2026)

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
Google Gemini 2.5 Pro, Gemini 2.5 Flash
Meta Llama 4 Maverick, Llama 4 Scout
DeepSeek DeepSeek V3
Alibaba Qwen3 235B

Development

git clone https://github.com/alvabillwu/tokencost.git
cd tokencost
pip install -e ".[dev]"
pytest

πŸ”„ Alternatives

An 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.

πŸ”— Ecosystem

Part of the alvabillwu AI/LLM DevTools suite:

  • ctxpack β€” Pack documents into an LLM context-window budget
  • token-viz β€” Token usage visualization toolkit
  • llm-router β€” Intelligent LLM request routing and load balancing
  • promptdrift β€” Detect prompt drift across model versions

License

MIT Β© alvabillwu


⭐ Like this? Star the repo to support open-source LLM tooling!

About

πŸ”’ LLM Token Cost Calculator β€” count tokens, estimate costs, compare models across OpenAI, Anthropic, Google, Meta & more from the CLI

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages