Skip to main content

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.

Release files for local-agent-cost-tracker 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for local-agent-cost-tracker 0.1.0
File Size Uploaded
local_agent_cost_tracker-0.1.0.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for local-agent-cost-tracker 0.1.0
File Interpreter ABI Platform
local_agent_cost_tracker-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / local_agent_cost_tracker-0.1.0.tar.gz

Download URL local_agent_cost_tracker-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9778686197bc8741153f25b4fcf49f443b77f6096460d70800bf78b719952e08
BLAKE2b-256 checksum
How to use checksums
e7c1fac76f52d86d2b15b2baf2e287c73c55796153631fb3d4470cdb2fa2a6e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / local_agent_cost_tracker-0.1.0-py3-none-any.whl

Download URL local_agent_cost_tracker-0.1.0-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d13ac66dee331913eb396729b6b418c6a9a96c0e94e935da1416e5388c47f6f2
BLAKE2b-256 checksum
How to use checksums
45e86022b686eac038f7850e6b5a2be5017d87293d9da5dca9b62d65c9cff559
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page