Zero-config AI cost calculator per commit/model with liteLLM
Project description
AI Cost Tracker
Zero-config AI cost calculator per commit/model with liteLLM integration.
Track AI usage costs across your git commits with three flexible usage modes - no initial configuration required.
Features
- liteLLM Integration - Support for 100+ AI providers via liteLLM
- OpenRouter Default - Pre-configured for OpenRouter with Qwen models
- Zero Config - Works out of the box, reads from
.envfile - Smart Token Estimation - Accurate cost calculation using liteLLM tokenizers
- ROI Calculation - Track value generated vs AI costs
Installation
pip install ai-cost-tracker
Quick Start
1. Initialize Configuration
aicost init
# Edit .env file to add your OpenRouter API key
echo "OPENROUTER_API_KEY=YOUR_KEY" >> .env
2. Run Analysis
# Uses defaults from .env (OpenRouter + Qwen)
aicost analyze --repo .
# Or specify directly
aicost analyze --repo . --model openrouter/qwen/qwen3-coder-next --api-key YOUR_KEY
Configuration
Create a .env file in your project root:
# Required: OpenRouter API key (https://openrouter.ai/keys)
OPENROUTER_API_KEY=YOUR_KEY
PFIX_MODEL=openrouter/qwen/qwen3-coder-next
Or use the built-in init command:
aicost init
Three Usage Options (Zero Config Required)
Option 1: BYOK (Bring Your Own Key) - Free
Use your own API key via OpenRouter. Costs calculated locally with real provider pricing.
# With OpenRouter key (default from .env)
aicost analyze --repo .
# Explicit key
aicost analyze --repo . --api-key YOUR_KEY
Supported models via liteLLM:
openrouter/qwen/qwen3-coder-next(default)openrouter/qwen/qwen3-coderanthropic/claude-3.5-sonnetopenai/gpt-4oollama/llama2(local)- 100+ more via liteLLM
Option 2: Local/Ollama - Zero API Costs
No API key needed. Estimates based on diff size using local pricing.
aicost --repo . --mode local
Estimation formula: diff_chars / 4 * 0.0001$/M tokens
How It Works
- Parse git history - Analyzuje commity z tagami
[ai:model] - Estimate tokens - Używa heurystyki lub liteLLM do liczenia tokenów
- Calculate cost - Mnoży tokeny × cena za model
- Generate ROI - Szacuje oszczędność czasu (100 LOC/h × $100/h)
Why liteLLM?
- Universal API - Jedna składnia dla 100+ providerów
- Automatic routing - Fallback między providerami
- Cost tracking - Wbudowane liczenie tokenów
- OpenRouter - Dostęp do najnowszych modeli bez kont premium
Option 3: SaaS Subscription - Managed
Enterprise managed solution with dashboard and invoicing.
aicost --repo . --saas-token PLACEHOLDER
Usage Examples
# Initialize .env config
aicost init
# Analyze last 50 commits (uses .env defaults)
aicost analyze --repo . -n 50
# Use specific model via liteLLM
aicost analyze --repo . --model anthropic/claude-3.5-sonnet
# Analyze all commits (not just AI-tagged)
aicost analyze --repo . --all
# Export to custom file
aicost analyze --repo . --output my_costs.csv
# Estimate single diff
aicost estimate my_changes.patch
# Read diff from stdin
git diff HEAD~1 | aicost estimate -
Tagging AI Commits
Tag commits with [ai:model] for automatic tracking:
git commit -m "[ai:openrouter/qwen/qwen3-coder-next] Refactor authentication"
git commit -m "[ai:anthropic/claude-3.5-sonnet] Add payment integration"
Sample Output
🔍 Analyzing 100 commits from my-project...
🤖 Model: openrouter/qwen/qwen3-coder-next | Mode: byok
==================================================
📊 AI COST ANALYSIS - openrouter/qwen/qwen3-coder-next
==================================================
Commits analyzed: 42
Total cost: $0.3245
Hours saved: 15.3h
Value generated: $1530.00
ROI: 4718x
==================================================
📁 Results saved to: ai_costs.csv
💡 Recent AI commits:
a1b2c3d4 | $0.0089 | [ai:qwen3-coder-next] Refactor...
e5f6g7h8 | $0.0121 | [ai:claude-3.5-sonnet] Add feature...
CSV Export Format
| Column | Description |
|---|---|
commit_hash |
Short commit SHA |
commit_message |
Full commit message |
author |
Commit author name |
date |
ISO format datetime |
cost |
Calculated cost in USD |
cost_formatted |
Formatted cost string |
model |
AI model used |
mode |
Calculation mode (byok/local/saas) |
tokens_input |
Estimated input tokens |
tokens_output |
Estimated output tokens |
hours_saved |
Estimated hours saved |
roi |
ROI multiplier |
Pricing Reference
| Model | Input | Output |
|---|---|---|
| openrouter/qwen/qwen3-coder-next | $0.50/M | $1.50/M |
| openrouter/qwen/qwen2.5-coder | $0.30/M | $1.00/M |
| anthropic/claude-3.5-sonnet | $3/M | $15/M |
| anthropic/claude-3.5-haiku | $0.8/M | $4/M |
| openai/gpt-4o | $5/M | $15/M |
| openai/gpt-4o-mini | $0.15/M | $0.6/M |
| ollama/* | ~$0.0001/M | ~$0.0001/M |
Business Model
| Tier | Price | Features |
|---|---|---|
| BYOK | Free | Use your own OpenRouter API key |
| SaaS | $9/month | Unlimited, managed keys, dashboard, EU invoicing |
Development
# Install with poetry
poetry install
# Run CLI
poetry run aicost analyze --repo ..
# Publish to PyPI
poetry publish --build
Environment Variables
| Variable | Description | Default |
|---|---|---|
OPENROUTER_API_KEY |
OpenRouter API key | (required for BYOK) |
PFIX_MODEL |
Default model for calculations | openrouter/qwen/qwen3-coder-next |
License
Licensed under Apache-2.0.
Licensed under Apache-2.0.
Licensed under Apache-2.0.
Licensed under Apache-2.0.
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 costs-0.1.14.tar.gz.
File metadata
- Download URL: costs-0.1.14.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca15bf5aaf6677e5f1399498401c0d7b5b4d1b2d7ae45b591ba9e9b1ff557b66
|
|
| MD5 |
b8c99ae0d6926927050df25dbcecf124
|
|
| BLAKE2b-256 |
5ef9e70214ff8cbc46620f8e67a3e58eba77896f00d3dd6217acece66029155d
|
File details
Details for the file costs-0.1.14-py3-none-any.whl.
File metadata
- Download URL: costs-0.1.14-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d4297ff31c2e52e082bf3b70a3b25746e3e163f00eb91d2ad51dad37bf255c
|
|
| MD5 |
2aaf4f0a0b3441bc1e15b4deb199dcb1
|
|
| BLAKE2b-256 |
6a3d56e4f31e29b90f528e6464cb44ba1e6cde74b73854073aa5d52b6c52f27d
|