PHPackages                             logique/ai-usage-monitor-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. logique/ai-usage-monitor-sdk

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

logique/ai-usage-monitor-sdk
============================

Laravel SDK for AI Usage Monitor

v0.3.0(1mo ago)0199↓80%MITPHPPHP ^8.0CI passing

Since Jul 8Pushed 1mo agoCompare

[ Source](https://github.com/Logique-ID/ai-usage-monitor-sdk-laravel)[ Packagist](https://packagist.org/packages/logique/ai-usage-monitor-sdk)[ Docs](https://github.com/Logique-ID/ai-usage-monitor-sdk-laravel)[ RSS](/packages/logique-ai-usage-monitor-sdk/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (5)Versions (7)Used By (0)

AI Usage Monitor — Laravel SDK
==============================

[](#ai-usage-monitor--laravel-sdk)

Laravel SDK for reporting AI usage events to the [AI Usage Monitor](https://YOUR-MONITOR-HOST) ingestion API. Drop-in, non-blocking — your app never slows down or crashes because of monitoring.

Requirements
------------

[](#requirements)

- PHP 8.0+
- Laravel 9, 10, 11, or 12

Getting an API key
------------------

[](#getting-an-api-key)

Each application authenticates with its own key, minted from the Monitor dashboard:

1. Sign in to the Monitor dashboard and open **API keys** in the top nav.
2. Click **Create key**, enter your application slug (lowercase `a-z 0-9 -`, e.g. `my-saas-app`), an optional label, and an optional expiry.
3. The full key (`aum_…`) is shown **once** — copy it immediately. The server stores only a hash and can never display it again; if you lose it, mint a new one.
4. Set it as `AUM_API_KEY` in your app's `.env` (see below). Never commit it.

The `app` you report (see Usage) must match the slug the key was minted for, or the event is rejected with `403`. Rotate by minting a new key, deploying it, then revoking the old one from the dashboard — revoked or expired keys are rejected with `401`.

Installation
------------

[](#installation)

**1. Require the package:**

```
composer require logique/ai-usage-monitor-sdk
```

**2. Publish the config:**

```
php artisan vendor:publish --tag=ai-monitor-config
```

**3. Set environment variables in your app's `.env`:**

```
AUM_ENDPOINT=https://YOUR-MONITOR-HOST/api/v1   # base URL — the SDK appends /events/batch
AUM_API_KEY=your-app-api-key
AUM_APP=my-saas-app                             # must equal the "Application" field the key was minted for
AUM_ENVIRONMENT=production                      # any lowercase slug: production | staging | development | dev | uat | …
AUM_BATCH_SIZE=50
AUM_TIMEOUT=5
```

**`AUM_APP` must be exactly the slug you entered in the *Application* field when creating the key on the Monitor's /api-keys page** — a mismatch rejects every event with `403`. With `AUM_APP` set, `report()` calls may omit `'app'`; an explicit `'app'` param still wins when provided.

The Service Provider and Facade are auto-discovered via Composer — no manual registration needed.

Usage
-----

[](#usage)

```
use Logique\AiUsageMonitor\Facades\AiMonitor;

// After an LLM call completes ('app' defaults to AUM_APP from .env):
AiMonitor::report([
    'service'  => 'ai-conversation', // feature slug — powers the "Usage by service"
                                     // breakdown; slug only: ^[a-z0-9-]+$
    'provider' => 'openai',        // google | openai | anthropic | azure_openai | other
    'model'    => 'gpt-4o',
    'usage'    => [
        'input_tokens'  => 150,
        'output_tokens' => 200,
    ],
]);
```

With optional fields:

```
AiMonitor::report([
    'app'       => 'my-saas-app',
    'provider'  => 'anthropic',
    'model'     => 'claude-3-5-sonnet-20241022',
    'service'   => 'summarizer',                 // sub-component slug
    'operation' => 'chat',                       // chat | completion | embedding | image_generation | audio | other
    'usage'     => ['input_tokens' => 100, 'output_tokens' => 50],
    'status'    => 'error',                       // success (default) | error
    'error'     => ['type' => 'rate_limit', 'message' => 'Rate limit exceeded'],
    'timing'    => ['duration_ms' => 1240],
    'metadata'  => [
        'user_id' => 'u_123',
        'feature' => 'summarize',
    ],
]);
```

`provider` and `model` are required; `app` is required unless `AUM_APP` is set (explicit param wins); `usage.input_tokens` / `usage.output_tokens`default to `0` when omitted. `event_id` (UUID v4), `schema_version`, `timestamp`, and `trace_id`/`span_id` are generated automatically. An invalid payload is dropped (and logged) — `report()` never throws into your application.

Events are buffered in-memory and flushed as async batches — the `report()` call returns immediately. On Laravel app shutdown, any remaining buffered events are auto-flushed.

How it works
------------

[](#how-it-works)

1. `report()` builds a contract-v1 event and adds it to an in-memory buffer
2. When buffer hits `AUM_BATCH_SIZE`, it dispatches a `FlushBufferJob` to your queue
3. The job POSTs the batch to `/events/batch` with retry on 429/5xx (backoff: 5s → 30s → 60s; `Retry-After` honored on 429). A `413` splits the batch and re-dispatches.
4. If Monitor is unreachable, the SDK swallows the error after retries (logged via `Log::warning`) — your app keeps running
5. On app termination, remaining buffer is auto-flushed

**Important:** Ensure a queue worker is running in your app:

```
php artisan queue:work
```

Event Contract
--------------

[](#event-contract)

The SDK sends payloads conforming to [AUM Event Contract v1](../docs/contract/event-schema-v1.md).

- Required from caller: `app`, `provider`, `model` (and `usage.input_tokens` / `usage.output_tokens`, default `0`)
- Auto-set by the SDK: `event_id` (UUID v4), `schema_version` (`"1.0"`), `timestamp` (UTC ISO 8601), `trace_id`/`span_id`, `app` (from `AUM_APP` when omitted), `environment` (from `AUM_ENVIRONMENT`, any lowercase slug), `operation` (default `chat`), `status` (default `success`)
- Content policy: `content` is only sent when `AUM_ENVIRONMENT` is not `production`
- Never sent: `cost` — calculated server-side

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

48d ago

PHP version history (2 changes)v0.1.1PHP ^8.4

v0.2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/555d6db6209b79c06a453bea1455548f43b21a49d2f753756be11c5873c83856?d=identicon)[faishal\_lgq](/maintainers/faishal_lgq)

---

Top Contributors

[![faishallogique](https://avatars.githubusercontent.com/u/99315557?v=4)](https://github.com/faishallogique "faishallogique (6 commits)")

---

Tags

laravelmonitoringaiusageobservabilityllmlogique

### Embed Badge

![Health badge](/badges/logique-ai-usage-monitor-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/logique-ai-usage-monitor-sdk/health.svg)](https://phpackages.com/packages/logique-ai-usage-monitor-sdk)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k113.1M1.0k](/packages/laravel-socialite)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k57.2M688](/packages/laravel-scout)[illuminate/auth

The Illuminate Auth package.

9328.5M1.4k](/packages/illuminate-auth)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M147](/packages/roots-acorn)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
