spend-meter is a WordPress plugin for sites that call language, embedding, image or speech models through several plugins. It records every call (tokens, cost, purpose, caller) and answers one question before each call: may this spend? The code is at https://github.com/IndianOpinion/spend-meter, licensed MIT. Version v0.1.0 was released on 15 November 2026.
We wrote it from scratch from an idea, not from any third-party plugin. It has not run on a live site. The 47 utilities in this series were specified, built, reviewed and released between 11 and 19 November 2026 by language-model coding agents under the editor’s direction, in five roles: a spec writer, a spec reviewer, a builder that saw only the spec, an independent code reviewer and a releaser. The editor made the rulings on every open question.
WordPress does not say how much model calls cost, on what, or when to stop. The PRD lists what goes wrong without a shared meter:
as_of date and a source on every row.input_tokens and prompt_tokens families).wp spend-meter command set (status, report, check, caps, kill, prices, reprice, reservations, export, prune).A caller plugin never depends on spend-meter. It asks through a filter and records through an action, and keeps its own cap and kill switch for when the meter is absent.
$decision = apply_filters('spend_meter_pre_spend', null, [
'purpose' => 'summary',
'caller' => 'my-plugin',
'provider' => 'example-provider',
'model' => 'example-model',
'est_input_tokens' => 1200,
'max_output_tokens' => 400,
]);
if (null === $decision) {
// No meter present: use your own cap and kill switch.
} elseif (true !== $decision['allowed']) {
return;
}
Inside, Decision runs the check in order: global kill switch, purpose kill switch, intent validation, ledger readiness, price and estimate, then the caps. A Ledger class does recording. The reservation step is the core of the design. An allowed check writes a reserved row holding the estimate before it reads the totals. Two processes racing near a cap each see the other’s reservation, so both may be denied but neither overshoots. A false deny costs one retried call. An overshoot costs money.
Money is integer nanos (one billionth of the currency unit) everywhere. Prices are decimal strings converted with integer arithmetic, never floats. The cost of a recorded call comes from the first source that applies: the provider’s reported cost, tokens priced from the table, the reservation estimate when no usage came back, or zero marked unpriced. When both a provider cost and a table cost exist, both are stored, so drift between list and billed price shows in reports.
A record settles its reservation in place. A second record on the same reservation (a retry) becomes a linked row. A record with no live reservation is inserted flagged unreserved, because the money was spent.
ledger_unavailable. A decision filter that throws denies with decision_filter_error.spend_meter_decision filter can add denials. An attempt to turn a deny into an allow is ignored and logged.meta is limited to eight short scalar values.The independent code review found and fixed these before the merge:
unpriced_model by default.There are no open issues. This is v0.1.0, tested on stubs, mocks and a throwaway MySQL 8.0 server: 173 PHPUnit tests, 6 of them integration tests against that server. Static analysis and code style checks passed. CI has not yet run on GitHub: the commit adding the workflow stayed local because the token lacked the workflow scope.
It needs PHP 8.1 or later, WordPress 6.4 or later, and MySQL 5.7+ or MariaDB 10.4+. There is no Composer requirement at runtime.
The package is not on Packagist yet, so a Composer install needs a vcs repository entry for https://github.com/IndianOpinion/spend-meter first.
composer require indianopinion/spend-meter
wp spend-meter caps set site --day=<amount> --month=<amount>
wp spend-meter prices import my-prices.json --dry-run
Without Composer, unzip a release into wp-content/plugins/spend-meter/ and activate it. A must-use loader is in examples/.