Token usage tracking wrapper for LLMs
Project description
Tokenator : Easiest way to track and analyze LLM token usage and cost
Have you ever wondered about :
- How many tokens does your AI agent consume?
- How much does it cost to do run a complex AI workflow with multiple LLM providers?
- How much money did I spent today on development?
Afraid not, tokenator is here! With tokenator's easy to use API, you can start tracking LLM usage in a matter of minutes.
Get started with just 3 lines of code!
Installation
pip install tokenator
Usage
OpenAI
from openai import OpenAI
from tokenator import tokenator_openai
openai_client = OpenAI(api_key="your-api-key")
# Wrap it with Tokenator
client = tokenator_openai(openai_client)
# Use it exactly like the OpenAI client
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
Cost Analysis
from tokenator import cost
# Get usage for different time periods
cost.last_hour()
cost.last_day()
cost.last_week()
cost.last_month()
# Custom date range
cost.between("2024-03-01", "2024-03-15")
# Get usage for different LLM providers
cost.last_day("openai")
cost.last_day("anthropic")
cost.last_day("google")
Example cost object
# print(cost.last_hour().model_dump_json(indent=4))
usage : {
"total_cost": 0.0004,
"total_tokens": 79,
"prompt_tokens": 52,
"completion_tokens": 27,
"providers": [
{
"total_cost": 0.0004,
"total_tokens": 79,
"prompt_tokens": 52,
"completion_tokens": 27,
"provider": "openai",
"models": [
{
"total_cost": 0.0004,
"total_tokens": 79,
"prompt_tokens": 52,
"completion_tokens": 27,
"model": "gpt-4o-2024-08-06"
}
]
}
]
}
Features
- Drop-in replacement for OpenAI, Anthropic client
- Automatic token usage tracking
- Cost analysis for different time periods
- SQLite storage with zero configuration
- Thread-safe operations
- Minimal memory footprint
- Minimal latency footprint
Most importantly, none of your data is ever sent to any server.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tokenator-0.1.9.tar.gz
(12.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
tokenator-0.1.9-py3-none-any.whl
(16.5 kB
view details)
File details
Details for the file tokenator-0.1.9.tar.gz.
File metadata
- Download URL: tokenator-0.1.9.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.0 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf8d053079df5a9340a71d512feacec53420ffa00035e7e9b5ec63f93ae62b4
|
|
| MD5 |
61454d9394e91aabb8f46dd0dd516870
|
|
| BLAKE2b-256 |
97e154f1373479257e5347837eb15ee7cd9fb5a41ce5b807dc4d2f1ad85924fc
|
File details
Details for the file tokenator-0.1.9-py3-none-any.whl.
File metadata
- Download URL: tokenator-0.1.9-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.0 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb7da3602c03b2de4c549487ba977eceda8016cee5d11053f14ee3e308d2668f
|
|
| MD5 |
53a02e256f862ca17ed741c253f73539
|
|
| BLAKE2b-256 |
acca527d724e97751e040e20447b22e0abe816106ed669f795116712ca2f5a18
|