Download the PHP package nsd7/laravel-ai-meter without Composer

On this page you can find all versions of the php package nsd7/laravel-ai-meter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-ai-meter

Laravel AI Meter

Self-hosted metering and budget enforcement for AI/LLM & agent calls in Laravel. Trace every call, attribute token cost to a user/tenant, see it in a built-in dashboard, and block runaway spend before it happens β€” all in your own app, with no external service.

Think Telescope + a spend governor for your AI calls.

Tests

πŸ“– Documentation Β· Changelog


Why this exists

Shipping AI features is easy; controlling their cost is not. Existing tools make you choose:

Send data to an external service? Built-in dashboard? Enforce budgets? Scope
Langfuse-style tracing Yes (run a second service) Its own ❌ observe only β€”
Budget packages No ❌ (raw table) ⚠️ per-run only per run
Laravel AI Meter No βœ… βœ… block/alert user / tenant / day / month / total

AI Meter is the only option that meters and enforces, self-hosted, with a dashboard, and attributes spend to whoever caused it.

Features

Screenshots

The self-hosted dashboard (Blade + Tailwind, light & dark):

Overview β€” spend today / this month / all-time, spend-over-time, and cost by model, provider & scope:

Budgets β€” every configured budget's live used-fraction, with the alert thresholds marked and over-limit scopes in red:

Calls β€” a filterable call log with CSV / JSON export and per-call detail:

Run trace β€” group an agent's calls under a run and see the whole trace, step by step:

Requirements

Installation

Visit /ai-meter while logged in. Publish the config to customise:

Usage

Record a call

The reliable, version-proof way to meter any provider/SDK:

Record a Prism response

Token usage and model are read straight off the Prism response, so cost is computed for you.

Auto-instrumentation

Laravel AI SDK β€” meter every call automatically, no manual record(). Enable the adapter; the package listens to the SDK's end-of-prompt event:

It reads usage/model defensively (works across SDK versions) and only wires up when enabled and the event class exists β€” so it never affects an app that doesn't use it.

Neuron AI β€” same idea: enable the adapter and it records each inference by listening to the event Neuron dispatches when a call completes.

Usage/model are read off the event's message/response defensively (including getUsage() / getModel() accessors), so it keeps working across Neuron versions and stays dormant until enabled.

Prism has no global event hook, so use the ready-made callback with Prism's ->asText():

Enforce a budget

Config:

Guard a route β€” returns HTTP 402 when the user is over their monthly ceiling:

Or check in code (great for pausing an agent mid-run):

Budget alerts (80% / 100%)

Both block and alert budgets fire a notification the first time a scope's spend crosses a threshold within the budget's window β€” so you hear about a runaway spend as it happens, not after the bill. Point it at an email address and/or a Slack incoming-webhook:

Each threshold alerts once per window (a day budget re-arms tomorrow, a month budget next month), and a single jump past several thresholds sends only the highest. Prefer your own handling? Leave notify empty and listen for the event:

Agent runs (trace + runaway-loop guard)

Wrap an agent loop in a run to group its calls, see the whole trace in the dashboard, and stop a runaway loop before it drains the budget:

Every run shows up under the Runs tab with its step/tool-call count, cost vs. budget, and a per-call trace.

Agent-facing budget API

Enable features.api to expose a read-only "how much budget is left?" endpoint β€” ideal for an SPA, a dashboard, or an AI agent deciding whether it can afford another step:

It runs behind the same middleware and gate as the dashboard. The same data is available in code via Meter::budgetReport($scope) β€” hand it to an MCP tool to let an agent check its own budget.

Configuration

Key options in config/ai-meter.php:

Key Default Description
route.prefix / route.middleware ai-meter / ['web','auth'] Dashboard routing.
gate viewAiMeter Gate checked when defined.
recording.store_io true Persist (redacted) prompt/response text.
recording.redact / max_io_chars true / 8000 Scrub secrets; truncate.
pricing.currency / fx_rate USD / null Display currency + USD→local conversion.
pricing.unknown_model {input:1,output:3} Fallback price per 1M tokens.
pricing.prices [] Override/extend the bundled price book (wins over everything).
pricing.prices_path null App-owned price-book JSON, loaded above the bundled table.
pricing.update.source package book URL Source for ai-meter:update-prices.
budgets [] Spend ceilings (scope, period, limit, action).
spend_store.driver database database (SUM per request) or cache (Redis counters).
prune.keep_days 90 Retention for ai-meter:prune.

High-volume budget enforcement

By default, "how much has this scope spent?" is a SUM of the calls table on each check β€” exact and zero-setup. Apps enforcing budgets on every request can switch to cache counters instead:

The cache driver (CacheSpendStore) increments a Redis (or any cache) counter per scope and period window as each call is recorded, so budget reads are O(1) GETs. Counters reflect spend recorded after the driver is enabled (they aren't backfilled); day/month counters expire with their window. Keep the database driver if you need exact historical aggregation.

Commands

Export the call log. The dashboard's Calls page has CSV / JSON buttons that export exactly what the current filters show. The same is available on the CLI, with filters and a date window:

Without --output it writes to stdout. Metadata columns (tokens, cost, scope, latency, trace/run ids, …) are always included; the prompt/response text and properties are added only with --with-io (or ?io=1 on the dashboard link).

Keep prices current without upgrading the package. ai-meter:update-prices fetches a price book (the package's maintained one by default, or any --source URL / file in the same provider β†’ model β†’ {input, output, cached_input} shape) and merges it into an app-owned file:

Point pricing.prices_path (or AI_METER_PRICES_SOURCE / AI_METER_PRICES_PATH) at that file and it's loaded above the bundled table but below your explicit pricing.prices overrides β€” so a refresh never clobbers your custom prices. Use --replace to overwrite instead of merge.

Roadmap

Testing

License

MIT. See LICENSE.


All versions of laravel-ai-meter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nsd7/laravel-ai-meter contains the following files

Loading the files please wait ...