Simple and lightweight Python package to track LLM API cost
Project description
🚀 costtracker
Track your LLM API cost in real time — with one line of code.
✨ Why costtracker?
Building with LLMs is easy.
Tracking cost isn’t.
costtracker solves this by giving you:
⚡ Instant cost visibility for every API call
No dashboards. No setup. No complexity.
🔥 Features
- 📊 Real-time token + cost tracking
- ⚡ One-line integration (
track(response)) - 🧠 Works with OpenAI-compatible APIs for now (Gemini included)
- 🪶 Lightweight & zero-config
- 🧱 Built for developers
⚡ Quick Demo
from costtracker import track
track(response)
⚡ Output
Model: gemini-2.5-flash-lite
Tokens: 13 (input: 4, output: 9)
Cost: $0.000011
📦 Installation
pip install -e .
⚙️ Setup
Create a .env file in your root directory:
GEMINI_API_KEY=your_api_key_here
🧪 Usage
import os
from dotenv import load_dotenv
from openai import OpenAI
from costtracker import track
load_dotenv()
client = OpenAI(
api_key=os.getenv("GEMINI_API_KEY"),
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)
response = client.chat.completions.create(
model="gemini-2.5-flash-lite",
messages=[
{"role": "user", "content": "Hello there!"}
]
)
track(response)
💡 Use Cases
- 🧑💻 AI app developers tracking API usage
- 🚀 Startup teams controlling LLM costs
- 📊 Experimentation with prompt optimization
- 🧪 GenAI project building
🤝 Contributing
- Contributions are welcome!
- Feel free to open issues or submit PRs.
⭐ If you like this project
Give it a star
📄 License
MIT License
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
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
File details
Details for the file costtracker-0.1.0.tar.gz.
File metadata
- Download URL: costtracker-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d3c4d4afe7e60ce752478bacfa98b02f608953ac16493f0cf7e67104e9c2d88
|
|
| MD5 |
a184e361280d831a209ab9a72cbb5ebd
|
|
| BLAKE2b-256 |
4cdcef9163efd4ccd45f6bbb86e722cb46eb92e1ba3bae595409a59e9273b7b1
|
File details
Details for the file costtracker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: costtracker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18c2cde43d48798e92d8870cd7ff6e99be30bc43f5c1af88e9421a2c606792c4
|
|
| MD5 |
ac805bae965078f4a890d740d3ebfea1
|
|
| BLAKE2b-256 |
81e7fb98b1201564b627034ef3bd9860a830fa81ab27daec8d5da982c585254f
|