See exactly what your agent run costs. One function. Zero deps.
agent-bill tracks LLM token costs across any multi-model agent run and produces an itemized receipt — per-call breakdown, model percentages, and optional budget warnings.
Zero runtime dependencies. Bundled pricing for 35+ models across OpenAI, Anthropic, Google, Mistral, Meta, DeepSeek, and Cohere.
Before agent-bill:
Your agent made 10 LLM calls.
Total cost: ???
After agent-bill:
==============================================================
AGENT BILL — Itemized Cost Receipt
==============================================================
Step Model In Tok Out Tok Cost
----------------------------------------------------------
1 gpt-4o 2,100 800 $0.0133 (plan task)
2 gpt-4o 1,800 600 $0.0105 (search query)
3 claude-sonnet-4 3,200 1,200 $0.0276 (analyze doc 1)
4 claude-sonnet-4 2,900 1,100 $0.0252 (analyze doc 2)
5 claude-sonnet-4 3,500 1,500 $0.0330 (analyze doc 3)
6 gpt-4o-mini 800 200 $0.0002 (summarize)
7 gpt-4o 2,400 900 $0.0150 (draft report)
8 claude-sonnet-4 4,000 2,000 $0.0420 (review report)
9 gpt-4o-mini 600 150 $0.0002 (format output)
10 gpt-4o 1,500 500 $0.0088 (final check)
Model Breakdown:
claude-sonnet-4 4 calls $0.1278 ( 72.3%) ##############
gpt-4o 4 calls $0.0475 ( 26.9%) #####
gpt-4o-mini 2 calls $0.0003 ( 0.2%) #
Total calls: 10
Total tokens: 27,750
TOTAL COST: $0.1756
Budget: $5.00 [OK]
pip install -e .
python -m agent_bill demofrom agent_bill import Bill
bill = Bill(budget_usd=5.00) # optional budget
# Record each LLM call with token counts
bill.record("gpt-4o", input_tokens=1200, output_tokens=400)
bill.record("claude-sonnet-4", input_tokens=2000, output_tokens=800, label="analyze")
# Print the itemized receipt
print(bill.receipt_text())
# Or access structured data
receipt = bill.receipt()
print(receipt.total_cost_usd) # 0.0270
print(receipt.by_model) # per-model breakdown
print(receipt.budget_exceeded) # FalseIf the model name is unknown, use cost_override:
bill.record("my-custom-model", input_tokens=500, output_tokens=200, cost_override=0.05)Set a budget to get warnings when spend exceeds the limit:
import warnings
from agent_bill import Bill, BudgetWarning
bill = Bill(budget_usd=1.00)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
bill.record("gpt-4o", input_tokens=50000, output_tokens=20000)
if w and issubclass(w[-1].category, BudgetWarning):
print("Budget exceeded — stop the agent")python -m agent_bill demo # Run the built-in demo
python -m agent_bill prices # List all bundled model prices35+ models with bundled pricing: GPT-4o, GPT-4o-mini, GPT-4, o1, o3, Claude Opus 4, Claude Sonnet 4, Claude Haiku 3.5, Gemini 2.0, Llama 3.3, Mistral Large, DeepSeek V3/R1, Command R+, and more. Model name aliases are resolved automatically.
- Python 3.11+
- Zero runtime dependencies
agent-bill is part of a suite of zero-dependency Python tools for the AI agent era:
| Tool | What it does |
|---|---|
| ghostlines | Find code your team merged but never understood |
| agent-circuit | Circuit breaker for agent tool calls |
| agent-guard | Block prompt injection and path traversal at the tool boundary |
| crowdllm | Multi-model voting for better answers |
| vcr-llm | Record and replay LLM conversations for testing |
| singleflight-agents | Deduplicate parallel agent tool calls |
MIT