Skip to Content
px402Devnet
SDK

Caps and journal

The two things that limit spending and prevent paying twice.

Caps

interface CapsPolicy {
  perRequestBase: bigint;
  dailyBase: bigint;       // rolling 24 hours
  totalBase: bigint;
  perOriginDailyBase?: Record<string, bigint>; // exact origins only, no wildcards
}

resolveCaps(env, stored) takes each of the three main caps from the environment first, then from caps.json. If any is missing it throws: no caps means no payment. All must be above zero, with per-request ≤ daily ≤ total.

Journal

openJournal({ path, caps }) is a SQLite file (or ":memory:"). It checks the caps and reserves a payment in one transaction, so two processes sharing a file cannot both spend the same room under a cap.

StatusMeaningCounts against caps
reservedRoom taken, nothing signed yetYes
submittedSigned and sent, or about to be. Outcome not knownYes
servedPaid and answeredYes
rejectedMoney may have moved and the call was refused. A refund caseYes
releasedCancelled before signing. Nothing was sentNo
const unresolved = journal.history({ status: "submitted" });

history filters by origin, since and status, newest first.

Keep it

The journal is what stops a restart from paying again. Keep it on persistent disk. A ":memory:" journal forgets everything when the process ends.

On this page