fr3on/laravel-ledger

Token cost accounting and budget enforcement for AI-heavy Laravel applications. Supports OpenAI, Anthropic, Gemini, and more.

Maintainers

Package info

github.com/fr3on/laravel-ledger

pkg:composer/fr3on/laravel-ledger

Statistics

Installs: 99

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2026-04-12 13:42 UTC

This package is auto-updated.

Last update: 2026-04-12 13:44:11 UTC


README

GitHub license PHP Version Laravel Version Tests

Token cost accounting for AI-heavy Laravel applications. Tracks spend per user, per feature, and per model. Enforces budgets before calls are made.

Installation

composer require fr3on/laravel-ledger
php artisan migrate

Usage

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

Expected Result

The ledger tracks token usage and calculates costs based on your pricing map. You can then generate reports:

php artisan ledger:report --period=month

Output 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

Configuration

Publish the config file:

php artisan vendor:publish --tag=ledger-config

Define your model pricing and token drivers in config/ledger.php.