Skip to main content

LLM cost intelligence + budget enforcement for AI agent fleets

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentbills-0.2.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentbills-0.2.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file agentbills-0.2.0.tar.gz.

File metadata

  • Download URL: agentbills-0.2.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for agentbills-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4847e47d4049bba323ce989619ee089572f315c5d0f384f3f882a75bf14c5c92
MD5 a019821e38bc8a5bb89ec8b1870328ce
BLAKE2b-256 7243632485aa0c43bc4f1ec5a84a2e8ab2a54e8e8f61c32b1541fdee36a68a5f

See more details on using hashes here.

File details

Details for the file agentbills-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: agentbills-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for agentbills-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ac76991cb3515367100ccd185a08ee994533a9ba1c2dbc0deb179293dbd342d
MD5 071259b7fcfc4caf6825a2f4d380e89e
BLAKE2b-256 f084b87c49daf9f3272c03196f6cb0bfa556097a59d6a9ae61ecf039a7ccd8d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page