spectra-php / laravel-spectra
Observability for AI and LLM calls in Laravel. Automatically tracks requests to OpenAI, Anthropic, Gemini, Mistral and 9 more providers, calculates token and media costs, enforces per-user budgets, and ships a real-time dashboard with OpenTelemetry export.
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/contracts: ^12.0||^13.0
- illuminate/database: ^12.0||^13.0
- illuminate/support: ^12.0||^13.0
- symfony/polyfill-php84: ^1.31
Requires (Dev)
- james-heinrich/getid3: 2.0.x-dev
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1
- openai-php/laravel: ^0.21.0
- orchestra/testbench: ^10.0||^11.0
- pestphp/pest: ^3.0||^4.0||^5.0
- pestphp/pest-plugin-arch: ^3.0||^4.0||^5.0
- pestphp/pest-plugin-laravel: ^3.0||^4.0||^5.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
Suggests
- james-heinrich/getid3: Required for extracting audio duration from TTS binary responses (minute-based cost calculation)
Provides
None
Conflicts
None
Replaces
None
README
Spectra is a comprehensive Laravel package for AI observability. It helps you track AI requests, measure usage, calculate costs across different pricing units, enforce budgets, and inspect AI operations through a unified dashboard and API. This lets you focus on shipping reliable AI features without getting buried in provider-specific operational complexity.
Official Documentation
Official documentation can be found on spectraphp.com.
Upgrading to 2.0
Spectra 2.0 tracks streamed responses automatically, bills prompt-cache reads and writes and reasoning tokens for every provider, and updates every pricing catalog. Most apps only need to run one new migration. See the upgrade guide and the changelog.
Code of Conduct
While this project is not affiliated with Laravel, we follow the Laravel Code of Conduct. We expect all contributors to follow these guidelines.
Author
This library is created by Ahmad Mayahi with contributions from the Open Source Community.
License
The MIT License (MIT). Please see License File for more information.