Skip to content

AgentSoftware/laravel-ai-token-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel AI Token Tracker

Automatically track Laravel AI SDK token usage across all your agents.

Installation

composer require agentsoftware/laravel-ai-token-tracker
php artisan migrate

The package auto-registers itself. No configuration needed.

Usage

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();

How it works

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.

Requirements

  • PHP 8.4+
  • Laravel 12 or 13
  • laravel/ai

About

Automatically track Laravel AI SDK token usage

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages