AI Agent Cost Governance โ track, control, and optimize LLM spending
Project description
๐งฎ AgentCost
Track, control, and optimize your AI spending.
AI costs are invisible, unpredictable, and uncontrolled. Teams deploy agents across OpenAI, Anthropic, Google, and open-source models with no idea what they're actually spending โ or whether cheaper models would work just as well. AgentCost fixes that.
Quickstart
pip install agentcostin
from agentcost.sdk import trace
from openai import OpenAI
client = trace(OpenAI(), project="my-app")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
# Every call is now tracked. Open the dashboard:
# agentcost dashboard
# โ http://localhost:8500
That's it. One line wraps your client, and every LLM call is tracked with model, tokens, cost, latency, and status.
Dashboard
# Seed demo data and launch
curl -X POST http://localhost:8500/api/seed -H "Content-Type: application/json" -d '{"days": 14}'
agentcost dashboard
The dashboard gives you six intelligence views:
| View | What it shows |
|---|---|
| Overview | Total spend, call volume, error rate, cost-over-time charts |
| Cost Breakdown | Spend by model, project, and provider with trend analysis |
| Forecasting | Predicted costs for next 7/14/30 days, budget exhaustion alerts |
| Optimizer | Model downgrade recommendations with estimated savings |
| Analytics | Token efficiency, top spenders, chargeback reports |
| Estimator | Pre-call cost estimation โ compare 42 models before you call |
Framework Support
AgentCost integrates with the frameworks you already use:
# LangChain
from agentcost.sdk.integrations import langchain_callback
chain.invoke(input, config={"callbacks": [langchain_callback("my-project")]})
# CrewAI
from agentcost.sdk.integrations import crewai_callback
crew = Crew(agents=[...], callbacks=[crewai_callback("my-project")])
# AutoGen
from agentcost.sdk.integrations import autogen_callback
agent = AssistantAgent("assistant", llm_config={..., "callbacks": [autogen_callback("my-project")]})
# LlamaIndex
from agentcost.sdk.integrations import llamaindex_callback
service_context = ServiceContext.from_defaults(callback_manager=llamaindex_callback("my-project"))
CLI
# Benchmark models on real professional tasks
agentcost benchmark --model gpt-4o --tasks 10
# Compare models head-to-head
agentcost compare --models "gpt-4o,gpt-4o-mini,claude-sonnet-4-6" --tasks 5
# View the leaderboard
agentcost leaderboard
# Check traces and budgets
agentcost traces --project my-app --summary
agentcost budget --project my-app --daily 50 --monthly 1000
# Manage plugins
agentcost plugin list
agentcost plugin install agentcost-slack-alerts
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application โ
โโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโผโโโ โโโโโโโผโโโ โโโโโโผโโโโ
โ Python โ โ Node.jsโ โ Proxy โ
โ SDK โ โ SDK โ โGateway โ
โโโโโฌโโโโโ โโโโโฌโโโโโ โโโโโฌโโโโโ
โ โ โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
โ AgentCost API Server โ
โ (FastAPI) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Traces โ Forecasts โ Optim โ
โ Budget โ Analytics โ Estim โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SQLite / PostgreSQL โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโผโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ
โ Dashboard โ โ OTel / โ โ Prometheus โ
โ (React) โ โ Grafana โ โ /metrics โ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Exporters
Send cost data to your existing observability stack:
# OpenTelemetry (Datadog, Jaeger, Grafana Tempo)
from agentcost.otel import install_otel_exporter
install_otel_exporter(endpoint="http://localhost:4317")
# Prometheus (Grafana, AlertManager)
# Enabled automatically at /metrics when server is running
Plugin System
Extend AgentCost with plugins:
# Install community plugins
agentcost plugin install agentcost-slack-alerts
agentcost plugin install agentcost-s3-archive
# Create your own plugin
agentcost plugin create my-plugin
Plugins can export data, add alerting, create custom views, and more. See the Plugin Development Guide.
TypeScript SDK
npm install @agentcost/sdk
import { AgentCost } from "@agentcost/sdk";
const ac = new AgentCost({ project: "my-app", apiUrl: "http://localhost:8500" });
// Trace any LLM call
const traced = await ac.trace({
model: "gpt-4o",
inputTokens: 150,
outputTokens: 80,
cost: 0.0035,
latencyMs: 450,
});
Self-Hosting
Community Edition (Quick Start)
git clone https://github.com/agentcostin/agentcost.git
cd agentcost
docker compose -f docker-compose.dev.yml up
# โ http://localhost:8100
Enterprise Edition
# Full stack: PostgreSQL + Keycloak SSO + API
docker compose up -d
# Configure SSO
export AGENTCOST_EDITION=enterprise
export AGENTCOST_AUTH_ENABLED=true
export KEYCLOAK_URL=http://localhost:8180
Enterprise Features
For teams and organizations that need governance:
| Feature | Description |
|---|---|
| SSO/SAML | Keycloak integration, OIDC + SAML 2.0 |
| Organizations | Multi-tenant team management with roles |
| Budget Enforcement | Cost centers, allocations, pre-call validation |
| Policy Engine | JSON rules: block models, cap costs, require approval |
| Approval Workflows | Human-in-the-loop for policy exceptions |
| Notifications | Slack, email, webhook, PagerDuty alerts |
| Agent Scorecards | Monthly agent grading (AโF) with recommendations |
| Audit Log | Hash-chained compliance trail |
| Anomaly Detection | ML-based cost/latency spike detection |
| AI Gateway | Transparent LLM proxy with policy enforcement |
Enterprise features are source-available under BSL 1.1. See enterprise/LICENSE.
โ Contact us or read the docs
Configuration
| Variable | Default | Description |
|---|---|---|
AGENTCOST_PORT |
8500 |
Server port |
AGENTCOST_EDITION |
auto |
community, enterprise, or auto |
AGENTCOST_AUTH_ENABLED |
false |
Enable SSO (enterprise) |
AGENTCOST_DB_URL |
SQLite | PostgreSQL connection string |
KEYCLOAK_URL |
โ | Keycloak server URL |
Contributing
We welcome contributions! See CONTRIBUTING.md for setup instructions.
git clone https://github.com/agentcostin/agentcost.git
cd agentcost
pip install -e ".[dev,server]"
pytest tests/ -v
License
- Core (agentcost SDK, dashboard, CLI, forecasting, optimizer, analytics, estimator, plugins): MIT
- Enterprise (auth, org, budgets, policies, notifications, anomaly, gateway): BSL 1.1 โ converts to Apache 2.0 after 3 years
Documentation ยท Issues ยท Discord ยท Twitter
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentcostin-1.0.0.tar.gz.
File metadata
- Download URL: agentcostin-1.0.0.tar.gz
- Upload date:
- Size: 169.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
598471a9725f60b6e0b20c5ebbc240090cad1e140a65611e076869bb89e464fc
|
|
| MD5 |
ad3635e283ccea2e8961668c569e33f5
|
|
| BLAKE2b-256 |
bbe1dc45dffd7d96e543fa295e85fc64e290aa3fa4bf2e01f7ada5a5f2d9b696
|
File details
Details for the file agentcostin-1.0.0-py3-none-any.whl.
File metadata
- Download URL: agentcostin-1.0.0-py3-none-any.whl
- Upload date:
- Size: 181.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d8f7c82d31fab96a3370468e59209e9afa096ac33cda53886c1b569f5f3315b
|
|
| MD5 |
0f5e454f09d7448494c5504a69fc6a9c
|
|
| BLAKE2b-256 |
78f217897cc39144bc8f930ae2977aef55e17f7b3f45b0933a861f894467ec2e
|