Catalog PyPI
PACKAGE EXPLORERView in registry

agentcostin

PyPI

AI Agent Cost Governance — track, control, and optimize LLM spending

agentaianthropiccostgovernancellmobservabilityopenaitracking
Versions collected1
Direct dependencies24From release 1.0.0
Last observed20 Oct, 21:44 UTC

README

Version 1.0.0 documentation

🧮 AgentCost

Track, control, and optimize your AI spending.

PyPI npm CI License Discord


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:

ViewWhat it shows
OverviewTotal spend, call volume, error rate, cost-over-time charts
Cost BreakdownSpend by model, project, and provider with trend analysis
ForecastingPredicted costs for next 7/14/30 days, budget exhaustion alerts
OptimizerModel downgrade recommendations with estimated savings
AnalyticsToken efficiency, top spenders, chargeback reports
EstimatorPre-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:

FeatureDescription
SSO/SAMLKeycloak integration, OIDC + SAML 2.0
OrganizationsMulti-tenant team management with roles
Budget EnforcementCost centers, allocations, pre-call validation
Policy EngineJSON rules: block models, cap costs, require approval
Approval WorkflowsHuman-in-the-loop for policy exceptions
NotificationsSlack, email, webhook, PagerDuty alerts
Agent ScorecardsMonthly agent grading (A–F) with recommendations
Audit LogHash-chained compliance trail
Anomaly DetectionML-based cost/latency spike detection
AI GatewayTransparent LLM proxy with policy enforcement

Enterprise features are source-available under BSL 1.1. See enterprise/LICENSE.

→ Contact us or read the docs

Configuration

VariableDefaultDescription
AGENTCOST_PORT8500Server port
AGENTCOST_EDITIONautocommunity, enterprise, or auto
AGENTCOST_AUTH_ENABLEDfalseEnable SSO (enterprise)
AGENTCOST_DB_URLSQLitePostgreSQL 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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.01 Mar 202624

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
agentcostin/agentcost

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:65fb0c657a0542115589838329f556a84a44586c01c559250d4c686301ed1985