RadarTopicsBuildersWeeklyReads
Open Source Radar
AgentOps-AI/

tokencost

GitHubWebsite

Tokencost estimates token costs for 400+ LLMs, tracks prices, and counts tokens for prompts and completions. It provides usage examples and a cost table. Latest release adds AWS Bedrock model cost tracking.

2.0kstars
105forks
29issues
MITlicense
2023since
Star historydaily snapshots by VibeCrowd

Collecting history — the radar snapshots this repo daily. The trend line appears after 3 days of data (1 so far).

Alternatives & relatedmatched by topic overlap
Reviewgenerated from repository data · Aug 5, 2026

What it is

Tokencost helps calculate the USD cost of using major LLM APIs by calculating the estimated cost of prompts and completions, and tracks token prices for models.

How it works

Tokens are counted using tokenization methods (including Tiktoken for strings and ChatML messages). It provides functions to calculate prompt and completion costs and to count tokens for both message-based and string prompts. The repository includes a cost table mapping models to per-1M-token costs and token limits.

Getting started

Installation

pip install tokencost

Usage (cost estimation)

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}")

Usage (string prompts)

from tokencost import calculate_prompt_cost

prompt_string = "Hello world" 
response = "How may I assist you today?"
model= "gpt-3.5-turbo"

prompt_cost = calculate_prompt_cost(prompt_string, model)
print(f"Cost: ${prompt_cost}")

Counting tokens

from tokencost import count_message_tokens, count_string_tokens

message_prompt = [{ "role": "user", "content": "Hello world"}]
print(count_message_tokens(message_prompt, model="gpt-3.5-turbo"))

print(count_string_tokens(prompt="Hello world", model="gpt-3.5-turbo"))

Recent releases

  • 0.1.26 (2025-08-13): Add AWS Bedrock model cost tracking. This release includes comprehensive support for AWS Bedrock models with flexible pricing pattern matching and model configuration. Changes include adding AWS Bedrock.
  • 0.1.25 (2025-07-22): Daily token price updates and performance fixes such as a 10-second timeout for price requests.
  • 0.1.24 (2025-06-24): Daily token price update notes.
  • 0.1.23 (2025-06-09): Daily token price update.
  • 0.1.22 (2025-05-23): Daily token price update and added support for cached tokens in costs module.

Traction

1999 stars, 105 forks, 29 open issues.

Behind the repo

Not applicable unless a linked startup/company is specified in the repository metadata.

Caveats

License: MIT. Created 2023-12-03. Last push 2025-09-05. Language: Python.

SharePost on XLinkedIn
All trending reposRevenue-verified startups →