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.
Metadata
Release files for agentmetering 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agentmetering-0.1.0.tar.gz | 19.6 kB | Without provenance | Details for agentmetering-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentmetering-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for agentmetering-0.1.0-py3-none-any.whl |
Total release size: 39.7 kB
Release files / agentmetering-0.1.0.tar.gz
| Download URL | agentmetering-0.1.0.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f21ed4eaebf4fc068b0e5b97adaa35df3151b9aa912659a9251be7351e7b70e
|
|
BLAKE2b-256 checksum How to use checksums |
5163f5212af823eeb1b5191ff9626e5c163ecbdac31d5708d9a2b9e59a00326c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|
Release files / agentmetering-0.1.0-py3-none-any.whl
| Download URL | agentmetering-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80b69d795821521cb22121332e250ca6aa8968d598b0b9ede8a6d5c77bbe9c97
|
|
BLAKE2b-256 checksum How to use checksums |
aec4ec0059bca4ea42f142fc357e35cb4505eef374d8992f25e10fa2d4984301
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|
Security for agentmetering 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.