gometap / larai-tracker
A standalone dashboard to track AI token usage and API costs for Laravel applications.
Requires
- php: ^8.2
- doctrine/dbal: ^3.5.1|^4.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.34|^3.0
- pestphp/pest-plugin-laravel: ^2.3|^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-01 06:42:02 UTC
README
Larai Tracker ๐
Larai Tracker is a standalone dashboard for tracking AI token usage and estimated USD API costs in Laravel applications. It observes supported requests made through Laravel's Http client for OpenAI, Anthropic, Gemini, Azure OpenAI, and OpenRouter without changing the calling code.
Supports Laravel 10, 11, and 12.
Screenshots
Dashboard
Logs
Features
- ๐ต๏ธ Automatic Tracking: Logs documented token usage from supported Laravel HTTP client responses.
- ๐ Premium Dashboard: Access a high-end AI analytics center at
/larai-tracker. - ๐ Singleton Authentication: Rate-limited, password-protected owner dashboard with secure first setup.
- ๐ฐ Honest Cost Estimates: Versioned USD catalog, manual overrides, and explicit unavailable-price states.
- ๐ Multi-Provider Support: OpenAI, Anthropic, Azure OpenAI, Gemini, and OpenRouter endpoint adapters.
- โ๏ธ Dynamic Pricing: Sync latest prices or manually override model costs from the UI.
- ๐ฆ Large-data Safety: Streamed exports, indexed date filters, and scheduled batched retention.
Installation
Install the package via composer:
composer require gometap/larai-tracker
Publish and run the migrations:
php artisan vendor:publish --tag="larai-tracker-migrations"
php artisan migrate
In production, configure either a permanent dashboard password or a temporary first-setup token:
LARAI_TRACKER_PASSWORD=a-long-random-password # Or, only until the first password is saved: LARAI_TRACKER_SETUP_TOKEN=a-long-random-owner-controlled-token
(Optional) Publish the configuration:
php artisan vendor:publish --tag="larai-tracker-config"
Usage
๐ต๏ธ Automatic Tracking
Once installed, the package observes successful calls made through Laravel's Http facade. It does not observe provider SDKs that bypass Laravel's HTTP client, streamed responses that do not emit a complete supported usage payload, or arbitrary OpenAI-compatible hosts.
| Provider | Supported endpoint shape | Usage fields |
|---|---|---|
| OpenAI | /v1/chat/completions, /v1/responses |
prompt/completion or input/output tokens |
| Anthropic | /v1/messages |
input/output tokens |
| Gemini | model generateContent URLs |
usageMetadata |
| Azure OpenAI | deployment chat/responses URLs | OpenAI-compatible usage |
| OpenRouter | /api/v1/chat/completions |
OpenAI-compatible usage |
Larai Tracker stores usage metadata only. It does not persist prompts, completions, raw bodies, authorization headers, or API keys.
๐ Accessing the Dashboard
Navigate to your application's URL at:
https://your-domain.com/larai-tracker
The dashboard features a premium dark-mode interface with:
- Total Investment: Your overall API spent.
- Burn Rate: Today's AI cost.
- Token Metrics: Total computation used.
- Live Stream: A real-time log of the latest AI calls.
Configuration
Authentication (Singleton Auth)
Larai Tracker uses a simple yet secure singleton authentication system. You can set the password in three ways (ordered by priority):
- Database: Change it directly from the Security section in the dashboard settings.
- Environment: Set
LARAI_TRACKER_PASSWORDin your.envfile. - Config: Set it in
config/larai-tracker.php.
If no password is set outside local, first setup is disabled unless LARAI_TRACKER_SETUP_TOKEN contains at least 16 characters. Enter that token once on the setup screen, save the password, then remove the setup token from the environment. Login is limited to five attempts per minute per IP.
Pricing, currency, and budgets
All estimated costs and budgets use USD. Unknown models are logged with a null cost, shown as Price unavailable, and excluded from totals and budget alerts. Prices are estimates and never replace provider invoices. Manual model prices take precedence and are not overwritten by catalog sync. See catalog provenance.
Retention
Web requests no longer run cleanup. Set the retention period in Settings and schedule the command in the host application:
use Illuminate\Support\Facades\Schedule; Schedule::command('larai:cleanup')->daily();
You can also run php artisan larai:cleanup --days=90 --batch=1000 manually.
Upgrading from v1.1.x
composer require gometap/larai-tracker:^1.2
php artisan vendor:publish --tag="larai-tracker-migrations"
php artisan migrate
The upgrade makes cost_usd nullable, adds price provenance and budget-alert idempotency fields, and normalizes the old display-only currency setting to USD. Existing logs and manual prices remain unchanged. Replace any GET logout links with the package's POST form if you published custom views, and schedule larai:cleanup if retention is enabled.
๐งช Testing
The package includes a comprehensive test suite powered by Pest.
composer test
composer format:check
composer analyse
Contributing
Please see CONTRIBUTING for details.
Credits
License
The Apache License 2.0. Please see License File for more information.