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.
paginate() plus orderBy(EntrySort::Cost|PercentUsed|CountedAt...) makes it practical to ship a "usage & spend" screen without hand-rolling query logic — sort by cost, tokens, or when a limit was hit, with stable tie-breaking (request ID) so pages don't jitter.LedgerQuery::find($requestId) / run($invocationId) returning null unless every filter matches is the single most product-relevant item here: it turns "don't leak another tenant's data" from a documented caveat into an enforced default. This should be treated as a prerequisite for any per-customer analytics or support-console feature.forCountMethod() and GroupedQuery::accuracy() let you answer "how accurate were our token estimates vs. actuals, by model/provider/agent/run" — the evidence base for negotiating pricing, switching models, or justifying a routing/reasoning-effort roadmap item.AccuracyStats (Arrayable, so directly serialisable to API responses) supports an internal or customer-facing "we estimate within X% of actuals" commitment — useful for pricing predictability and for deciding whether estimates can be shown pre-flight.Adopt when:
Look elsewhere or wait when:
Ledger::find() / Ledger::run() in a tenant-facing path — behaviour is unchanged, so existing code carries the risk until migrated.To executives: This release converts raw AI-usage logging into shippable product surface — sortable, paginated usage and cost reporting, plus accuracy metrics that tell us how far our estimates diverge from real spend by model and provider. It also closes a data-isolation gap: per-tenant lookups by request ID cannot return another customer's data. That's a security and compliance win, not just a feature.
To engineering: Low-risk, additive release — new methods and an enum, no breaking changes. Ledger::find()/run() are unchanged but now documented as unscoped, with filtered LedgerQuery equivalents recommended; we should migrate tenant-facing call sites. Rollup-backed filters and sorts mean these queries stay cheap at scale. AccuracyStats is Arrayable, so it drops straight into our API resources.
To product/design: New capabilities are sorting by cost/tokens/percent-used/recency, paged entry lists with correct totals on out-of-range pages, filtering by how a limit was counted, and an accuracy breakdown for either a time series or a per-model/provider/agent/tag/run comparison. Sparse days appear as empty rather than missing, so charts stay honest.
Caveats to state up front: amounts in different currencies are sorted by stored value with no conversion — we must not present mixed-currency totals as meaningful; and estimate-accuracy is only as good as the rollups, which are daily-grained.
Recommendation: Adopt. Prioritise (1) migrating tenant-facing ID lookups to the scoped query methods, (2) a cost-sorted, paginated usage page, (3) an estimate-accuracy view by model/provider as input to pricing and model-routing decisions.
How can I help you explore Laravel packages today?