Skip to content
Code Recycle

Component · for humans & their agents

LLM Spend Cap

verified · first-partyactively maintained$0 during beta (was $49)

A runaway agent does not spend money slowly. This refuses a request before it runs when its worst-case cost breaches a per-request ceiling, and separately stops an organisation breaching a rolling day or month budget.

by ledgerline · Code Recycle moderator

Get it free — beta

Every claim on this page is refundable if it is untrue — refund policy.

Building it yourself: ~2h of agent time across about 4 attempts. Your credits are already paid for, so that feels free — but they are rivalrous: those are hours not spent on the part only you can build. And this one fails quietly when it is wrong, so the attempt that looks finished may not be. $49.

19 tests. Pure functions, zero runtime dependencies, ESM. No I/O — you pass in the token

The bug this exists to prevent

Almost every spend guard is written after the fact: sum what has been spent, and stop when the total is too high. That catches the slow case and misses the expensive one.

The failure that costs real money is a single request that should never have started — a prompt that already contains 400,000 tokens of context, pointed at the most expensive model, with a large max_tokens. By the time it appears in the ledger it has already been paid for. A cumulative cap is a smoke alarm that rings once the house has burned.

The other half is worse because it is invisible: an agent in a retry loop issues requests that are each individually reasonable. Nothing looks anomalous per request. The bill is the only place the loop is visible, and it arrives weeks later.

Rule 1 — price the ceiling, not the average

estimateMaxRequestUsd() costs a request at its maximum: the input tokens already counted, plus the model's full max_tokens of output, each at that model's rate. decidePerRequest() compares that ceiling to your limit and refuses before the call is made.

Estimating the likely cost is the mistake worth avoiding. A request that usually returns 200 tokens and occasionally returns 8,000 is exactly the request that breaches a cap, and averaging prices it as safe every time until it isn't.

Rule 2 — the pricing table is passed in, never duplicated

PriceLookup is a function you supply. This package ships no model prices.

That is deliberate. A second copy of a pricing table is a copy that goes stale — provider changes a rate, one table updates, and the guard now enforces a limit computed from prices that no longer exist. It fails in the safe-looking direction, permitting spend, and nothing reports an error because the arithmetic is still perfectly valid.

approxTokensFromChars() is available for the pre-tokenizer estimate, and it is deliberately rough — the point is refusing a 400k-token request, and no reasonable error in a 4-chars-per-token approximation changes that answer.

Rule 3 — day and month are separate ceilings

decideCumulative() takes the current rolling totals and the pending amount and reports which ceiling would break. resolveOrgCaps() applies defaults where an organisation has none set.

Both windows exist because they fail differently: a day cap contains a loop that started this morning, a month cap contains steady over-use that never trips a daily limit.

What this does NOT do

No counting, no storage, no ledger, no provider calls. It decides; you persist. That is why it is testable without a database, and it is the half that is worth buying — the storage is straightforward and the policy is where the mistakes live.

It does not know your prices. See Rule 2.

Verified

19 tests covering ceiling estimation, per-request refusal at and around the boundary, unknown models, day and month cumulative breaches, and default resolution.

01Capabilities

Does

  • + Budget policies & spending limits
  • + LLM cost alerting
  • + LLM cost accounting

Doesn’t

  • No exclusions declared

02Requirements & stack

Depends on

No declared dependencies

Credentials needed

None declared

Stack

03Community

No endorsements yet

No verified confirmations yet — be the first.

Confirmations come from verified purchasers, installers, vetted reviewers, or an installation outcome your org reported through the agent tools. They grade quality — security is verified separately, and community votes can never override the security gate.

Open an issue

Sign in to confirm — weight comes from verified usage, not vote count.

Nobody has reported anything yet — a success counts as a report too.

04Trust Passport

Full passport →
–/100

0/0 automated components pass. An automated score is never a security guarantee.

✓ Verified · first-partyreviewed Sep 20, 2026 · re-verification due Dec 19, 2026
  • publisher identity Publisher status verified; 1 verification(s) on file
  • malicious pattern scan No known malicious-behavior patterns across 7 source file(s) plus listing text
  • capability contract All 0 observed capability reference(s) match the declared manifest
  • agent safety scan No injection patterns in agent-readable content
  • provenance No release signature or provenance attestation
  • behavioral sandbox Not performed in this environment — requires the production isolated runner (docs/sandbox-requirements.md). No untrusted code is ever executed on the application host.

Every listing must pass this review before it can be sold, and it is re-run on every release. Verification describes what we checked — it is not a guarantee that the software is safe.

VersionChannelReleasedNotes
0.1.0stableAug 11, 2026Initial extraction.