Skip to content

trystub

trystub

A drop-in budget gate for AI agents that spend real money: paid APIs, x402 micropayments, LLM tokens. One enforceable budget in front of the whole fleet, with an exact double-entry record of every agent's spend. Uses a reserve → pay → settle flow so irreversible payments fire exactly once, even under retries or crashes.

0dependencies
payment guarantee
100%spend attributable

Problem

Autonomous agents spend real money on paid APIs, x402 micropayments, and LLM tokens, and nothing enforces a ceiling. A retry loop or a runaway sub-agent can burn a budget before any human notices, and payments are irreversible once fired.

Approach

  • Put one enforceable budget gate in front of the whole fleet instead of per-agent limits that drift apart.
  • Designed a reserve → pay → settle flow so irreversible payments fire exactly once, even under retries or crashes.
  • Built meterLLM to price OpenAI- and Anthropic-shaped usage without shipping stale price tables.
  • Added idempotency keys so retries are safe across the fleet, plus operator sweep and shard provisioning for sustained throughput.

Outcome

A drop-in npm package (zero dependencies) that gives operators a single, auditable budget boundary with an exact double-entry record of every agent's spend.

Architecture

The reserve → pay → settle lifecycle. Irreversible payment only fires after a successful reserve; settlement is idempotent.fig. 01
const reservation = await stub.reserve({
  agentId, amount, idempotencyKey,
});
if (!reservation.ok) throw new BudgetExceeded();

const receipt = await pay(reservation);

await stub.settle({
  reservationId: reservation.id,
  receipt,            // safe to retry
});
typescript

Highlights

  • Reserve → pay → settle exactly-once flow, so irreversible payments fire once even under retries or crashes.

  • meterLLM prices OpenAI- and Anthropic-shaped usage without shipping stale price tables.

  • Idempotency keys make retries safe across the whole agent fleet.

  • Operator sweep and shard provisioning for sustained throughput.

Stack

  • TypeScript
  • AWS
  • Aurora DSQL
  • x402
  • Large Language Models