Skip to main content

Real-time AI agent cost monitoring and budget alerting for local development

Project description

local-agent-cost-tracker

Real-time cost tracking for AI agents—know exactly what you're spending before the bill arrives.

What is this?

A lightweight desktop application that monitors your AI agent traffic in real-time, calculates token costs across OpenAI, Anthropic, and local models, and alerts you before you exceed your budget. Built to solve the #1 pain point from production agent deployments: "I don't know how much this is costing me until the invoice arrives." Runs entirely offline with zero telemetry, backed by SQLite, and complements observability tools by focusing purely on cost tracking.

Features

  • Real-time cost tracking – Monitor token consumption and costs as they happen
  • Multi-model support – OpenAI, Anthropic, and local LLM pricing built-in
  • Budget alerts – Get notified before you exceed spending thresholds
  • Offline-first – Zero telemetry, no cloud dependencies, runs on your machine
  • SQLite backend – Simple, fast, portable cost history
  • CLI + Server – Command-line tool or HTTP server for integration
  • Docker ready – Includes Dockerfile and docker-compose for easy deployment
  • Zero dependencies on external services – Works with air-gapped deployments

Quick Start

Installation

# Clone and install
git clone <repo-url>
cd local-agent-cost-tracker
pip install -e .

Configuration

Copy .env.example to .env and configure your settings:

cp .env.example .env

Key variables:

  • OPENAI_API_KEY – For OpenAI model pricing (optional)
  • ANTHROPIC_API_KEY – For Anthropic model pricing (optional)
  • BUDGET_LIMIT – Monthly spending cap in USD
  • ALERT_THRESHOLD – Alert when spending reaches X% of budget

Run the Server

# Start the tracking server
python -m local_agent_cost_tracker.server

# Server runs at http://localhost:8000

Command-line Usage

# Track a single API call
local-agent-cost-tracker log --model gpt-4 --tokens 150 --cost 0.0045

# View cost summary
local-agent-cost-tracker summary --period month

# Export cost history
local-agent-cost-tracker export --format csv --output costs.csv

# Check remaining budget
local-agent-cost-tracker budget

Docker

docker-compose up -d

Usage Example

from local_agent_cost_tracker import CostTracker

tracker = CostTracker()

# Log a request
tracker.log_request(
    model="gpt-4",
    input_tokens=120,
    output_tokens=85,
    timestamp="2025-03-29T10:30:00Z"
)

# Get cost summary
summary = tracker.get_summary(period="week")
print(f"Weekly spend: ${summary['total_cost']:.2f}")
print(f"Budget remaining: ${summary['remaining_budget']:.2f}")

# Check if over budget
if tracker.is_over_budget():
    print("⚠️ Budget exceeded!")

Tech Stack

  • Language: Python 3.10+
  • HTTP Server: FastAPI
  • Database: SQLite
  • Pricing Engine: Custom model pricing resolver
  • Token Counting: tiktoken (OpenAI), built-in counters
  • Testing: pytest
  • Deployment: Docker, docker-compose
  • CI/CD: GitHub Actions

License

MIT – See LICENSE for details.


Get started tracking costs in 5 minutes. No signup, no telemetry, no surprises.

Project details


Download files

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

Source Distribution

local_agent_cost_tracker-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

local_agent_cost_tracker-0.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file local_agent_cost_tracker-0.1.0.tar.gz.

File metadata

  • Download URL: local_agent_cost_tracker-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for local_agent_cost_tracker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9778686197bc8741153f25b4fcf49f443b77f6096460d70800bf78b719952e08
MD5 aaa2f0e20ed6e126816204e2dbcc4875
BLAKE2b-256 e7c1fac76f52d86d2b15b2baf2e287c73c55796153631fb3d4470cdb2fa2a6e4

See more details on using hashes here.

File details

Details for the file local_agent_cost_tracker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for local_agent_cost_tracker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d13ac66dee331913eb396729b6b418c6a9a96c0e94e935da1416e5388c47f6f2
MD5 60d3ffb7fff861d13e69ee83f7ab26d5
BLAKE2b-256 45e86022b686eac038f7850e6b5a2be5017d87293d9da5dca9b62d65c9cff559

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