Skip to main content

AgentBill Python SDK

OpenTelemetry-based SDK for automatically tracking and billing AI agent usage.

Installation

pip install git+https://github.com/Agent-Bill/python.git

From PyPI (Coming Soon)

pip install agentbill

From Source

git clone https://github.com/Agent-Bill/python.git
cd python
pip install -e .

File Structure

agentbill-python/
├── README.md
├── setup.py
├── agentbill/
│   ├── __init__.py
│   ├── client.py
│   ├── tracer.py
│   └── types.py
└── examples/
    └── basic_usage.py

Quick Start

from agentbill import AgentBill
import openai

# Initialize AgentBill
agentbill = AgentBill.init({
    "api_key": "your-api-key",
    "customer_id": "customer-123",
    "debug": True
})

# Wrap your OpenAI client
client = agentbill.wrap_openai(openai.OpenAI(
    api_key="sk-..."
))

# Use normally - all calls are automatically tracked!
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Features

  • ✅ Zero-config instrumentation
  • ✅ Accurate token & cost tracking
  • ✅ Multi-provider support (OpenAI, Anthropic, Bedrock, Azure OpenAI, Mistral, Google AI)
  • ✅ Rich metadata capture
  • ✅ OpenTelemetry-based

Supported Providers

  • OpenAI - GPT-4, GPT-5, Embeddings, DALL-E, Whisper, TTS
  • Anthropic - Claude Sonnet, Claude Opus
  • AWS Bedrock - Claude, Titan, and other Bedrock models
  • Azure OpenAI - GPT models via Azure
  • Mistral AI - Mistral models
  • Google AI - Gemini Pro, Gemini Flash

Provider Examples

OpenAI

from agentbill import AgentBill
import openai

agentbill = AgentBill.init({"api_key": "your-api-key"})
client = agentbill.wrap_openai(openai.OpenAI(api_key="sk-..."))

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Anthropic

from agentbill import AgentBill
import anthropic

agentbill = AgentBill.init({"api_key": "your-api-key"})
client = agentbill.wrap_anthropic(anthropic.Anthropic(api_key="sk-ant-..."))

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

AWS Bedrock

from agentbill import AgentBill
import boto3

agentbill = AgentBill.init({"api_key": "your-api-key"})
bedrock = agentbill.wrap_bedrock(boto3.client('bedrock-runtime'))

response = bedrock.invoke_model(
    modelId='anthropic.claude-v2',
    body=json.dumps({
        "prompt": "Hello!",
        "max_tokens_to_sample": 300
    })
)

Azure OpenAI

from agentbill import AgentBill
from openai import AzureOpenAI

agentbill = AgentBill.init({"api_key": "your-api-key"})
client = agentbill.wrap_azure_openai(AzureOpenAI(
    api_key="your-azure-key",
    api_version="2024-02-01",
    azure_endpoint="https://your-resource.openai.azure.com"
))

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Mistral AI

from agentbill import AgentBill
from mistralai import Mistral

agentbill = AgentBill.init({"api_key": "your-api-key"})
client = agentbill.wrap_mistral(Mistral(api_key="your-mistral-key"))

response = client.chat.complete(
    model="mistral-large-latest",
    messages=[{"role": "user", "content": "Hello!"}]
)

Google AI (Gemini)

from agentbill import AgentBill
import google.generativeai as genai

agentbill = AgentBill.init({"api_key": "your-api-key"})
genai.configure(api_key="your-google-key")
model = genai.GenerativeModel('gemini-pro')
wrapped_model = agentbill.wrap_google_ai(model)

response = wrapped_model.generate_content("Hello!")

Configuration

config = {
    "api_key": "your-api-key",        # Required
    "base_url": "https://...",         # Optional
    "customer_id": "customer-123",     # Optional
    "debug": True                       # Optional
}

agentbill = AgentBill.init(config)

Publishing to PyPI

Prerequisites

  1. Create a PyPI account at https://pypi.org/account/register/
  2. Generate an API token at https://pypi.org/manage/account/token/
  3. Create ~/.pypirc file with your token:
[pypi]
username = __token__
password = pypi-YOUR_API_TOKEN_HERE

Publishing Steps

# Build the package
python setup.py sdist bdist_wheel

# Upload to PyPI
pip install twine
twine upload dist/*

GitHub Repository Setup

  1. Create repository: https://github.com/Agent-Bill/python
  2. Push all files (agentbill/, examples/, LICENSE, setup.py, README.md)
  3. Tag releases: git tag v1.0.0 && git push origin v1.0.0
  4. Users can install with: pip install git+https://github.com/Agent-Bill/python.git

License

MIT

Release files for agentbill 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentbill 1.0.0
File Size Uploaded
agentbill-1.0.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentbill 1.0.0
File Interpreter ABI Platform
agentbill-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / agentbill-1.0.0.tar.gz

Download URL agentbill-1.0.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
95f865fbc8b1cbeeeb01453091c81f2ff21efad7d58f4a5e56c549104dbcea6d
BLAKE2b-256 checksum
How to use checksums
5c6844ee8e81d102c08a8b120793154369700cc69e7ceb4c96372e6282dd2e91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / agentbill-1.0.0-py3-none-any.whl

Download URL agentbill-1.0.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdb332bf40d9f6f94861d88cdb2e749eb08fcdf5f321e1639f6600b8e89f56e5
BLAKE2b-256 checksum
How to use checksums
8328e298d54c0db56816e4fa5818cd02ad57905f9bb20591b13c16a8c1fa5952
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page