OPEN SOURCE · PYTHON · GO · TYPESCRIPT
--Python--installsTypeScript--installsGo--installs

REAL-TIME
COST ENFORCEMENT
FOR AI AGENTS

Set a hard dollar limit on any AI agent session with one line of code. Automatic tracking, circuit breaking, and cost reports across every LLM provider.

Works with every LLM provider

OpenAI
Anthropic
Google Gemini
Mistral
Cohere
LangChain
CrewAI

Code Examples

A few lines. Full control.

Drop-in auto-tracking, manual wrapping, async agents, and nested budgets.

import agentbudget
import openai

agentbudget.init("$5.00")

# Your existing code. Zero changes needed.
client = openai.OpenAI()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Analyze this market..."}]
)
# ^ Automatically tracked. Budget enforced.

print(agentbudget.spent())       # 0.0035
print(agentbudget.remaining())   # 4.9965
print(agentbudget.report())      # Full cost breakdown

agentbudget.teardown()

The Problem

Agents are unpredictable by design.
Your bill shouldn't be.

Traditional software has deterministic costs. Agent software doesn't. An agent might make 3 LLM calls or 300.

The Loop Problem

Agent gets stuck retrying the same call. 200 LLM calls in 10 minutes. $50–$200 before anyone notices.

The Invisible Spend

Tokens aren’t dollars. GPT-4o costs 15x more than GPT-4o-mini. Mix in tool calls, nobody knows the real cost.

Multi-Provider Chaos

One session calls OpenAI, Anthropic, Google, and 3 APIs. Each has its own billing. No unified real-time view.

The Scaling Problem

1,000 concurrent sessions. 5% failure rate = 50 runaway agents. Your bill becomes your worst case times your user count.

Features

Everything you need. Nothing you don't.

A single library. No infrastructure. Works with your existing code.

Drop-in Auto-Tracking

One line patches OpenAI and Anthropic SDKs. Your existing code stays completely untouched.

Learn more

Dollar-Denominated

Tracks real dollars, not tokens. Across LLM calls, tool calls, and external APIs in one balance.

Learn more

Circuit Breaker

Soft limit warnings, hard limit enforcement, and automatic loop detection kills runaway sessions.

Learn more

Multi-Provider

Built-in pricing for 40+ models across OpenAI, Anthropic, Google, Mistral, and Cohere. OpenRouter supported.

Learn more

Async Native

Full async/await support with AsyncBudgetSession. Works with async agents and concurrent sessions.

Learn more

Nested Budgets

Parent sessions allocate sub-budgets to child agents. Costs roll up to the parent automatically.

Learn more

Framework Integrations

LangChain callback handler, CrewAI middleware. Drop into your existing agent framework.

Learn more

Webhooks

Stream budget events to Slack, Datadog, or your billing system via HTTP webhooks.

Learn more

Zero Infrastructure

No Redis. No servers. No cloud account. Pure Python library that runs in your process.

Learn more

Streaming Support

stream=True calls are fully tracked. Cost recorded after iterator exhaustion — chunks pass through unchanged.

Learn more

Finalization Reserve

Reserve a budget fraction for the final response. Agents finish their last step instead of being cut off mid-task.

Learn more

Live Monitoring

See exactly what your agent spends.

Every LLM call, tool call, and cost event is logged in real time with a structured report.

agentbudget · session_7f3a
14:23:01INFOSession started · budget: $5.00
14:23:02LLMgpt-4o · 847 tokens · cost: $0.0029
14:23:03TOOLserp_api · cost: $0.01
14:23:05LLMgpt-4o · 2,104 tokens · cost: $0.0073
14:23:06COSTRunning total: $0.0202 · remaining: $4.98
14:23:08LLMgpt-4o-mini · 512 tokens · cost: $0.0004
14:24:51WARNSoft limit reached · 90% budget used · $4.52 spent
14:25:12INFOSession ended · total: $4.71 · 23 calls · 14.2s

See it in action

Watch a 6-min video all about AgentBudget

A complete walkthrough — from installation to real-time cost enforcement across your AI agents.

Community

Star History

Watch our growth on GitHub. Star the repo to stay updated.

Star History Chart

Ship your agents with confidence.

Set a budget. Move on.

AGENTBUDGET