PHPackages                             ajooda/laravel-ai-metering - 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. ajooda/laravel-ai-metering

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

ajooda/laravel-ai-metering
==========================

AI usage metering and billing for Laravel apps (tokens, quotas, credits, billing).

v1.0.0(5mo ago)312[1 PRs](https://github.com/ajooda/laravel-ai-metering/pulls)MITPHPPHP ^8.1CI passing

Since Dec 10Pushed 2mo agoCompare

[ Source](https://github.com/ajooda/laravel-ai-metering)[ Packagist](https://packagist.org/packages/ajooda/laravel-ai-metering)[ RSS](/packages/ajooda-laravel-ai-metering/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

Laravel AI Metering
===================

[](#laravel-ai-metering)

[![Latest Version](https://camo.githubusercontent.com/4701d7692e5f16ae47b2e910bf16c9f3b24996b2a652f19d6477b7fb40f76b75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616a6f6f64612f6c61726176656c2d61692d6d65746572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ajooda/laravel-ai-metering)[![Total Downloads](https://camo.githubusercontent.com/938a7cf4cdc6c0b098c779477db83f3461833ad42d54b799b6c493a613c8682b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616a6f6f64612f6c61726176656c2d61692d6d65746572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ajooda/laravel-ai-metering)[![License](https://camo.githubusercontent.com/808ae8c0938c75520f3c2b28d7186d833602d3182a98ac097c0f1fc935bde59d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616a6f6f64612f6c61726176656c2d61692d6d65746572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ajooda/laravel-ai-metering)[![PHP Version](https://camo.githubusercontent.com/7b87292a1d2af59c063ec6b311201ec9670f74e3794c13c4698a7a51ad29cf3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3737374242342e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/b6c6fc0ff2b3f9f6ce91d9df8adb8719bd12e8f9b593c36584e76e2a5eabd293/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d4646324432302e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![Stability](https://camo.githubusercontent.com/1cf378d574fdb63d2c0f4d89cb19d1c8fa0080ab98d15713363abc796ad9b2d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d737461626c652d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ajooda/laravel-ai-metering)[![Documentation](https://camo.githubusercontent.com/09e816ae34b01c0a0c356178a99f4041e3c82696002ef2dd521eb5b0f16c6ace/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d617661696c61626c652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](docs/)

**Usage metering, quotas, and billing for AI applications.**

A production-ready Laravel package that automatically tracks AI usage, enforces quotas, and integrates with Stripe for billing. Perfect for SaaS applications that need to meter and bill AI usage.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Why Choose This Package?](#why-choose-this-package)
- [Requirements](#requirements)
- [Quick Start](#quick-start)
    - [Installation](#installation)
    - [Usage Example](#usage-example)
- [Documentation](#documentation)
- [Quick Links](#quick-links)
- [Contributing](#contributing)
- [License](#license)
- [Support](#support)

Features
--------

[](#features)

- 🎯 **Simple Developer Experience** - Fluent API for metering AI usage
- 📊 **Usage Tracking** - Automatic token and cost tracking
- 🚦 **Quota Management** - Configurable limits (tokens, cost, per-plan, per-tenant)
- 💳 **Billing Integration** - Stripe/Cashier support with credit-based and subscription modes
- 🏢 **Multi-Tenancy** - Works with or without tenancy packages
- 🔌 **Provider Agnostic** - Support for OpenAI, Anthropic, and custom providers
- ⚡ **Performance** - Caching, queue support, and optimized queries

Why Choose This Package?
------------------------

[](#why-choose-this-package)

- **Zero Configuration Required** - Start tracking usage immediately, no plans or subscriptions needed
- **Production Ready** - Battle-tested with comprehensive test coverage and security features
- **Automatic Processing** - Automatic usage extraction, cost calculation, and billing integration
- **Flexible Billing** - Support for both subscription-based and credit-based billing models
- **Multi-Tenant Ready** - Built-in support for multi-tenant applications without coupling to specific packages
- **Extensible** - Easy to add custom providers, billing drivers, and tenant resolvers
- **Well Documented** - Comprehensive documentation with examples and troubleshooting guides

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

[](#requirements)

- PHP &gt;= 8.1 (PHP &gt;= 8.2 for Laravel 11.x and 12.x)
- Laravel 10.x, 11.x, or 12.x
- Database (MySQL, PostgreSQL, SQLite, or SQL Server)

### Version Compatibility

[](#version-compatibility)

Laravel VersionPHP VersionPackage VersionStatus10.x&gt;= 8.1^1.0✅ Supported11.x&gt;= 8.2^1.0✅ Supported12.x&gt;= 8.2^1.0✅ Supported### Optional Dependencies

[](#optional-dependencies)

- **OpenAI**: `openai-php/laravel` (for OpenAI provider)
- **Anthropic**: `anthropic-php/sdk` (for Anthropic provider)
- **Stripe/Cashier**: `laravel/cashier` (for Stripe billing integration)

Quick Start
-----------

[](#quick-start)

> **Note**: This package supports Laravel Package Auto-Discovery, so you do not need to manually register the service provider.

### Installation

[](#installation)

```
# 1. Install the package
composer require ajooda/laravel-ai-metering

# 2. Publish and run migrations
php artisan vendor:publish --tag=ai-metering-migrations
php artisan migrate

# 3. Verify installation
php artisan ai-metering:validate
```

### Usage Example

[](#usage-example)

**Full Example** - Complete usage with all options:

```
use Ajooda\AiMetering\Facades\AiMeter;
use OpenAI\Laravel\Facades\OpenAI;

$response = AiMeter::forUser(auth()->user())
    ->billable(auth()->user())
    ->usingProvider('openai', 'gpt-4o-mini')
    ->feature('chat')
    ->call(function () {
        return OpenAI::chat()->create([
            'model' => 'gpt-4o-mini',
            'messages' => [
                ['role' => 'user', 'content' => 'Hello!'],
            ],
        ]);
    });

// Access the AI response
$aiResponse = $response->getResponse();

// Check usage
$usage = $response->getUsage();
echo "Tokens: {$usage->totalTokens}, Cost: \${$usage->totalCost}";
```

**Minimal Example** - Just track usage:

```
use Ajooda\AiMetering\Facades\AiMeter;

$response = AiMeter::forUser(auth()->user())
    ->billable(auth()->user())
    ->usingProvider('openai', 'gpt-4o-mini')
    ->call(fn() => OpenAI::chat()->create([...]));

$usage = $response->getUsage();
```

**That's it!** Usage is automatically tracked. No plans or subscriptions required for basic tracking.

Documentation
-------------

[](#documentation)

Comprehensive documentation is available in the [`docs/`](docs/) directory:

- **[Overview](docs/overview.md)** - What this package does and when to use it
- **[Installation](docs/installation.md)** - Detailed installation and setup guide
- **[Configuration](docs/configuration.md)** - All configuration options explained
- **[Usage Guide](docs/usage.md)** - Common usage flows and examples
- **[Features](docs/features/)** - Detailed feature documentation
    - [Plans &amp; Quotas](docs/features/plans-and-quotas.md) - Setting up usage limits
    - [Credits](docs/features/credits.md) - Credit-based billing
    - [Billing Integration](docs/features/billing.md) - Stripe/Cashier integration
    - [Multi-Tenancy](docs/features/multi-tenancy.md) - Multi-tenant usage tracking
    - [Periods](docs/features/periods.md) - Period configuration
- **[Advanced Topics](docs/advanced.md)** - Extensibility, customization, events, hooks
- **[API Reference](docs/api-reference.md)** - Complete API documentation
- **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions

Quick Links
-----------

[](#quick-links)

### Common Tasks

[](#common-tasks)

- [Setting up plans and quotas](docs/features/plans-and-quotas.md)
- [Credit-based billing](docs/features/credits.md)
- [Stripe integration](docs/features/billing.md)
- [Multi-tenant setup](docs/features/multi-tenancy.md)
- [Using middleware](docs/usage.md#using-middleware)
- [Querying usage](docs/usage.md#querying-usage)

### Artisan Commands

[](#artisan-commands)

```
# Generate usage report
php artisan ai-metering:report

# Cleanup old usage records
php artisan ai-metering:cleanup

# Sync Stripe overages
php artisan ai-metering:sync-stripe-overages

# Validate configuration
php artisan ai-metering:validate

# Migrate plan
php artisan ai-metering:migrate-plan "App\Models\User" 1 "pro-plan"

# List plans
php artisan ai-metering:sync-plans
```

See [API Reference](docs/api-reference.md#artisan-commands) for complete command documentation.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

### Quick Start for Contributors

[](#quick-start-for-contributors)

1. **Fork and clone the repository**:

    ```
    git clone https://github.com/ajooda/laravel-ai-metering.git
    cd laravel-ai-metering
    ```
2. **Install dependencies**:

    ```
    composer install
    ```
3. **Run tests**:

    ```
    composer test
    ```
4. **Run tests with coverage**:

    ```
    composer test-coverage
    ```

See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

Support
-------

[](#support)

### Getting Help

[](#getting-help)

- 🐛 **Bug Reports**: [Open an issue](https://github.com/ajooda/laravel-ai-metering/issues)
- 💬 **Questions**: [GitHub Discussions](https://github.com/ajooda/laravel-ai-metering/discussions)
- 📖 **Documentation**: [Full Documentation](docs/)
- 🔒 **Security Issues**: Email **** or see [SECURITY.md](SECURITY.md)

### Maintainers

[](#maintainers)

**Primary Maintainer**: AbdAlhadi Jouda ()

**Response Times**:

- Security vulnerabilities: 48 hours initial response
- Bug reports: 3-5 business days
- Questions: 5-7 business days
- Feature requests: As time permits

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance80

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Unknown

Total

1

Last Release

153d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ddf468e0a9d93bd4158d7b710aee484f849565653997da49862aa98b9dbb3f6?d=identicon)[ajooda](/maintainers/ajooda)

---

Top Contributors

[![ajooda](https://avatars.githubusercontent.com/u/214831202?v=4)](https://github.com/ajooda "ajooda (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

ai-meteringanalyticsanthropicbillingcost-trackingcreditslaravellaravel-cashierlaravel-packagemeteringmonitoringmulti-tenantopenaiphpquotasstripesubscriptionstoken-trackingusage-analyticsusage-trackinglaravelbillingaiopenaianthropicmeteringusage-tracking

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ajooda-laravel-ai-metering/health.svg)

```
[![Health](https://phpackages.com/badges/ajooda-laravel-ai-metering/health.svg)](https://phpackages.com/packages/ajooda-laravel-ai-metering)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)

PHPackages © 2026

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