Skip to main content

See what your AI really costs. Zero code changes.

Project description

spent

See what your AI really costs. Zero code changes.

PyPI Python License Stars


You're spending hundreds on LLM APIs every month. Do you know which calls cost what?

spent tracks every token, every model, every dollar -- automatically. One command. No code changes. Beautiful reports.

$ spent run python app.py

 ┌──────────────────────────────────────────┐
 │  spent                    session a1b2c3 │
 │                                          │
 │  Total Cost:    $4.2731                  │
 │  Tokens:        125,430  (98k in / 27k out)
 │  API Calls:     47                       │
 │  Duration:      2m 34s                   │
 └──────────────────────────────────────────┘

  Model                   Calls  Tokens     Cost     Share
  gpt-4o                  12     84,200     $3.8100  ████████░░ 89%
  gpt-4o-mini             31     38,100     $0.4200  █░░░░░░░░░ 10%
  claude-sonnet-4-6        4      3,130     $0.0431  ░░░░░░░░░░  1%

  Savings Opportunities: ~$2.1000
    gpt-4o -> gpt-4o-mini: save $2.10 (55%) on 12 calls

Quick Start

pip install spent

Option 1: Zero code changes (recommended)

Just prefix your command:

spent run python app.py
spent run python -m pytest
spent run --budget 5.00 python train.py

Option 2: One line of code

from spent import track
from openai import OpenAI

client = track(OpenAI())

# Use normally -- costs tracked automatically
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
# Exit summary printed automatically

Works with Anthropic too:

from spent import track
from anthropic import Anthropic

client = track(Anthropic())

Features

Feature Status
OpenAI cost tracking Done
Anthropic cost tracking Done
Beautiful terminal dashboard Done
Per-model cost breakdown Done
Savings recommendations Done
Budget alerts Done
Session history Done
JSON/CSV export Done
Google AI tracking Roadmap
Auto model routing Roadmap
Team cost sharing Roadmap
CI/CD cost reports Roadmap

Commands

# Track costs (zero code changes)
spent run python app.py

# Set a budget alert
spent run --budget 10.00 python app.py

# Live dashboard (watches costs in real-time)
spent dashboard

# View cost reports
spent report              # Recent sessions
spent report --today      # Today's costs
spent report --json       # Machine-readable
spent report --csv        # Spreadsheet-ready

# Clear all data
spent reset

How It Works

spent transparently patches the OpenAI and Anthropic Python SDKs at import time. When your code calls client.chat.completions.create(...), spent:

  1. Intercepts the call (before and after)
  2. Extracts token usage from the response
  3. Calculates cost using up-to-date pricing
  4. Stores the record in a local SQLite database
  5. Returns the original response unchanged

Your code runs exactly the same. No API proxies. No network changes. No latency added to API calls themselves.

Data stays on your machine at ~/.spent/data.db.

Supported Models

40+ models with up-to-date pricing:

Provider Models
OpenAI GPT-4o, GPT-4o-mini, GPT-4-Turbo, GPT-4, GPT-3.5-Turbo, o1, o3, o3-mini, o4-mini
Anthropic Claude Opus 4, Claude Sonnet 4, Claude Haiku 4, Claude 3.5/3 family
Google Gemini 2.5 Pro/Flash, 2.0 Flash, 1.5 Pro/Flash
DeepSeek DeepSeek Chat, DeepSeek Reasoner
Mistral Mistral Large, Mistral Small, Codestral
Groq Llama 3.3 70B, Llama 3.1 8B, Mixtral 8x7B

Unknown models are tracked with $0 cost (tokens still recorded).

Budget Alerts

Set a budget and get warned when you exceed it:

# CLI
spent run --budget 5.00 python app.py

# Python
from spent import track, configure
configure(budget=5.00)
client = track(OpenAI())

When the budget is exceeded:

[spent] BUDGET ALERT: $5.0231 spent (budget: $5.00)

Why spent?

spent Manual tracking LLM framework built-in
Code changes needed 0 Lots Framework-specific
Works across providers Yes Manual per-provider Usually one provider
Historical data SQLite Spreadsheets In-memory only
Savings recommendations Automatic You do the math No
Export formats JSON, CSV Copy-paste Varies
Privacy 100% local Depends Often cloud

Roadmap

  • Google AI / Vertex tracking -- Gemini model support
  • Auto model routing -- automatically use cheaper models for simple tasks
  • Team dashboards -- aggregate costs across team members
  • CI/CD integration -- cost reports in GitHub Actions / PR comments
  • Ollama / local model tracking -- track local inference costs (compute time)
  • Web dashboard -- browser-based cost explorer
  • Slack / Discord alerts -- budget notifications in team channels
  • Cost anomaly detection -- alert on unusual spending patterns

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

git clone https://github.com/loplop-h/spent.git
cd spent
pip install -e ".[dev]"
pytest

License

MIT

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

spent-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

spent-0.1.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f724821699692243b44ca1ad90f60876839211f6e456fa270c134c7d7a528132
MD5 957cb06f39819089cefa3344f92cd011
BLAKE2b-256 0d03029873c00d9a55335024d5bd3a98c895fd9075416162d25547448b8c119c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for spent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 732da0181f17a269b8d97ceef557d3261201ddd0b9c80dca046a400f515fbad4
MD5 82e428c3730194713505fabf7f54f06e
BLAKE2b-256 54b3853fc06d8114cb4a94d3c08800d8710e3e05938e1e5e54254e5aca340227

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