Automatically track Laravel AI SDK token usage across all your agents.
composer require agentsoftware/laravel-ai-token-tracker
php artisan migrateThe package auto-registers itself. No configuration needed.
use AgentSoftware\LaravelAiTokenTracker\Facades\AiUsage;
// Overall totals
AiUsage::total();
// ['input_tokens' => 12400, 'output_tokens' => 3200, 'cache_write_tokens' => 800, 'cache_read_tokens' => 400]
// Totals for a specific agent
AiUsage::forAgent(MyAgent::class)->total();
// Totals grouped by agent class
AiUsage::byAgent();The package listens to the AgentPrompted event dispatched by laravel/ai after every prompt. Each prompt call writes one row to ai_token_usages with the agent class, model name, and token counts.
- PHP 8.4+
- Laravel 12 or 13
laravel/ai