agentbills
LLM cost intelligence + budget enforcement for AI agent fleets.
The Python SDK for AgentBills. Drop one line at the top of your agent and every OpenAI / Anthropic / Bedrock call reports a cost event to your dashboard.
Install
pip install agentbills[all]
Provider-specific installs are available if you only use one:
pip install agentbills[openai] # only the OpenAI library
pip install agentbills[anthropic] # only the Anthropic library
pip install agentbills[bedrock] # only boto3 / Bedrock
Quick start — auto-instrument
from agentbills import instrument
instrument() # patches openai/anthropic/bedrock libs at import time
# nothing else changes — your existing client calls now report events
import openai
client = openai.OpenAI()
client.chat.completions.create(model="gpt-4o-mini", messages=[...])
Set AGENTBILLS_API_KEY in the environment and you're done:
export AGENTBILLS_API_KEY=blaze_sk_...
Or pass it explicitly: instrument(api_key="blaze_sk_...").
Tag events with custom metadata
set_metadata() attaches a dict to every event generated in the current context (works across await boundaries):
from agentbills import set_metadata
set_metadata({"feature": "summarize", "user_id": "u123"})
response = openai_client.chat.completions.create(...)
# the event for this call carries feature=summarize, user_id=u123
To pin the agent name for a specific call instead of relying on fleet_name:
set_metadata({"agent_id": "researcher"})
Explicit-wrap pattern
If you'd rather not monkey-patch globally, wrap a specific client:
import openai
from agentbills import AgentBillsClient, wrap_openai_client
ab = AgentBillsClient(api_key="blaze_sk_...")
openai_client = wrap_openai_client(openai.OpenAI(), ab, agent_name="researcher")
Decorator pattern (for explicit fleets)
from agentbills import Fleet
fleet = Fleet(api_key="blaze_sk_...")
@fleet.agent("researcher")
def run(query: str):
...
print(fleet.dashboard_url)
Flushing before exit
The SDK buffers events and flushes in batches. For short-lived scripts, flush explicitly:
client = instrument()
# ... your agent code ...
client.flush()
For long-running services this isn't necessary — the buffer flushes automatically on every batch_size events.
Migrating from blaze-agents 0.1
The old package was blaze-agents with imports like from blaze import …. v0.2 renames to agentbills and adds the instrument() entry point.
# OLD
from blaze import Fleet, BlazeClient
# NEW
from agentbills import Fleet, AgentBillsClient # BlazeClient is a back-compat alias
The from blaze import … path no longer works — update your imports.
License
MIT.
Release files for agentbills 0.2.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 | |
|---|---|---|---|
| agentbills-0.2.0.tar.gz | 15.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentbills-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.1 kB
Release files / agentbills-0.2.0.tar.gz
| Download URL | agentbills-0.2.0.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4847e47d4049bba323ce989619ee089572f315c5d0f384f3f882a75bf14c5c92
|
|
BLAKE2b-256 checksum How to use checksums |
7243632485aa0c43bc4f1ec5a84a2e8ab2a54e8e8f61c32b1541fdee36a68a5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / agentbills-0.2.0-py3-none-any.whl
| Download URL | agentbills-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ac76991cb3515367100ccd185a08ee994533a9ba1c2dbc0deb179293dbd342d
|
|
BLAKE2b-256 checksum How to use checksums |
f084b87c49daf9f3272c03196f6cb0bfa556097a59d6a9ae61ecf039a7ccd8d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|