Metadata-Version: 2.4
Name: agentbills
Version: 0.2.0
Summary: LLM cost intelligence + budget enforcement for AI agent fleets
Author-email: AgentBills <support@agentbills.app>
License: MIT
Project-URL: Homepage, https://agentbills.app
Project-URL: Documentation, https://agentbills.app/docs
Project-URL: Source, https://github.com/Vivekreddy99/blaze-api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.0
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == "openai"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30; extra == "anthropic"
Provides-Extra: bedrock
Requires-Dist: boto3>=1.34; extra == "bedrock"
Provides-Extra: all
Requires-Dist: openai>=1.0; extra == "all"
Requires-Dist: anthropic>=0.30; extra == "all"
Requires-Dist: boto3>=1.34; extra == "all"
Dynamic: license-file

# agentbills

**LLM cost intelligence + budget enforcement for AI agent fleets.**

The Python SDK for [AgentBills](https://agentbills.app). Drop one line at the top of your agent and every OpenAI / Anthropic / Bedrock call reports a cost event to your dashboard.

## Install

```bash
pip install agentbills[all]
```

Provider-specific installs are available if you only use one:

```bash
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

```python
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:

```bash
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):

```python
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`:

```python
set_metadata({"agent_id": "researcher"})
```

## Explicit-wrap pattern

If you'd rather not monkey-patch globally, wrap a specific client:

```python
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)

```python
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:

```python
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.

```python
# 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.
