Observed since 21 Oct, 10:19 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Zero-config OpenAI API cost tracking - just one import and you're done!
Zero-config OpenAI API cost tracking - just one import and you're done!
Track all your OpenAI API usage automatically without modifying your existing code. Supports GPT-4, GPT-3.5, DALL-E, Sora, and more.
pip install ai-cost-tracker
In your main Python file (the one that runs first):
import openai_cost_tracker.services.zero_config_tracker
That's it! All your OpenAI calls are now automatically tracked.
# Your existing code works as-is - no changes needed!
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello"}]
)
# This call is automatically tracked! ✨
# View cost summary
openai-cost-view
# View last 7 days
openai-cost-view --days 7
# View by service
openai-cost-view --service my_service
# Export to JSON
openai-cost-view --export costs.json
# app.py
from flask import Flask
import openai_cost_tracker.services.zero_config_tracker # Add this line
app = Flask(__name__)
from openai import OpenAI
client = OpenAI()
@app.route('/chat')
def chat():
# Automatically tracked!
response = client.chat.completions.create(...)
return response
# main.py
from fastapi import FastAPI
import openai_cost_tracker.services.zero_config_tracker # Add this line
app = FastAPI()
from openai import OpenAI
client = OpenAI()
@app.post("/chat")
async def chat():
# Automatically tracked!
response = await client.chat.completions.create(...)
return response
# my_script.py
import openai_cost_tracker.services.zero_config_tracker # Add this line
from openai import OpenAI
client = OpenAI()
# All calls automatically tracked!
response = client.chat.completions.create(...)
If you prefer manual tracking:
from openai_cost_tracker import get_tracker
from openai import OpenAI
client = OpenAI()
tracker = get_tracker()
response = client.chat.completions.create(...)
usage = response.usage
tracker.log_api_call(
api_key=os.getenv("OPENAI_API_KEY"),
api_type="chat",
model="gpt-4",
operation="create",
cost=tracker.calculate_chat_cost(
model="gpt-4",
tokens_input=usage.prompt_tokens,
tokens_output=usage.completion_tokens
),
tokens_input=usage.prompt_tokens,
tokens_output=usage.completion_tokens
)
Find all OpenAI usage in your project:
openai-cost-scan
# Scan specific directory
openai-cost-scan --scan-root /path/to/project
Set up daily email summaries with our interactive wizard:
# Install email support
pip install "ai-cost-tracker[email]"
# Run the interactive email configuration wizard
openai-cost-config-email
The wizard supports:
Then start the monitor:
openai-cost-monitor
That's it! You'll receive daily cost reports automatically.
import openai_cost_tracker.services.zero_config_tracker # That's it!
npm install ai-cost-tracker
const { getTracker } = require('ai-cost-tracker');
const tracker = getTracker();
await tracker.trackOpenAI(response, 'gpt-4', apiKey);
npm install ai-cost-tracker
import { useCostTracker, CostSummary } from 'ai-cost-tracker/react';
function App() {
const { trackOpenAI } = useCostTracker();
return <CostSummary days={7} />;
}
See EXAMPLES.md for Ruby, PHP, Go, Vue.js, and more!
All data is stored locally in SQLite:
~/.openai_cost_tracker/openai_usage.dbCostTracker(db_path="/custom/path")openai-cost-viewView cost summaries and usage statistics.
openai-cost-view [--days N] [--service NAME] [--api-key HASH] [--recent N] [--json] [--export FILE]
openai-cost-scanScan codebase for OpenAI usage.
openai-cost-scan [--scan-root PATH] [--output FILE]
openai-cost-monitorRun monitoring service with email reports.
openai-cost-monitor [--config PATH] [--db-path PATH] [--no-scan]
Automatically calculates costs based on current OpenAI pricing:
Optional environment variables:
# Enable verbose output
export OPENAI_COST_TRACKER_VERBOSE=1
# Custom database location
export COST_TRACKER_DB=/path/to/openai_usage.db
from openai_cost_tracker import CostTracker, get_tracker
tracker = get_tracker() # Get global tracker
# or
tracker = CostTracker(db_path="/custom/path") # Custom tracker
# Calculate costs
cost = tracker.calculate_chat_cost("gpt-4", tokens_input=1000, tokens_output=500)
image_cost = tracker.calculate_image_cost("dall-e-3", size="1024x1024")
video_cost = tracker.calculate_video_cost("sora-2", seconds=8)
# Get summary
summary = tracker.get_usage_summary(days=7)
Contributions welcome! Please see our contributing guidelines.
MIT License - see LICENSE file
pip install ai-cost-tracker
✅ Published to PyPI: https://pypi.org/project/ai-cost-tracker/0.1.0/
Made with ❤️ for developers who want to track their AI costs without the hassle.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 7 Nov 2025 | 6 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 21 Oct, 10:19 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:77262420c7a88ef69692df1d85165831303afcabbfdfbbf1c455ca5328ab0317