agentbill / php-sdk
OpenTelemetry-based SDK for tracking AI agent usage and billing
v1.0.0
2025-10-22 17:46 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
- ramsey/uuid: ^4.0
README
OpenTelemetry-based SDK for automatically tracking and billing AI agent usage.
Installation
From GitHub (Recommended)
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/YOUR-ORG/agentbill-php"
}
],
"require": {
"agentbill/sdk": "dev-main"
}
}
Then run:
composer install
From Packagist
composer require agentbill/sdk
From Source
git clone https://github.com/YOUR-ORG/agentbill-php.git
cd agentbill-php
composer install
File Structure
agentbill-php/
├── README.md
├── composer.json
├── src/
│ ├── AgentBill.php
│ └── Tracer.php
└── examples/
└── basic_usage.php
Quick Start
<?php require 'vendor/autoload.php'; use AgentBill\AgentBill; // Initialize AgentBill $agentbill = AgentBill::init([ 'api_key' => 'your-api-key', 'customer_id' => 'customer-123', 'debug' => true, ]); // Wrap your OpenAI client $openai = $agentbill->wrapOpenAI($openaiClient); // Use normally - all calls are automatically tracked! $response = $openai->chat([ 'model' => 'gpt-4', 'messages' => [ ['role' => 'user', 'content' => 'Hello!'] ] ]); // Flush telemetry $agentbill->flush();
Features
- ✅ Zero-config instrumentation
- ✅ Accurate token & cost tracking
- ✅ Multi-provider support (OpenAI, Anthropic)
- ✅ Rich metadata capture
- ✅ OpenTelemetry-based
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 Packagist
Prerequisites
- Create a Packagist account at https://packagist.org/register/
- Create a GitHub repository for the SDK
Publishing Steps
- Push code to GitHub:
agentbill-php - Submit package to Packagist: https://packagist.org/packages/submit
- Link GitHub repository
- Packagist will auto-update on new releases
# Tag a release
git tag v1.0.0
git push origin v1.0.0
GitHub Repository Setup
- Create repository:
agentbill-php - Push all files from
src/directory - Ensure
composer.jsonhas correct autoload paths
License
MIT