OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Tokencost

Tokencost is an open-source Python library that counts tokens in text and message-formatted prompts and estimates the USD costs of LLM prompts and completions. Its README describes support for more than 400 models and provides examples for OpenAI and Anthropic model families.

Independent OpenViST project profile, based on linked sources.

Tokencost — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use Tokencost when a Python application needs prompt token counts or estimated prompt and completion costs for supported LLM models.

Who it is for

  • Python developers building applications that use LLM APIs
  • AI-agent developers who want to estimate token usage and API costs across steps
  • Teams comparing estimated costs across supported models

Documented uses

  • Count tokens in a string prompt or message list.
  • Estimate the USD cost of a prompt before making an API request.
  • Estimate completion costs and combine them with prompt costs.
  • Add projected LLM usage costs to application displays or agent cost tracking.
Before you choose

Requirements & limits

The repository identifies the project as MIT-licensed open source and documents installation through PyPI.

  • Tokencost provides estimates rather than making the model request in the documented examples.
  • Its token-counting method depends on the model family and generation; older Claude models are described as using an approximation.
  • The README describes USD estimates and coverage of more than 400 LLMs.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Install Tokencost and estimate a prompt cost

Set up the Python package and calculate an estimated prompt cost from a string or message list.

Before you start

  • Python environment
  • A model name and prompt text or message list

Steps

  1. Install the package with the command below.

    Documented command
    pip install tokencost
  2. Import calculate_prompt_cost from tokencost.

  3. Pass a prompt string or message list and a model name to calculate the estimated prompt cost.

Expected outcome

A USD prompt-cost estimate for the selected model and prompt.

Guide limitations

  • The result is an estimate based on the library’s model pricing and token-counting methods.
  • The documented instructions do not establish that this procedure sends an LLM request.
Source-based practical guide

Count tokens in a string or message prompt

Use Tokencost’s documented counting functions to obtain a token count for prompt text.

Before you start

  • Tokencost installed in a Python environment
  • A model name and either a string prompt or a message list

Steps

  1. Import count_string_tokens and count_message_tokens from tokencost.

  2. Pass a string prompt and model name to count_string_tokens, or pass a message list and model name to count_message_tokens.

Expected outcome

A token count for the supplied string or formatted messages.

Guide limitations

  • The README describes different counting methods for model families: Tiktoken for strings and ChatML, Anthropic’s beta counting API for Anthropic models above version 3, and Tiktoken approximation for older Claude models.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
13 October 2026
Original website title
AgentOps-AI/tokencost · Official homepage title · retained in its source language