Stop guessing your AI costs. Start managing them like a CFO.
ComputeCFO is an AI Financial Officer Agent that tracks, analyzes, and optimizes your LLM API spending. It works both as a standalone dashboard and as a Python library you can integrate into any project. Inspired by Graham's value investing, Pacioli's double-entry bookkeeping, and Alphabet's independent accounting model.
Every AI developer eventually faces these questions:
- ๐ธ "Wait, I spent HOW much this month?"
- ๐ค "Which feature is burning through my budget?"
- ๐ "Am I getting good ROI on this AI investment?"
- ๐จ "How do I prevent a $500 surprise bill?"
- ๐ข "How much is each project costing independently?"
- ๐ "Is there an anomaly in my spending pattern?"
ComputeCFO answers all of these โ as a library with 3 lines of code, or as a full dashboard with 1 command.
pip install computecfo fastapi uvicorn
python -m computecfo.server # or: python server.py
# Open http://localhost:8878Local use only. The dashboard has no authentication, so it binds to
127.0.0.1by default. Don't changeHOSTto0.0.0.0or expose port 8878 publicly unless you put your own access control (e.g. a reverse proxy) in front of it โ anyone who can reach the port can read your LLM spending data.
The dashboard provides real-time cost monitoring with:
- Financial overview with daily/weekly/monthly summaries
- Interactive spending trend charts
- Model value scoring (Graham-inspired)
- Project-level independent accounting
- Anomaly detection ("Mr. Market" alarm)
- Pre-call cost estimator
- Dark/Light theme toggle
- Chinese/English language switch
pip install computecfofrom computecfo import CostTracker
tracker = CostTracker()
# Record an API call (after your Claude/OpenAI/Gemini call)
tracker.record("claude-sonnet-4-20250514",
input_tokens=1500, output_tokens=500,
module="chatbot", action="respond",
project="my-saas")
# Check spending
print(tracker.get_today())
# {'cost': 0.012, 'calls': 1, 'total_tokens': 2000, ...}tracker.get_today() # Today's spending
tracker.get_this_month() # Monthly total
tracker.get_by_module() # Cost per feature
tracker.get_by_model() # Cost per model
tracker.get_by_project() # Cost per project
tracker.get_daily_trend(30) # 30-day chart data
tracker.get_recent(20) # Last 20 API calls
tracker.get_projected_monthly() # Projected monthly cost
# All query methods support project filtering:
tracker.get_today(project="my-saas")
tracker.get_by_model(project="internal-tools")from computecfo import CostTracker, track_cost
tracker = CostTracker()
@track_cost(tracker, module="chatbot", action="respond", project="my-saas")
def ask_claude(prompt):
response = anthropic.messages.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": prompt}]
)
return response
# Cost is automatically recorded โ works with Anthropic, OpenAI, and dict responses
result = ask_claude("Hello!")Supports sync and async functions, with auto-detection for Anthropic and OpenAI response formats.
# Alphabet-style independent cost tracking per project
tracker.record("claude-opus-4-20250514", 2000, 800,
module="search", project="google-search")
tracker.record("gpt-4o", 1500, 600,
module="vision", project="waymo")
# Independent P&L per project
for p in tracker.get_by_project():
print(f"{p['project']}: ${p['cost']:.2f}")from computecfo import BudgetManager
from computecfo.models import BudgetConfig
config = BudgetConfig(
daily_limit=5.0, # $5/day
monthly_limit=100.0, # $100/month
auto_downgrade=True, # auto-switch to cheaper model when over budget
)
budget = BudgetManager(tracker, config)
# Before each API call:
check = budget.pre_call_check("claude-opus-4-20250514")
if check["approved"]:
model = check["model"] # might be downgraded to sonnet!
else:
print(f"Blocked: {check['reason']}")Three protection levels:
| Level | Trigger | Action |
|---|---|---|
| Warning | 80% of budget | Log warning |
| Critical | 100% of budget | Auto-downgrade model |
| Circuit Break | 150% of budget | Block all API calls |
from computecfo.models import estimate_tokens
# Know the cost before you spend โ Margin of Safety
estimate = budget.estimate_call_cost(
model="claude-opus-4-20250514",
prompt="Analyze this codebase and suggest improvements..."
)
print(f"Estimated cost: ${estimate['estimated_cost']:.4f}")
print(f"Budget remaining: ${estimate['budget_remaining']:.2f}")
if estimate.get("cheaper_alternative"):
print(f"Try {estimate['cheaper_alternative']} instead")from computecfo import CostAnalyzer
analyzer = CostAnalyzer(tracker)
# Graham-inspired value analysis โ find the "undervalued" models
for score in analyzer.get_model_value_scores():
print(f"{score['model']}: {score['grade']} "
f"(value: {score['value_score']}/100) โ {score['recommendation']}")# "Mr. Market" alarm โ detect irrational spending patterns
anomalies = analyzer.detect_anomalies()
for a in anomalies:
print(f"[{a['severity']}] {a['type']}: {a['message']}")
# [high] spending_spike: Spending on 2025-01-15 was 3.2x above average
# [medium] premium_creep: Premium model usage increased from 20% to 65%from computecfo import AlertManager, AlertConfig, create_budget_callbacks
alerts = AlertManager(AlertConfig(
telegram_bot_token="123456:ABC-DEF...", # from @BotFather
telegram_chat_id="-1001234567890", # your chat/group/channel ID
# Also supports:
# slack_webhook="https://hooks.slack.com/services/...",
# discord_webhook="https://discord.com/api/webhooks/...",
))
# Connect to budget system
callbacks = create_budget_callbacks(alerts)
budget = BudgetManager(tracker, config, callbacks=callbacks)
# Now you get Slack/Discord alerts on budget warnings, critical, and circuit breaksfrom fastapi import FastAPI
from computecfo import CostTracker
from computecfo.api import create_router
app = FastAPI()
tracker = CostTracker()
app.include_router(create_router(tracker), prefix="/api/cost")
# 14 endpoints available:
# GET /api/cost/summary?days=7&project=my-saas
# GET /api/cost/by-module
# GET /api/cost/by-model
# GET /api/cost/by-project
# GET /api/cost/daily-trend
# GET /api/cost/recent
# GET /api/cost/budget
# GET /api/cost/estimate
# GET /api/cost/roi
# GET /api/cost/efficiency
# GET /api/cost/prediction
# GET /api/cost/savings
# GET /api/cost/model-values
# GET /api/cost/anomalies
# GET /api/cost/report| Provider | Models | Auto-Pricing |
|---|---|---|
| Anthropic | Claude Opus 4, Sonnet 4, Haiku 3.5 | โ |
| OpenAI | GPT-4o, GPT-4o-mini, GPT-4.1, o3-mini | โ |
| Gemini 2.5 Pro, Gemini 2.5 Flash | โ | |
| DeepSeek | DeepSeek V3, DeepSeek R1 | โ |
| Custom | Any model โ add your own pricing | โ |
Add custom models:
from computecfo.models import MODEL_PRICING
MODEL_PRICING["my-custom-model"] = {"input": 2.0, "output": 8.0, "provider": "custom"}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ComputeCFO Agent โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Dashboard UI โ โ FastAPI Server โ โ
โ โ (HTML/JS/CSS)โโโโถโ (server.py) โ โ
โ โ Chart.js โ โ 14 REST APIs โ โ
โ โ i18n (ไธญ/EN) โ โโโโโโโโโโฌโโโโโโโโโ โ
โ โ Dark/Light โ โ โ
โ โโโโโโโโโโโโโโโ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Core Engine โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ CostTracker โ track โ โ
โ โ BudgetManagerโ guard โ โ
โ โ CostAnalyzer โ score โ โ
โ โ AlertManager โ alert โ โ
โ โ @track_cost โ auto โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ SQLite โ โ
โ โ ~/.computecfo/ โ โ
โ โ usage.db โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Zero core dependencies โ Python 3.10+ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The standalone dashboard provides a full financial overview with interactive charts.
Features:
- Real-time spending summaries (today / week / month / projected)
- Daily spending trend line chart
- Cost breakdown by model (doughnut chart)
- Project-level P&L with bar chart
- Model value scoring table (Graham-inspired grades A-F)
- Anomaly detection alerts
- Pre-call cost estimator
- Recent activity log
- Budget controls with 3-level protection
- Dark / Light theme toggle
- Chinese / English language switch
- Auto-refresh every 30 seconds
ComputeCFO's core uses only Python standard library + SQLite. No external packages required.
Optional: Install fastapi + uvicorn for the dashboard and API server.
See examples/quickstart.py for a complete walkthrough covering all features.
- AI Chatbot โ Track cost per conversation, optimize model selection
- Content Generation โ Measure cost per output, calculate production ROI
- Code Assistant โ Budget controls for team usage, per-developer tracking
- Research Agent โ Monitor long-running agent costs, prevent runaway spending
- Multi-Model Pipeline โ Compare provider costs, find the cheapest sufficient model
- Multi-Project Organization โ Independent P&L per project, Alphabet-style
Pull requests welcome! Please open an issue first to discuss changes.
MIT โ see LICENSE
Built by @SilentFleetKK