# AgentBill Python SDK
OpenTelemetry-based SDK for automatically tracking and billing AI agent usage.
## Installation
### From PyPI (Recommended)
```bash
pip install agentbill-py-sdk
```
### From PyPI (Coming Soon)
```bash
pip install agentbill
```
### From Source
```bash
git clone https://github.com/Agent-Bill/python.git
cd python
pip install -e .
```
## File Structure
```
agentbill-python/
├── agentbill/
│ ├── __init__.py
│ ├── client.py
│ ├── tracer.py
│ └── types.py
├── examples/
│ ├── openai_basic.py
│ ├── anthropic_basic.py
│ ├── bedrock_basic.py
│ ├── azure_openai_basic.py
│ ├── mistral_basic.py
│ └── google_ai_basic.py
├── tests/
│ ├── test_agentbill.py
│ └── test_tracer.py
├── README.md
├── setup.py
├── pyproject.toml
├── pytest.ini
├── Makefile
├── CHANGELOG.md
├── CONTRIBUTING.md
├── SECURITY.md
└── LICENSE
```
## Quick Start
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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)
```python
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
```python
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:
```ini
[pypi]
username = __token__
password = pypi-YOUR_API_TOKEN_HERE
```
### Publishing Steps
```bash
# 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 agentbill-py-sdk`
## License
MIT
Raw data
{
"_id": null,
"home_page": "https://github.com/Agent-Bill/python",
"name": "agentbill-py-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "ai, billing, tracking, opentelemetry, llm, agents",
"author": "AgentBill",
"author_email": "AgentBill Team <support@agentbill.com>",
"download_url": "https://files.pythonhosted.org/packages/9f/67/2005ef887aec86fc3c496d9a899522f9f5192878ff12329eb1cfff0eb521/agentbill_py_sdk-1.0.3.tar.gz",
"platform": null,
"description": "# AgentBill Python SDK\n\nOpenTelemetry-based SDK for automatically tracking and billing AI agent usage.\n\n## Installation\n\n### From PyPI (Recommended)\n```bash\npip install agentbill-py-sdk\n```\n\n### From PyPI (Coming Soon)\n```bash\npip install agentbill\n```\n\n### From Source\n```bash\ngit clone https://github.com/Agent-Bill/python.git\ncd python\npip install -e .\n```\n\n## File Structure\n\n```\nagentbill-python/\n\u251c\u2500\u2500 agentbill/\n\u2502 \u251c\u2500\u2500 __init__.py\n\u2502 \u251c\u2500\u2500 client.py\n\u2502 \u251c\u2500\u2500 tracer.py\n\u2502 \u2514\u2500\u2500 types.py\n\u251c\u2500\u2500 examples/\n\u2502 \u251c\u2500\u2500 openai_basic.py\n\u2502 \u251c\u2500\u2500 anthropic_basic.py\n\u2502 \u251c\u2500\u2500 bedrock_basic.py\n\u2502 \u251c\u2500\u2500 azure_openai_basic.py\n\u2502 \u251c\u2500\u2500 mistral_basic.py\n\u2502 \u2514\u2500\u2500 google_ai_basic.py\n\u251c\u2500\u2500 tests/\n\u2502 \u251c\u2500\u2500 test_agentbill.py\n\u2502 \u2514\u2500\u2500 test_tracer.py\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 setup.py\n\u251c\u2500\u2500 pyproject.toml\n\u251c\u2500\u2500 pytest.ini\n\u251c\u2500\u2500 Makefile\n\u251c\u2500\u2500 CHANGELOG.md\n\u251c\u2500\u2500 CONTRIBUTING.md\n\u251c\u2500\u2500 SECURITY.md\n\u2514\u2500\u2500 LICENSE\n```\n\n## Quick Start\n\n```python\nfrom agentbill import AgentBill\nimport openai\n\n# Initialize AgentBill\nagentbill = AgentBill.init({\n \"api_key\": \"your-api-key\",\n \"customer_id\": \"customer-123\",\n \"debug\": True\n})\n\n# Wrap your OpenAI client\nclient = agentbill.wrap_openai(openai.OpenAI(\n api_key=\"sk-...\"\n))\n\n# Use normally - all calls are automatically tracked!\nresponse = client.chat.completions.create(\n model=\"gpt-4\",\n messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n```\n\n## Features\n\n- \u2705 Zero-config instrumentation\n- \u2705 Accurate token & cost tracking\n- \u2705 Multi-provider support (OpenAI, Anthropic, Bedrock, Azure OpenAI, Mistral, Google AI)\n- \u2705 Rich metadata capture\n- \u2705 OpenTelemetry-based\n\n## Supported Providers\n\n- **OpenAI** - GPT-4, GPT-5, Embeddings, DALL-E, Whisper, TTS\n- **Anthropic** - Claude Sonnet, Claude Opus\n- **AWS Bedrock** - Claude, Titan, and other Bedrock models\n- **Azure OpenAI** - GPT models via Azure\n- **Mistral AI** - Mistral models\n- **Google AI** - Gemini Pro, Gemini Flash\n\n## Provider Examples\n\n### OpenAI\n```python\nfrom agentbill import AgentBill\nimport openai\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\nclient = agentbill.wrap_openai(openai.OpenAI(api_key=\"sk-...\"))\n\nresponse = client.chat.completions.create(\n model=\"gpt-4\",\n messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n```\n\n### Anthropic\n```python\nfrom agentbill import AgentBill\nimport anthropic\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\nclient = agentbill.wrap_anthropic(anthropic.Anthropic(api_key=\"sk-ant-...\"))\n\nresponse = client.messages.create(\n model=\"claude-sonnet-4-20250514\",\n max_tokens=1024,\n messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n```\n\n### AWS Bedrock\n```python\nfrom agentbill import AgentBill\nimport boto3\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\nbedrock = agentbill.wrap_bedrock(boto3.client('bedrock-runtime'))\n\nresponse = bedrock.invoke_model(\n modelId='anthropic.claude-v2',\n body=json.dumps({\n \"prompt\": \"Hello!\",\n \"max_tokens_to_sample\": 300\n })\n)\n```\n\n### Azure OpenAI\n```python\nfrom agentbill import AgentBill\nfrom openai import AzureOpenAI\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\nclient = agentbill.wrap_azure_openai(AzureOpenAI(\n api_key=\"your-azure-key\",\n api_version=\"2024-02-01\",\n azure_endpoint=\"https://your-resource.openai.azure.com\"\n))\n\nresponse = client.chat.completions.create(\n model=\"gpt-4\",\n messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n```\n\n### Mistral AI\n```python\nfrom agentbill import AgentBill\nfrom mistralai import Mistral\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\nclient = agentbill.wrap_mistral(Mistral(api_key=\"your-mistral-key\"))\n\nresponse = client.chat.complete(\n model=\"mistral-large-latest\",\n messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n```\n\n### Google AI (Gemini)\n```python\nfrom agentbill import AgentBill\nimport google.generativeai as genai\n\nagentbill = AgentBill.init({\"api_key\": \"your-api-key\"})\ngenai.configure(api_key=\"your-google-key\")\nmodel = genai.GenerativeModel('gemini-pro')\nwrapped_model = agentbill.wrap_google_ai(model)\n\nresponse = wrapped_model.generate_content(\"Hello!\")\n```\n\n## Configuration\n\n```python\nconfig = {\n \"api_key\": \"your-api-key\", # Required\n \"base_url\": \"https://...\", # Optional\n \"customer_id\": \"customer-123\", # Optional\n \"debug\": True # Optional\n}\n\nagentbill = AgentBill.init(config)\n```\n\n## Publishing to PyPI\n\n### Prerequisites\n1. Create a PyPI account at https://pypi.org/account/register/\n2. Generate an API token at https://pypi.org/manage/account/token/\n3. Create `~/.pypirc` file with your token:\n```ini\n[pypi]\nusername = __token__\npassword = pypi-YOUR_API_TOKEN_HERE\n```\n\n### Publishing Steps\n```bash\n# Build the package\npython setup.py sdist bdist_wheel\n\n# Upload to PyPI\npip install twine\ntwine upload dist/*\n```\n\n## GitHub Repository Setup\n\n1. Create repository: `https://github.com/Agent-Bill/python`\n2. Push all files (agentbill/, examples/, LICENSE, setup.py, README.md)\n3. Tag releases: `git tag v1.0.0 && git push origin v1.0.0`\n4. Users can install with: `pip install agentbill-py-sdk`\n\n## License\n\nMIT\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "OpenTelemetry-based SDK for tracking and billing AI agent usage",
"version": "1.0.3",
"project_urls": {
"Documentation": "https://github.com/Agent-Bill/python#readme",
"Homepage": "https://github.com/Agent-Bill/python",
"Issues": "https://github.com/Agent-Bill/python/issues",
"Repository": "https://github.com/Agent-Bill/python.git"
},
"split_keywords": [
"ai",
" billing",
" tracking",
" opentelemetry",
" llm",
" agents"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c66f66eb07940823c0dd71401efa12e793d49801212e12361142f9b0218de22c",
"md5": "ebc083a380669b74dc9f132061da219f",
"sha256": "122d4613ecd2e8d7cf27dd03e2c390bbd3f4842743da8d56c555f17aa8264a38"
},
"downloads": -1,
"filename": "agentbill_py_sdk-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebc083a380669b74dc9f132061da219f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11546,
"upload_time": "2025-10-27T13:10:30",
"upload_time_iso_8601": "2025-10-27T13:10:30.705814Z",
"url": "https://files.pythonhosted.org/packages/c6/6f/66eb07940823c0dd71401efa12e793d49801212e12361142f9b0218de22c/agentbill_py_sdk-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9f672005ef887aec86fc3c496d9a899522f9f5192878ff12329eb1cfff0eb521",
"md5": "4b2caf068f01b4d5a6d4a7a2b68ed253",
"sha256": "f604d8711882cc6bf721759942573caff7724d87b298bbf1ee799bcb2fc96140"
},
"downloads": -1,
"filename": "agentbill_py_sdk-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "4b2caf068f01b4d5a6d4a7a2b68ed253",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 13879,
"upload_time": "2025-10-27T13:10:31",
"upload_time_iso_8601": "2025-10-27T13:10:31.549651Z",
"url": "https://files.pythonhosted.org/packages/9f/67/2005ef887aec86fc3c496d9a899522f9f5192878ff12329eb1cfff0eb521/agentbill_py_sdk-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-27 13:10:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Agent-Bill",
"github_project": "python",
"github_not_found": true,
"lcname": "agentbill-py-sdk"
}