tokencost
To calculate token and translated USD cost of string and message calls to OpenAI, for example when used by AI agents
Decision gist · record as of 2026-08-14
Yes, if you build with LLM APIs and need cost visibility before or after requests. The package is straightforward, permissively licensed, and has low install friction. However, be aware that maintenance is aging—pricing tables may lag behind provider updates, and support for newly released models is not guaranteed. Verify that the models you use are in the pricing table before relying on it for cost estimates.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction install with three runtime dependencies (tiktoken, aiohttp, anthropic).
- Maintenance status is aging—last commit was 2025-09-05 and the package has not had a release since 2025-08-13, though the repository remains active and is not archived.
License · maintenance · safety
permissive license (permissive) — Licensed under MIT (permissive), so you can use, modify, and distribute freely with minimal restrictions.
last release 2025-08-13 (366 days) · last repo commit 2025-09-05 · 2,003 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 396,149 downloads/mo, #6,971 on PyPI
Alternatives
Verify before relying
pip install tokencost
from tokencost import calculate_prompt_cost, calculate_completion_cost
model = "gpt-3.5-turbo"
prompt = [{"role": "user", "content": "Hello world"}]
completion = "How may I assist you today?"
prompt_cost = calculate_prompt_cost(prompt, model)
completion_cost = calculate_completion_cost(completion, model)
print(f"{prompt_cost} + {completion_cost} = {prompt_cost + completion_cost}")- Whether pricing table is automatically updated when providers change rates, or requires manual maintenance.
- Support status for models released after the latest 2025-08-13 release.
- Whether aiohttp is used for async cost calculation or is an indirect dependency.
What it is and what it does
TokenCost is a client-side utility for estimating the USD cost of LLM API calls by counting tokens and applying current pricing. It wraps OpenAI's tiktoken tokenizer for accurate token counting on OpenAI and older Claude models, and uses Anthropic's beta token counting API for Claude 3 and later. The package maintains a pricing table for major LLM providers and exposes simple functions to calculate prompt and completion costs from either message-formatted lists or raw strings.
You use it to estimate costs before sending requests to an LLM API, or to calculate the cost of responses you've already received. It integrates with the OpenAI and Anthropic client libraries and is commonly used in AI agent frameworks to track spending. The package depends on tiktoken, aiohttp, and anthropic as runtime dependencies.
Use it for
- Estimate the cost of a prompt before sending it to OpenAI or Anthropic to stay within budget.
- Track total token costs in an AI agent that makes multiple LLM calls across different models.
- Count tokens in a string or message list without making an API call, using tiktoken directly.
- Compare pricing across different LLM models to choose the most cost-effective option for a task.
- Log and report spending on LLM APIs in production applications.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you build with LLM APIs and need cost visibility before or after requests.
The package is straightforward, permissively licensed, and has low install friction. However, be aware that maintenance is aging—pricing tables may lag behind provider updates, and support for newly released models is not guaranteed. Verify that the models you use are in the pricing table before relying on it for cost estimates.
Install
tokencost on PyPI
Before you install
Low friction install with three runtime dependencies (tiktoken, aiohttp, anthropic). Maintenance status is aging—last commit was 2025-09-05 and the package has not had a release since 2025-08-13, though the repository remains active and is not archived.
Requires Python 3.10 or later.
License in practice
Licensed under MIT (permissive), so you can use, modify, and distribute freely with minimal restrictions.
Quickstart
pip install tokencost
from tokencost import calculate_prompt_cost, calculate_completion_cost
model = "gpt-3.5-turbo"
prompt = [{"role": "user", "content": "Hello world"}]
completion = "How may I assist you today?"
prompt_cost = calculate_prompt_cost(prompt, model)
completion_cost = calculate_completion_cost(completion, model)
print(f"{prompt_cost} + {completion_cost} = {prompt_cost + completion_cost}")
Verify before relying
- Whether pricing table is automatically updated when providers change rates, or requires manual maintenance.
- Support status for models released after the latest 2025-08-13 release.
- Whether aiohttp is used for async cost calculation or is an indirect dependency.
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagestiktokenaiohttpanthropic |
| Maintenance | Aging 366 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 396,149 / month, #6,971 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 |
Evidence: tokencost-0.1.26-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “llm token counting”
- tokencostCounts tokens and estimates USD costs for LLM API calls across…
- openai-messages-token-helperEstimates token usage for OpenAI Chat Completions API messages and…
- mistral_commonProvides tokenizers, validation, and normalization utilities for…
Give your agent the search over MCP, or paste the wish link into any chat.
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to call 100+ LLM providers (OpenAI, Anthropic, Gemini, Bedrock, Azure, and others) using OpenAI-compatible API format, available as both a Python SDK and a self-hosted AI Gateway proxy server.
Install it if you need to work with multiple LLM providers or want to centralize LLM routing in your organization.
Client library and CLI tool for downloading, uploading, and managing models, datasets, and repositories on the Hugging Face Hub platform.
Install it if you work with Hugging Face Hub models or datasets.
LangChain provides a framework for building agents and LLM-powered applications by composing language models, tools, and memory through a unified API that abstracts over multiple model providers.
hf-xet provides chunk-based deduplication and efficient file transfer for the Hugging Face Hub, enabling faster uploads and downloads of large files with local disk caching.
Tokenizers converts raw text into token sequences for NLP models, with support for training custom vocabularies and using pre-built tokenizers (BPE, WordPiece) optimized for speed via Rust.
Transformers provides a unified framework for loading, fine-tuning, and running state-of-the-art pretrained models across text, vision, audio, video, and multimodal tasks using PyTorch, JAX, or TensorFlow.
Install it if you need to run or train any transformer-based model for NLP, vision, audio, or multimodal tasks.
See also openai-messages-token-helper · genai-prices · gptcache · fhlmi · headroom-ai · agentops · litellm-enterprise · unclecode-litellm