Skip to main content

Know where your AI money goes. Track LLM API costs per feature, per model, per user.

Project description

LLMSpend

Know where your AI money goes.

Track LLM API costs per feature, per model, per user. 2 lines of code. Zero config.

Install

pip install llmspend

Quick Start

import anthropic
from llmspend import monitor

# Wrap your client — that's it
client = monitor.wrap(anthropic.Anthropic(), project="my-app")

# Use it exactly as before
response = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=500,
    messages=[{"role": "user", "content": "Hello"}]
)
# Cost, tokens, and latency are now tracked automatically

Tag by Feature

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1000,
    messages=[{"role": "user", "content": query}],
    llmspend={"feature": "chatbot", "user_id": "u_123"}
)

View Your Costs

# Last 24 hours, grouped by model
llmspend stats

# Last 7 days, grouped by feature
llmspend stats --last 7d --by feature

# Most expensive calls
llmspend top

# Export as JSON
llmspend export
  LLMSpend — Last 7d
  ──────────────────────────────────────────────────
  Total: $12.4320 across 2,847 calls

  Group                      Calls       Cost    Avg ms
  ───────────────────────── ────── ────────── ────────
  claude-sonnet-4-6            312   $8.9400     1240ms
  claude-haiku-4-5             1893   $2.1200      430ms
  gpt-4o-mini                  642   $1.3720      380ms

Works with OpenAI too

import openai
from llmspend import monitor

client = monitor.wrap(openai.OpenAI(), project="my-app")
# All chat.completions.create calls are now tracked

What Gets Tracked

Per API call:

  • Provider, model, timestamp
  • Input/output tokens
  • Cost in USD
  • Latency in ms
  • Your custom tags (feature, user_id)

What is never tracked:

  • Prompt content
  • Response content
  • API keys

Self-Hosted Dashboard

Coming soon — React dashboard for visualizing costs locally.

Hosted Version

Coming soon at llmspend.dev — team dashboards, alerts, cost forecasting.

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

llmspend-0.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

llmspend-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for llmspend-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aeea5f67d3e9699eb6d8c4b0e8b08c7a92ddb851e59284af485a7695b2b9c82e
MD5 464755b821465a3c3c899aab029acfec
BLAKE2b-256 abe56fe59f4434cf07e268ccd72546b5ed063a956cb6c88b0fa8b71ff4c93344

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for llmspend-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0c169a198263458a3414ff76754cef8685ce1d5269c07923e3db7e73a6ab25e
MD5 2f62734580685ffdad468f494ed448b3
BLAKE2b-256 f18b6a25004a344801064cd4b70eb8678a85568ba449cf10b9cf15422131ef41

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