phoenix1331/laravel-ai-headroom-ledger
Laravel AI Headroom Ledger provides an auditable record of AI token usage and remaining headroom, helping you track consumption, enforce budgets, and monitor provider limits through simple Laravel-friendly APIs.
Architecture fit: The package fits Laravel/PHP applications that need usage, token, cost, and accuracy observability. v0.1.1 strengthens the query layer with sorting, pagination, scoped lookups, count-method filtering, and accuracy breakdowns. Daily rollups make it suitable for dashboards and reporting without repeatedly scanning raw entries. The added LedgerQuery::find() and LedgerQuery::run() filtered variants improve multi-tenant safety, but the unscoped Ledger::find() and Ledger::run() remain available and are now explicitly documented as unscoped.
Integration feasibility: The release is additive: no breaking API changes are called out. New orderBy(), paginate(), forCountMethod(), scoped find()/run(), and accuracy() APIs can be adopted incrementally. LedgerPage and AccuracyStats make UI/API integration easier, including Arrayable support for JSON output. Feasibility is good for a Laravel app already using Composer, migrations, and scheduled jobs, but depends on rollup setup and tenant-filter discipline.
Technical risk: The package is still v0.x, so API churn is a real risk. Rollup freshness directly affects filters, pagination totals, and accuracy stats. Cost sorting uses stored currency values without conversion, which can mislead cross-currency comparisons. Null sorting is consistent across databases per the notes, but consumers must still handle null-last behavior clearly. Scoped find()/run() reduce tenant leakage risk only if every relevant filter is applied correctly. Pagination with filters, sorting, and computed actual/estimate figures may need indexing and load testing.
Key questions: Which Laravel/PHP versions are supported, especially for readonly LedgerPage and enums? Which database engines are supported and tested for null ordering and pagination? How are daily rollups generated, backfilled, and repaired? What is the tenancy model, and how should teams enforce filtered LedgerQuery usage? How should mixed-currency cost reporting be presented? What sample thresholds make AccuracyStats reliable? What is the pagination count cost on large ledgers? What is the package’s versioning and support policy for v0.x?
Stack fit: Best fit is a Laravel/PHP application using Eloquent/DB, scheduled jobs, and existing tenant/auth scoping. The package can support internal cost dashboards, tenant-facing usage pages, support tooling, and model/provider accuracy reporting. Non-Laravel PHP stacks or teams without rollup jobs would face more integration work.
Migration path: Start with package installation, config publishing, migrations, ingestion validation, and rollup scheduling. Then adopt the new query features in order: filtered queries, sorting, pagination, count-method filtering, tenant-scoped find()/run(), and accuracy reporting. Keep unscoped Ledger::find()/run() out of tenant-facing code and document that guardrail.
Compatibility: Existing behavior is unchanged, and the new APIs are additive. The enum and readonly page object require verification against the app’s PHP version. Null-last sorting is stated to be consistent across databases, but target databases should still be tested. Currency sorting is by stored value only, so reporting layers should avoid implying converted cost comparisons. AccuracyStats as Arrayable should fit existing Laravel JSON responses.
Sequencing: 1) Install and configure the package. 2) Validate ingestion and daily rollups. 3) Add filtered LedgerQuery usage behind tenant scopes. 4) Implement pagination and sorting in dashboards. 5) Add count-method filters for cost-method reporting. 6) Add accuracy breakdowns for model/provider/agent/tag/run views. 7) Load-test pagination and ordered queries. 8) Publish internal guidance on scoped lookups, currency handling, and null sorting.
Maintenance: Code maintenance is modest if the package is actively maintained, but v0.x requires release tracking and version pinning. Daily rollups add scheduled-job ownership, backfill procedures, and freshness monitoring. Teams should expect occasional schema or API adjustments before v1.
Support: Maintainer support and community depth are unknown from the release notes. Teams should pin versions, keep an internal integration runbook, and avoid depending on undocumented behavior. Support staff need clear guidance on scoped versus unscoped lookup methods.
Scaling: Daily rollups are the right scaling lever for dashboards and filters. Pagination limits result sets, but ordered queries over computed actual/estimate figures and tenant filters still need proper indexes, retention policies, and query monitoring. Accuracy stats scale well where rollups support the grouping; other groupings may be more expensive.
Failure modes: Stale or missing rollups can produce wrong filters, totals, and accuracy figures. Misused unscoped Ledger::find()/run() can leak cross-tenant data. Mixed-currency cost sorting can be misread as normalized spend. Null-last sorting and ties by request ID must be reflected in UI copy and tests. Pagination past the end returns an empty page with the correct total, which should be handled intentionally. Rollup job failures and migration issues are the main operational risks.
Ramp-up: Laravel developers should ramp up quickly on installation and query APIs. The TPM’s focus should be on enforcing tenant-scoped query patterns, explaining actual-versus-estimated figures and currency behavior, documenting null sorting, and training support on rollup freshness and safe lookup methods.
How can I help you explore Laravel packages today?