Laravel SDK
Report cost, latency, and quality for the AI agents in your Laravel app. If you use laravel/ai, every prompt and embedding is captured automatically, no code changes. The SDK is non-blocking and never throws into your app.
Install
Until we are on Packagist, add the repository, then require the package:
"repositories": [
{ "type": "vcs", "url": "git@github.com:agent-ping/agent-ping-laravel.git" }
]
composer require agentping/laravel:^0.1
Set your API key. The ingest region is read from the key, so there is nothing else to configure:
AGENTPING_API_KEY=apk_eu_...
Requires PHP 8.2+. The service provider is auto-discovered.
Automatic instrumentation
With laravel/ai installed, every prompt, stream, and embedding is reported, with provider, model, token usage, latency, and cost:
$reply = (new SalesCoach)->prompt('Score this email: ...'); // captured automatically
Disable it any time with AGENTPING_LISTEN_TO_AI_SDK=false.
Naming your agents
Runs are grouped by agent name in Spend and Pulse. The name is resolved in this order:
- An active run:
AgentPing::run('name')orAgentPing::agent('name', fn () => ...). AgentPing::useAgent('name'): set once at the top of a request, job, or command; every auto-captured call in that scope uses it (reset automatically afterwards).- A named Agent class: a
laravel/aiAgent class likeMorningBriefingis auto-namedmorning_briefing, no extra code. AGENTPING_DEFAULT_AGENT(defaultai-agent).
The anonymous agent($prompt)->prompt(...) helper carries no name, so for those calls use one of the first two. Either name the whole scope once:
use AgentPing\Laravel\Facades\AgentPing;
AgentPing::useAgent('morning-briefing');
$summary = agent($systemPrompt)->prompt($userMessage, provider: 'anthropic');
or wrap a single call to also group it as one run:
$summary = AgentPing::agent('morning-briefing', fn () =>
agent($systemPrompt)->prompt($userMessage, provider: 'anthropic')
);
If you define your agents as classes instead of the agent() helper, naming is automatic.
Manual tracking
For agents that do not use laravel/ai, track runs directly:
use AgentPing\Laravel\Facades\AgentPing;
$run = AgentPing::run('support-triage', customerId: 'acme', feature: 'ticket-routing');
$run->event('llm_call', [
'provider' => 'anthropic',
'model' => 'claude-sonnet-4-6',
'input_tokens' => 1200,
'output_tokens' => 480,
]);
$run->finish('success', scores: ['confidence' => 0.92]);
Nest sub-agents by passing parentRunId: (or set the AGENTPING_PARENT_RUN env var) to build a run tree.
Heartbeats
For cron jobs and scheduled tasks, report one completion per run:
AgentPing::heartbeat('daily-summary', status: 'ok', costUsd: 0.084, durationMs: 12_300);
Queue workers
Telemetry flushes automatically at the end of each web request, console command, and queued job. Restart Horizon and your queue workers after deploying so they load the new code and key. For a custom long-running loop, call AgentPing::flush().
Configuration
| Variable | Default | Description |
|---|---|---|
AGENTPING_API_KEY |
required | Region-scoped team key (apk_...). |
AGENTPING_DEFAULT_AGENT |
ai-agent |
Name for un-named auto-captured calls. |
AGENTPING_LISTEN_TO_AI_SDK |
true |
Auto-instrument laravel/ai. |
AGENTPING_PARENT_RUN |
optional | Parent run id for nesting. |
Run php artisan vendor:publish --tag=agentping-config for the full config (queue size, batch size, timeouts). Use a team key for the SDK; ping_... tokens are for URLs only.