Born from our own $800 OpenAI bill — AgentCost found the runaway agent and cut our spend 44% in two weeks. Read the story
$ pip install agentcostfrom agentcost import track_costsimport openai # Initializetrack_costs.init(api_key="sk_...", project_id="6b3f2e1d-9c4a-4f8e-b2d7-3a5c8e9f0a1b") # Use your LLM as usual — calls are tracked automaticallyclient = openai.OpenAI()response = client.chat.completions.create( model="gpt-4o", messages=[...])Tracks every major provider — 3,500+ models supported
Capabilities
AgentCost answers the three questions a token total cannot — for what already ran, and for what you are about to ship.
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.
search_docs ran 2.4× per run — a loop, not a caching problem
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
Never wrote prose, and the input set is bounded. That is a classifier, not a model.
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
Intercepts OpenAI, Anthropic, Gemini and LangChain. No wrappers, no decorators, no refactor.
Streamed calls are tracked with the same accuracy as blocking ones, sync and async alike.
Agent, workflow and step context ride contextvars, so parallel pipelines never mix their spend.
Monthly budgets with threshold alerts, and detection when an agent's spend leaves its own baseline.
Pricing syncs continuously, so a model released this week is costed correctly this week.
Token counts and timings — never your prompts. Run it locally or self-host the whole stack.
How it works
pip install agentcost
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.
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
No wrappers, no decorators, no middleware. AgentCost uses lightweight interception to instrument OpenAI, Anthropic, Gemini, and LangChain calls transparently. Your code stays clean.
Install the SDK
pip install agentcost
Add two lines
import + init — done
See your costs
Open your dashboard at agentcost.tech
FAQ
Getting Started
Technical
Pricing & License
Weighing up alternatives? Honest side-by-side breakdowns:
Have another question? Read the docs · Open a GitHub issue
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