Wraps each AI call to record model, tokens and cost in a ledger collection, and refuses calls when a run, job, day or month cap is reached. It pauses all calls when prepaid credits run out, probes hourly to resume, and sends one notice per run-out. Requires Payload 3.80 or newer and MongoDB; ships Anthropic prices and a provider adapter.
AI Budget for Payload: a ledger of every AI API call's tokens and cost, budgets per job, day and month that stop a job cleanly, and a clear pause when prepaid credits run out.
Installation
npm i @extantape/payload-plugin-ai-budget0
Stars
0
Forks
1
Open Issues
3 days ago
Last Updated
356
Weekly Downloads
v0.1.1
npm Version
45.4 KB
Unpacked Size
0
Dependencies
00 since Nov 8
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
341+341 since Nov 14
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 341 |
| Dec 5, 2026 | 327 |
| Dec 4, 2026 | 307 |
| Dec 3, 2026 | 280 |
| Dec 2, 2026 | 247 |
| Dec 1, 2026 | 23 |
| Nov 30, 2026 | 27 |
| Nov 29, 2026 | 28 |
| Nov 28, 2026 | 27 |
| Nov 27, 2026 | 28 |
| Nov 26, 2026 | 25 |
| Nov 25, 2026 | 27 |
| Nov 24, 2026 | 33 |
| Nov 23, 2026 | 41 |
| Nov 22, 2026 | 256 |
| Nov 21, 2026 | 253 |
| Nov 20, 2026 | 250 |
| Nov 19, 2026 | 250 |
| Nov 18, 2026 | 246 |
| Nov 17, 2026 | 233 |
| Nov 16, 2026 | 221 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1456393913-root)<a href="https://payloaddirectory.dev/plugins/1456393913-root"><img src="https://payloaddirectory.dev/badge/1456393913-root.svg" alt="Payload Directory"></a>README
AI Budget for Payload: a ledger of every AI API call's tokens and cost, budgets per job, day and month that stop a job cleanly, and a clear pause when prepaid credits run out.
Status: 0.1.1 is the latest release (see CHANGELOG.md). 44 tests pass against Payload 3.92 with an in-memory MongoDB replica set, using fake answers shaped like Anthropic's (no real API is called) and a stand-in for the Notifications plugin. They cover the prices, the ledger and what it leaves out, every cap, fail-closed reads, the credits-out pause and probe, which errors count as a run-out, the notice and its fallbacks, the auto-reload suggestion, the summary and access, signed-out visitors included. No site uses it yet.
withAiBudget(payload, { job, run }, call) wraps each AI call.
UnknownJob), so nothing spends outside the budget by accident;BudgetSpent, with which cap): this run, this job today, everything today, everything this month. The tightest wins;CreditsOut).recordUsage(payload, { job, run, batch }, results). Batch result entries ({ result: { message } }) are read as they come. For a stream, record its final message.BudgetSpent, saves what it has done, and stops. Don't retry.anthropicPrices (2026-11-10) ships as data.
costOf is exported, so another tool can recompute and compare.usageOf(answer) and isNoCredit(error). anthropicProvider reads answers by shape, with no SDK. Another provider is a few lines.CreditsOut);probeJob (any job, if you don't name one) is let through to see if they're back, and only one worker probes at a time;notify), else your onCreditsOut.maxSuggestionUSD. The plugin never sets anything up.spendSummary(payload), for a spend card:
onCreditsOut, the run-out is logged as an error and the plugin warns at start-up. Give one of them.seeded: true shows in the summary and never counts toward a cap, so a seeded month can't refuse a real run on a test site.access.manage, required; only an answer of exactly true counts). Nobody writes it through the API.On its own: wrap each AI call in withAiBudget, and give it caps, a price table, a provider and access.manage. Without Notifications, the credits-out notice goes to your onCreditsOut. It doesn't depend on any other plugin.
Needs: Payload ^3.80.0 as a peer dependency. No other EXTANT APE plugin is required.
Works with:
ai-budget:credits-out kind through config.custom.notificationKinds and sends the notice to the accounts in notify through config.custom.notifications.notify.Color Theory: none needed. It has no screens of its own, and its collections use Payload's standard admin, which takes Color Theory's admin colors when its applyToAdmin option is on.
Family: none yet. The plugin families are a working draft, and AI Budget isn't in it.
npm install @extantape/payload-plugin-ai-budget
import { aiBudgetPlugin, anthropicPrices, anthropicProvider, withAiBudget, BudgetSpent } from '@extantape/payload-plugin-ai-budget'
aiBudgetPlugin({
caps: { month: 15, day: 1.5, jobs: { translate: { run: 1, label: 'Translation' }, watch: { day: 0.25 } } }, // USD
prices: anthropicPrices,
provider: anthropicProvider,
access: { manage: ({ req }) => req.user?.role === 'admin' }, // required
probeJob: 'watch',
notify: [ownerAccountId],
})
try {
const answer = await withAiBudget(payload, { job: 'translate', run: runId }, () => anthropic.messages.create({ … }))
} catch (e) {
if (e instanceof BudgetSpent) { await saveProgress(); return }
throw e
}
Caps, the price table and the suggestion ceiling are checked at start-up: no negatives, missing prices or job caps above the month. Job names are matched exactly, so constructor isn't a job.
recordUsage settles the create's unpriced record and skips results that errored, expired or were canceled.anthropicProvider that's a 402, a 4xx whose type is billing_error, or a 400 invalid_request_error whose message says the credit balance is too low. A 5xx, a network error, or an error thrown without a status and the response body fails as an ordinary error and is recorded as one, whatever its message says. If a provider changes its status, type or wording, a real run-out is recorded the same way, so check the ledger's error records after a provider change.npm test # integration tests, in-memory MongoDB
npm run typecheck
npm run build
MIT. See LICENSE.
audit fields
Adds createdBy and lastModifiedBy fields to Payload collections and globals
922.3k/wk115v4
activity log
Record create, update and delete activity on selected collections and globals in a dedicated log collection
87639/wk115v4
payload hooks
Identifier-only audit logging hooks for Payload collections, plus a helper to run callbacks after transaction commit
77225/wk3v3
payload plugin audit trail
Hash-chained audit trail recording which fields changed, by whom and how, without storing values
74157/wk0v3
payload plugin audit log
Append-only audit log of document, global and auth changes with CSV and NDJSON export
72394/wk37v3
audit logs
Read-only audit trail of create, update, delete and login events with field-level diffs and sensitive-field redaction
67660/wk0v3