lunetics/llm-cost-tracking-bundle
Lunetics LLM Cost Tracking Bundle helps Symfony/PHP apps monitor LLM API usage and estimate spend across providers and models. Track token counts, attribute costs to users or features, set budgets, and review usage via dashboards and reports.
lunetics/llm-cost-tracking-bundle is a Symfony bundle (not a Laravel package) that tallies token usage and computes per-model LLM costs, with a Web Profiler panel for inspecting them. In Laravel you get the cost-tracking core, but not the profiler UI — plan to build your own surfacing (logs, Telescope, a dashboard).
composer require lunetics/llm-cost-tracking-bundleLlmCostServiceProvider, or instantiate the tracker directly from the container.CostTrackerInterface. In v0.6.0 this interface changed (see Gotchas) — read its signature in the source before writing your first implementation.config/llm-cost-tracking.php so you can maintain prices yourself.First use case: a thin decorator around your OpenAI/Anthropic client that records model, prompt_tokens, completion_tokens on each response and returns a computed cost you can log alongside the request.
$this->app->bind(CostTrackerInterface::class, ...). This keeps you insulated from the v0.6.0 interface break and lets you swap in a null/no-op tracker in tests.Log::warning() or a metrics counter.llm_costs table (user, tenant, job id, model, tokens, cost).CostTrackerInterface that records calls and returns a fixed cost; assert against that in feature tests rather than mocking HTTP.CostTrackerInterface changed. Any custom implementation (including test doubles and decorators) will fatal until it implements the new skipped-call methods. Check PR #12 for the exact signature before upgrading; this is a minor-version bump with a BC break, so pin ^0.5 if you can't migrate immediately.CostTrackerInterface rather than extending the concrete tracker — it survives upstream class renames and is the cleanest place to add tenant tagging or metrics export.How can I help you explore Laravel packages today?