Search by

packstub / credits

icaliman

Credits and usage metering for Laravel: per-user or per-team balances, credits that expire and are spent soonest-expiring first, holds you reserve before an AI call and settle once its cost is known, fractional meters that never round a credit away, plan allowances renewed without a cron, idempotenc

Package info

github.com/packstub/credits

pkg:composer/packstub/credits

Fund package maintenance!

icaliman

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-28 07:33 UTC

This package is auto-updated.

Last update: 2026-10-28 09:56:11 UTC


README

Latest Version on Packagist Tests Total Downloads License Sponsor

Credits for Laravel: a Usage & credits page with the available, held and expiring balances, the lots in the order spends take them, and the ledger with a grant, a spend, its refund, a metered capture and a pending hold

Credits and usage metering for Laravel apps that charge per use: AI features, exports, SMS, API calls. Give each user or team a balance, let plans top it up every month, charge measured usage, and know, at any time, where every credit came from and where it went.

$team->credits()->grant(1_000, 'Pro plan', expiresAt: now()->endOfMonth());

$hold = $team->credits()->hold(200, 'AI turn');          // reserve before the call
$response = $agent->prompt($question);
$hold->settleUsage([                                      // charge what it actually cost
    'ai.input_tokens' => $response->usage->uncachedInputTokens(),
    'ai.output_tokens' => $response->usage->outputTokens,
]);

$team->credits()->available();                            // whole credits; a fraction carries to the next call

Features

Integer credits throughout (pick your scale: 1 credit = 1/1000 of a cent works), no floats, SQLite, MySQL, MariaDB and Postgres.

Compatibility

Credits Laravel PHP
1.x 13.x 8.4+

Installation

composer require packstub/credits
php artisan migrate

Add the trait to whatever holds credits:

use Packstub\Credits\Concerns\HasCredits;

class Team extends Model
{
    use HasCredits;
}

Schedule the catch-up for idle wallets (optional: every wallet catches up when it is used):

Schedule::command('credits:expire')->hourly();

Documentation

Testing

composer test

Security

Report vulnerabilities to security@packstub.dev, not through a public issue: see SECURITY.md, which also lists what to keep on your side of the line (wallets from the authenticated holder, holds and transactions looked up through the wallet, quantities from the provider's response).

License

MIT. See LICENSE.md.