- How do I install nsd7/laravel-ai-meter in a Laravel application?
- Install the package with Composer by requiring nsd7/laravel-ai-meter in your project. Then publish the package's config and database migrations and run php artisan migrate so the metering tables exist. After that you record AI calls through the package facade and the requests, tokens, and estimated costs are logged to your own database. Check the README for the exact publish tags and facade namespace used by the current release.
- Which Laravel and PHP versions does laravel-ai-meter support?
- The authoritative version constraints are declared in the package's composer.json on the repository and on its Packagist page. Before installing, compare those requirements against the Laravel and PHP versions your application runs. Because it is a standard Composer package with migrations and a facade, it follows normal Laravel package conventions, but you should still confirm compatibility for older framework versions rather than assuming support.
- How does laravel-ai-meter track token usage and estimated AI costs?
- You record each AI or agent call through the package's simple facade, passing along details such as the provider, model, token counts, and the user or feature the call belongs to. The package writes that record to your database and calculates an estimated cost from the token usage, so you get per-request cost attribution rather than a single monthly bill. Because you supply the token numbers, it works even when a provider's response format or SDK differs. The result is a queryable trace history you can aggregate by user, model, or feature.
- Does laravel-ai-meter require an external service or send my data anywhere?
- No. The package is self-hosted: traces, token counts, costs, and budget limits are stored in your own application database, and the dashboard is served from your Laravel app. There is no third-party metering account, API key, or data pipeline to configure. That makes it a good fit for teams with data residency or vendor-approval constraints. You remain responsible for your normal database backups and access controls.
- How do multi-scope spend limits and budget enforcement work?
- The package lets you define spend limits at more than one scope, so you can cap usage per user, per model, or per feature instead of relying on a single global number. Recorded requests are checked against those limits so you can identify or block calls that would exceed the budget. The exact configuration keys and the enforcement behavior are documented in the README, so review them before relying on limits in production. A common pattern is a generous global ceiling plus tighter per-user limits.
- Can I break down AI spend by user, model, or feature?
- Yes. Cost and token attribution is a core feature: each logged request carries the context you attach to it, such as the user ID, model name, or feature label. You can then query or view that data in the built-in dashboard to see which users, models, or product areas are driving spend. This is typically the fastest way to spot an expensive prompt or a runaway agent loop. Keep your attribution keys consistent so reports stay comparable over time.
- Does laravel-ai-meter work with multiple AI providers like OpenAI, Anthropic, or custom agents?
- The package is designed for metering AI usage across providers, and because you log usage explicitly through the facade, the metering layer itself is provider-agnostic. You can record calls from OpenAI, Anthropic, local models, or your own agent pipelines as long as you can supply the model name and token counts. Any provider-specific auto-instrumentation or integrations are listed in the README. That explicit approach keeps the package stable even when provider SDKs change.
- How do I test AI metering and budget limits without spending real money?
- Because metering happens through a facade and database logging, you can call it directly in tests with synthetic token and cost values instead of hitting a real provider. Use Laravel's database testing helpers, such as RefreshDatabase, and assert that the expected metering rows and limit checks occur. For the AI call itself, fake or stub your provider client so no network requests are made. This lets you verify budget enforcement logic in CI at zero cost.
- How should I secure the built-in dashboard in production?
- The dashboard is served by your own Laravel application, so protect it with the same mechanisms you use for other internal pages, such as auth middleware or a gate that restricts access to administrators. Avoid leaving the dashboard routes publicly reachable, since the data reveals usage patterns and spend. Review the package's route and middleware configuration options in the README. If you need stronger separation, you can also restrict the routes by environment or IP.
- How is laravel-ai-meter different from hosted LLM observability tools like Helicone or Langfuse?
- Hosted observability platforms usually sit as a proxy or SDK that ships your prompts and usage data to their infrastructure. laravel-ai-meter keeps everything inside your Laravel app and database, with no external service, and focuses on metering, cost attribution, and budget enforcement rather than deep prompt-level tracing. That means fewer moving parts and simpler vendor review, but you own the storage and retention. If you mainly need spend control per user, model, or feature, the self-hosted approach is often enough.