--- id: tokencost version: "0.1.26" license: unclear license_treatment: permissive maintenance: aging --- # tokencost — To calculate token and translated USD cost of string and message calls to OpenAI, for example when used by AI agents License: permissive · Maintenance: aging · Downloads: 396.1K/mo ## 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 above — verify before relying. Counts tokens and estimates USD costs for LLM API calls across OpenAI, Anthropic, and other major providers before or after requests are sent. 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 pip install tokencost uv add tokencost poetry add tokencost ## Installing tokencost 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. 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}") Requires Python 3.10 or later. 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: not declared (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 396.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags llm token counting, openai cost estimation, prompt pricing calculator, ai api cost tracking, token counter for llms, anthropic token counting, llm billing estimation, llm-cost-tracking, token-counting, api-pricing [View on SkillFed](https://skillfed.io/packages/tokencost) · [View on PyPI](https://pypi.org/project/tokencost/)