Know what your AI agents actually cost. Track LLM tokens, tool API calls, and compute costs.
Project description
agentcost
Know what your AI agents actually cost. Track LLM tokens, tool API calls, and compute costs — per agent, per task, per tool.
Get Started (3 commands)
pip install agentcost
agentcost login
agentcost run my_agent.py
That's it. Every OpenAI and Anthropic call inside your script is automatically tracked — zero code changes needed.
How It Works
agentcost run wraps your script, detects installed LLM libraries, and captures token usage from every API response. Events are sent to your dashboard in the background. No slowdown, no side effects.
Setup
1. Install
pip install agentcost
2. Login (one time)
agentcost login
Stores your API key securely in ~/.config/agentcost/. Get your key from agentmeter.com.
3. Run
agentcost run my_agent.py
Works with any Python script that uses OpenAI or Anthropic SDKs.
CLI Commands
agentcost login # Save your API key (one-time setup)
agentcost run app.py # Track a script automatically
agentcost status # Check login status and connection
agentcost summary # View cost summary in terminal
agentcost agents # List all tracked agents
agentcost logout # Remove stored credentials
Alternative: Python API
For more control, use the Python API directly:
import agentcost
# Auto-patch all LLM calls (after login, no key needed)
agentcost.init(agent_id="my-agent")
# Or with explicit key
agentcost.init(api_key="ac_xxxxx", agent_id="my-agent")
Track tool costs
from agentcost import AgentCost
ac = AgentCost()
@ac.track_tool(name="stripe_api", cost_per_call=0.02)
def charge_customer(amount):
return stripe.charges.create(amount=amount)
Group calls into runs
with ac.track_run("support-agent", task="process_refund") as run:
run.record("stripe_api", cost=0.02)
run.record_llm("gpt-4o", tokens_in=500, tokens_out=200)
print(f"Run cost: ${run.total_cost:.4f}")
Custom Pricing
ac = AgentCost(
pricing_overrides={
"my_custom_api": 0.05,
"my-fine-tuned-model": {"input": 5.00, "output": 15.00},
}
)
Supported Providers
- OpenAI — gpt-4o, gpt-4o-mini, gpt-4-turbo, o1, o1-mini, and more
- Anthropic — Claude Opus, Sonnet, Haiku (all versions)
- 30+ tool APIs — Stripe, Salesforce, SendGrid, Twilio, etc.
Ships with built-in pricing for all models. Override any price with pricing_overrides.
Dashboard
View cost dashboards, set budgets, and get alerts at agentmeter.com.
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 agentmetering-0.1.0.tar.gz.
File metadata
- Download URL: agentmetering-0.1.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f21ed4eaebf4fc068b0e5b97adaa35df3151b9aa912659a9251be7351e7b70e
|
|
| MD5 |
fd526be068db32501e1635d4b26d07a8
|
|
| BLAKE2b-256 |
5163f5212af823eeb1b5191ff9626e5c163ecbdac31d5708d9a2b9e59a00326c
|
File details
Details for the file agentmetering-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentmetering-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80b69d795821521cb22121332e250ca6aa8968d598b0b9ede8a6d5c77bbe9c97
|
|
| MD5 |
e75f7a9028bd688457527a47cc289335
|
|
| BLAKE2b-256 |
aec4ec0059bca4ea42f142fc357e35cb4505eef374d8992f25e10fa2d4984301
|