Supports OpenAI GPT, Google Gemini, Anthropic Claude and xAI Grok APIs
To install:
pip install gpt-token-tracker
Examples:
from gpt_token_tracker.token_logger import TokenLogger
from gpt_token_tracker.writers.log_writer import LogWriter
from gpt_token_tracker.pricing import PricingRealtime
log_writer = LogWriter("realtime_tokens") ### Name of logger
realtime_costs = {
"text_in": 0.60,
"cached_text_in": 0.06,
"text_out": 2.40,
"audio_in": 10.00,
"audio_out": 20.00,
"image_in": 5.00,
"cached_image_in": 0.50,
"cached_audio_in": 0.40,
}
token_logger = TokenLogger(log_writer, PricingRealtime(realtime_costs))
token_logger_realtime.record(realtime_model, realtime_result, fake_realtime_usage)
MODEL_NAME = "gpt-realtime-mini"
response = ...
realtime_result = "This is a fake realtime result"
usage = response.usage
token_logger.record(MODEL_NAME, realtime_result, usage)
from gpt_token_tracker.token_logger import TokenLogger
from gpt_token_tracker.writers.csv_writer import CSVWriter
from gpt_token_tracker.pricing import PricingTextCompletion
csv_writer = CSVWriter("completion_usage.csv")
text_completion_costs = {
"text_in": 0.25,
"cached_text_in": 0.025,
"text_out": 2.00,
}
csv_token_logger = TokenLogger(csv_writer, PricingTextCompletion(text_completion_costs))
MODEL_NAME = "gpt-5-mini"
response = ...
completion_result = "This is a fake completion result"
usage = response.usage
csv_token_logger.record(MODEL_NAME, completion_result, usage)
from gpt_token_tracker.token_logger import TokenLogger
from gpt_token_tracker.writers.csv_writer import CSVWriter
from gpt_token_tracker.pricing_gemini import PricingGemini
csv_writer = CSVWriter("gemini_usage.csv")
costs = {
"text_in": 0.10,
"image_in": 0.10,
"video_in": 0.10,
"audio_in": 0.30,
"cached_text_in": 0.01,
"cached_video_in": 0.01,
"cached_image_in": 0.01,
"cached_audio_in": 0.03,
"text_out": 0.40,
"audio_out": 0.40,
"thinking": 0.40
}
csv_token_logger = TokenLogger(csv_writer, PricingGemini(costs))
MODEL_NAME = "gemini-2.5-flash-native-audio"
response = ...
result = "This is a fake completion result"
usage = ...
csv_token_logger.record(MODEL_NAME, result, usage)
To run tests:
python -m pip install -r requirements.txt -r requirements_tests.txt --upgrade
python -m pytest tests
Metadata
Release files for gpt-token-tracker 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gpt_token_tracker-0.5.0.tar.gz | 10.7 kB | Without provenance | Details for gpt_token_tracker-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gpt_token_tracker-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for gpt_token_tracker-0.5.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / gpt_token_tracker-0.5.0.tar.gz
| Download URL | gpt_token_tracker-0.5.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09aa849a3fab8c8b3c91c08c06e364a46928ca6e71a6837d44d18e8e16a0582d
|
|
BLAKE2b-256 checksum How to use checksums |
eda4c8f9eb22419f9a65ed5b7b6354592ab30393d2de1bfc480bdd6380d940e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / gpt_token_tracker-0.5.0-py3-none-any.whl
| Download URL | gpt_token_tracker-0.5.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dcd05e5980ab7aeb0a5f197b7c1a725e9ce7df9980e5c01f904a4bf589ce18a7
|
|
BLAKE2b-256 checksum How to use checksums |
dbe8b1aa924ebd47f0bee242008d5b6be54ef71739d080631ef389e31c3adc61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for gpt-token-tracker 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.