PHPackages                             hikuroshi/rate-budget - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hikuroshi/rate-budget

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hikuroshi/rate-budget
=====================

A multi-key quota decision engine for RPM, TPM, and RPD-aware routing.

v1.0.0(2w ago)00MITPHPPHP &gt;=8.1

Since May 25Pushed 2w agoCompare

[ Source](https://github.com/Hikuroshi/rate-budget-php)[ Packagist](https://packagist.org/packages/hikuroshi/rate-budget)[ Docs](https://github.com/hikuroshi/rate-budget-php)[ RSS](/packages/hikuroshi-rate-budget/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

hikuroshi/rate-budget
=====================

[](#hikuroshirate-budget)

A multi-key quota decision engine for RPM, TPM, and RPD-aware routing.

`hikuroshi/rate-budget` selects an active key within a scope such as a tenant, workspace, project, user, or guild. Each key has independent RPM, TPM, and RPD limits, so your application can safely move to another key when one key is cooling down, under token pressure, or near its daily quota.

The package is lightweight, dependency-free, and storage adapter friendly. Your application owns the state; `hikuroshi/rate-budget` only computes quota decisions and records reservations through the configured adapter.

Install
-------

[](#install)

```
composer require hikuroshi/rate-budget
```

Core Algorithm
--------------

[](#core-algorithm)

RPM: spacing-based cooldown.

```
cooldownMs = ceil(60000 / rpm) + bufferMs
```

TPM: sliding 60-second token window.

```
usedTokensLast60s + estimatedRequestTokens
