agentpay / php-sdk
PHP SDK for sending privacy-preserving telemetry to AgentPay.
Requires
- php: >=8.3
- guzzlehttp/guzzle: ^7.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^3.0
Requires (Dev)
- guzzlehttp/psr7: ^2.6
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.10
This package is not auto-updated.
Last update: 2026-09-02 05:12:21 UTC
README
Standalone PHP SDK for sending privacy-preserving telemetry to AgentPay.
Install
composer require agentpay/php-sdk
This package uses PSR-18 and PSR-17, so your application must provide an HTTP client and PSR-17 factories.
Quick Start
use AgentPay\AgentPayClient;
use AgentPay\Config\AgentPayConfig;
use AgentPay\Enum\EventType;
use AgentPay\Enum\IntegrationType;
use AgentPay\Enum\TaskType;
use AgentPay\Enum\TaskTypeSource;
use AgentPay\Telemetry\TelemetryEvent;
$client = AgentPayClient::create(new AgentPayConfig(
baseUrl: 'http://api.agentpay.localhost:8088',
apiKey: getenv('AGENTPAY_API_KEY') ?: '',
));
$client->telemetry()->ingest(new TelemetryEvent(
externalEventId: 'evt_'.bin2hex(random_bytes(8)),
organizationId: 'org_demo',
agentExternalId: 'php-sdk-demo',
agentName: 'PHP SDK Demo',
integrationType: IntegrationType::PhpSdk,
sessionExternalId: 'ses_demo',
taskExternalId: 'task_demo',
taskType: TaskType::Feature,
taskTypeSource: TaskTypeSource::Explicit,
taskTypeConfidence: 1.0,
eventType: EventType::LlmCompleted,
occurredAt: new DateTimeImmutable(),
provider: 'openai',
model: 'gpt-5.1',
inputTokens: 1000,
outputTokens: 250,
durationMs: 1200,
));
By default, metadata is sanitized before leaving the process. Prompt text, source code, file contents, secrets, tokens, and environment-like values should not be sent through metadata.
Offline Buffer
For integrations that should survive temporary AgentPay downtime, pass a telemetry buffer and use ingestOrBuffer():
use AgentPay\Telemetry\FileTelemetryBuffer;
$client = AgentPayClient::create(
config: $config,
telemetryBuffer: new FileTelemetryBuffer(__DIR__ . '/var/agentpay-events.jsonl'),
);
$client->telemetry()->ingestOrBuffer($event);
$client->telemetry()->flushBuffer();
Only retryable failures are buffered: transport failures, 429 and 5xx.
Quality Gates
composer verify
This runs PSR-12 checks, PHPStan and PHPUnit.
More Examples
examples/basic.phpexamples/batch.phpexamples/effective-budget.phpexamples/offline-buffer.phpexamples/custom-psr18-client.php
The public API is documented in docs/api.md.