Skip to main content

Real-time LLM cost tracking and optimization โ€” Rust core with Python API

Project description

๐Ÿ’ฐ CostReporter

See where your LLM money goes. Cut costs by 50%+ without sacrificing quality.

CostReporter is a real-time cost optimizer for Claude Code (and other LLMs) that answers the question every user has:

"Why does Claude cost so much, and what can I do about it?"


Problem

Claude Code users bleed money without seeing it:

โŒ No visibility into what costs tokens
โŒ Don't know if file reads or AI calls waste more
โŒ No way to prevent runaway spending
โŒ Can't compare model costs (Claude 3.5 vs Haiku)
โŒ Repeated prompts cost 10x more than cached ones

CostReporter solves all of it.


Solution

Session starts
    โ†“
CostReporter tracks every operation
    โ†“
Shows: "File reads = 60% of your tokens ($47 today)"
    โ†“
Recommends: "Batch file reads to save $14/day"
    โ†“
You implement โ†’ Saves $420/month

Features

๐Ÿ’ต Real-time Cost Breakdown

Today's spending:
โ”œโ”€ File operations:  $32.40 (60%) โ† EXPENSIVE
โ”œโ”€ AI calls:         $15.20 (28%)
โ”œโ”€ Git operations:    $3.10 (6%)
โ”œโ”€ Tool execution:    $1.50 (3%)
โ””โ”€ Database queries:  $0.80 (1%)

๐Ÿ’ก Tip: Batch file reads to save ~$14/day

๐Ÿšจ Spending Limits & Alerts

beacon = CostGuardian()
beacon.set_daily_limit(50)  # Stop if daily spend > $50
beacon.set_operation_limit("file_read", 20)  # Warn if file ops > $20

# Claude Code now warns:
"โš ๏ธ File operations at $22. Approach your $20 limit."

๐ŸŽฏ Model Selector

Task: Read config file + check syntax
Recommended: Claude Haiku ($0.08) โœ…
Claude 3.5: $0.45
Savings: $0.37 per task ร— 20/day = $7.40/day saved

๐Ÿ”„ Prompt Caching Detector

Detected repeated prompts:
โ”œโ”€ "Analyze this file" (seen 12 times)
โ”œโ”€ "Check git status" (seen 18 times)
โ””โ”€ "Suggest fixes" (seen 8 times)

๐Ÿ’ก Use prompt caching to reduce cost by 90%
Potential savings: $4.20/day

๐Ÿ“Š Cost Trends & Insights

Weekly spending:
โ”œโ”€ Mon: $52.30 โ†‘ (5% increase)
โ”œโ”€ Tue: $49.10
โ”œโ”€ Wed: $48.50 โ†“ (1% improvement)
โ”œโ”€ Thu: $51.20
โ””โ”€ Fri: $53.10 โ†‘ (4% increase)

Insight: Friday spending 8% higher. Pattern matches large refactoring tasks.

Quick Start

Install

pip install cost-reporter

# Or from source
git clone https://github.com/Mullassery/CostReporter.git
cd CostReporter
make install

Usage

from cost_guardian import CostGuardian

guardian = CostGuardian()

# Set spending limits
guardian.set_daily_limit(100)          # Stop at $100/day
guardian.set_operation_limit("file_read", 30)  # Warn at $30 for reads

# Get today's breakdown
breakdown = guardian.get_cost_breakdown()
print(breakdown)
# {"file_read": 32.40, "ai_call": 15.20, "total": 47.60}

# Get recommendations
recs = guardian.get_recommendations()
# [
#   {"issue": "File reads too high", "savings": "$14/day", "action": "Batch requests"},
#   {"issue": "Repeated prompt detected", "savings": "$4.20/day", "action": "Use prompt caching"},
# ]

# Project cost vs budget
status = guardian.get_budget_status()
# {"spent": $47.60, "limit": $100, "remaining": $52.40, "status": "healthy"}

Why CostReporter Wins

Feature Existing Tools CostReporter
Cost tracking โœ“ (fragmented) โœ“ Unified
Spending limits โœ— โœ“ Hard stops
Model recommendations โœ— โœ“ ROI calculated
Prompt caching detection โœ— โœ“ 90% savings
Cost trends โœ— โœ“ Weekly insights
Real-time alerts Partial โœ“ Instant
Easy setup โœ— โœ“ Zero config

Expected Savings

Based on typical Claude Code usage patterns:

User Type Current/Month With Guardian Savings
Solo developer $120 $60 50%
Team of 5 $800 $350 56%
Enterprise (50+) $12,000 $4,500 62%

Typical savings: 50-60% through model selection + prompt caching + operation batching


Architecture

Rust Core (High-performance cost tracking)

  • Real-time token accounting
  • Model pricing database
  • Caching pattern detection
  • Cost trend analysis

Python Wrapper (Easy integration)

  • Simple API for spending limits
  • CLI for dashboards
  • Integration with pandas/databases
  • Webhook alerts

Roadmap

Phase 1 (MVP) โ€” Cost Visibility

  • โœ… Real-time cost tracking
  • โœ… Daily/weekly breakdowns
  • โœ… Operation-level cost attribution
  • โœ… Basic spending limits

Phase 2 โ€” Intelligence

  • Model selector (choose cheapest for task)
  • Prompt caching detector
  • Batch operation recommendations
  • Cost trend analysis

Phase 3 โ€” Automation

  • Auto-select models based on budget
  • Auto-batch operations
  • Spending alerts + Slack integration
  • Team dashboards

Phase 4 โ€” Enterprise

  • Multi-org cost centers
  • Chargeback + billing
  • Compliance reporting
  • Budget forecasting

Requirements

  • Python 3.9+
  • Rust 1.70+ (source builds only)
  • ~5MB disk space

License

MIT โ€” See LICENSE


Community

  • ๐Ÿ’ฌ Discuss on r/ClaudeCode
  • ๐Ÿ› Report issues on GitHub
  • ๐Ÿ’ก Share cost-saving tips with the community

Save money. Build faster. Together. ๐Ÿ’š

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycost_reporter-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file pycost_reporter-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycost_reporter-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5908a29da1ec11ffa2314d867e082e2bddfd144167c66d60028e4711275712df
MD5 3fd2b0c4c0fa7a28d6823f36993a5663
BLAKE2b-256 edf8439a4ab864d224c77f373c7b8333a2e55fb2ea27820da25e73c74b1f8773

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page