Launching AgentCost

Published: (February 14, 2026 at 11:56 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

The Problem

Last month, my LangChain agent cost me $800 in OpenAI fees.
I had no idea which agent was expensive or where to optimize — I was flying blind.

The Solution

I built AgentCost, an open‑source tool that tracks every LLM call your agents make.

AgentCost screenshot

How It Works

AgentCost works by intercepting LangChain’s LLM calls using Python’s monkey‑patching.

Architecture

Three components:

  • Python SDK – intercepts calls
  • FastAPI backend – stores data
  • React dashboard – visualizes costs

Results

After using AgentCost for 2 weeks:

  • Identified that my Router Agent was called 10× more than needed
  • Switched simple queries to GPT‑3.5 instead of GPT‑4
  • Reduced costs from $800/month to $450/month (44 % savings)

Technical Challenges

Monkey patching without breaking user code

How I solved:

Accurate token counting

The challenge: Different models use different tokenizers…

Batching for performance

The solution: Hybrid batching (size + time‑based)…

Try It Yourself

AgentCost is open source and free to use:

  • GitHub:
  • Docs:
pip install agentcost

What’s Next

  • Cost alerts (Slack/email when a threshold is hit)
  • Automatic optimization suggestions
  • OpenAI and Anthropic SDK support

Feedback Welcome

If you try AgentCost, I’d love to hear your thoughts!

0 views
Back to Blog

Related posts

Read more »