Token cost accounting for AI-heavy Laravel applications. Tracks spend per user, per feature, and per model. Enforces budgets before calls are made.
composer require fr3on/laravel-ledger
php artisan migrateWrap your AI calls with the Ledger facade:
use Fr3on\Ledger\Facades\Ledger;
$result = Ledger::for(user: $user, feature: 'chat')
->budget()->dailyLimit(tokens: 50_000)->orFail()
->track(fn() => $ai->generate($prompt));The ledger tracks token usage and calculates costs based on your pricing map. You can then generate reports:
php artisan ledger:report --period=monthOutput Example:
Ledger Report — April 2026
Feature Requests Tokens Cost (USD)
──────────────────────────────────────────────────────
chat 1,240 4,820,000 $72.30
summarize 380 940,000 $14.10
embed 2,100 210,000 $4.20
──────────────────────────────────────────────────────
TOTAL 3,720 5,970,000 $90.60
Publish the config file:
php artisan vendor:publish --tag=ledger-configDefine your model pricing and token drivers in config/ledger.php.