Your AI bill spiked. Which agent did it?

AgentCost traces every LLM call back to the agent that made it — OpenAI, Anthropic, Gemini, LangChain, 3,500+ models. Two lines of Python. Free hosted cloud — or self-host the MIT code.

Born from our own $800 OpenAI bill — AgentCost found the runaway agent and cut our spend 44% in two weeks. Read the story

Quick Start
1. Install
$ pip install agentcost
2. Add two lines to your code
from agentcost import track_costs
import openai
 
# Initialize
track_costs.init(api_key="sk_...", project_id="6b3f2e1d-9c4a-4f8e-b2d7-3a5c8e9f0a1b")
 
# Use your LLM as usual — calls are tracked automatically
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[...]
)
3. Watch the dashboard
$3,412/mo tracked$1,532/mo savings foundsee it live in the demo — no signup

Tracks every major provider — 3,500+ models supported

OpenAI
Anthropic
Google
Mistral
DeepSeek
Groq
Cohere
Together AI
AWS Bedrock
Azure OpenAI
Perplexity
Replicate
Fireworks AI
Meta Llama
OpenAI
Anthropic
Google
Mistral
DeepSeek
Groq
Cohere
Together AI
AWS Bedrock
Azure OpenAI
Perplexity
Replicate
Fireworks AI
Meta Llama

Capabilities

Your invoice says what you spent.
It never says what you spent it on.

AgentCost answers the three questions a token total cannot — for what already ran, and for what you are about to ship.

01

What did one run actually cost?

Your bill shows tokens. It cannot tell you whether $0.04 was a three-step pipeline or one step retried twice. Wrap a run and AgentCost reports cost per run, per step and per tool — and flags the same call being made twice inside one run, which is a loop rather than something a cache would fix.

support-triage$0.0338 / run
classify
$0.0008
search_docs
$0.0209
draft_reply
$0.0121

search_docs ran 2.4× per run — a loop, not a caching problem

02

Which of these calls needed a model at all?

An agent whose replies are always a few tokens long, over inputs that keep repeating, is doing classification — work a smaller model or a lookup does for a fraction of the price. AgentCost finds those workloads from token counts alone, without ever reading a prompt.

sentiment-classifier

165,000 calls to gpt-4o

-$135/mo
Longest reply
14 tokens
Inputs repeating
63%

Never wrote prose, and the input set is bounded. That is a classifier, not a model.

03

What will the next version cost?

Run one command before you deploy. It prices the prompt and skill files your agent sends on every call, projects a local test run to production volume, and fails your CI on a cost regression. It runs entirely on your machine and transmits nothing.

$ agentcost analyze ./agent --runs-per-day 2000

3 runs · 4.0 calls/run · $0.044 per run

Projected: $2,640.00 / month

[high] step ‘search_docs’ ran 2.0× per run

[high] 3 of 3 runs repeated an identical call

Two lines, four SDKs

Intercepts OpenAI, Anthropic, Gemini and LangChain. No wrappers, no decorators, no refactor.

Streaming included

Streamed calls are tracked with the same accuracy as blocking ones, sync and async alike.

Concurrency-safe attribution

Agent, workflow and step context ride contextvars, so parallel pipelines never mix their spend.

Budgets and anomalies

Monthly budgets with threshold alerts, and detection when an agent's spend leaves its own baseline.

3,500+ models priced

Pricing syncs continuously, so a model released this week is costed correctly this week.

Metadata only, MIT licensed

Token counts and timings — never your prompts. Run it locally or self-host the whole stack.

How it works

From call to insight
in four steps.

pip install agentcost

Install the SDK

A lightweight Python package. Add the import and call init() with your API key. Your existing LangChain code continues to work unchanged — the SDK intercepts calls transparently via monkey-patching.

No wrappers, no decorators, no middleware.

step-01.sh
from agentcost import track_costs

track_costs.init(
    api_key="sk_...",
    project_id="6b3f2e1d-9c4a-4f8e-b2d7-3a5c8e9f0a1b",
)

# That's it. Your code stays the same.

Integration

Two lines. That's it.

No wrappers, no decorators, no middleware. AgentCost uses lightweight interception to instrument OpenAI, Anthropic, Gemini, and LangChain calls transparently. Your code stays clean.

01

Install the SDK

pip install agentcost

02

Add two lines

import + init — done

03

See your costs

Open your dashboard at agentcost.tech

my_agent.py
from agentcost import track_costs
 
# Settings → your project → copy UUID + API key
track_costs.init(api_key="sk_...", project_id="6b3f2e1d-9c4a-4f8e-b2d7-3a5c8e9f0a1b")
 
# Your existing code works unchanged
from langchain_openai import ChatOpenAI
 
llm = ChatOpenAI(model="gpt-4o")
response = llm.invoke("Analyze this data...")
# ↑ Automatically tracked: tokens, cost, latency
0+models trackedOpenAI · Anthropic · Google · Mistral · and 50+ providers
~0msblocking overheadEvents are batched and sent asynchronously — tracking never blocks your calls
0%open source (MIT)Free hosted cloud — or self-host the same stack with Docker. No lock-in.

FAQ

Frequently asked questions

Getting Started

Technical

Pricing & License

Weighing up alternatives? Honest side-by-side breakdowns:

Have another question? Read the docs · Open a GitHub issue

Stop guessing.
Start tracking.

Set up in under two minutes. Free cloud — or self-host. No credit card, no vendor lock-in.

MIT License · Free cloud or Docker self-host · No lock-in