Set spending limits for an AI agent using x402
By 1YC · Updated September 9, 2026
Wallie is an open-source runtime that checks an allowance before an agent signs a supported x402 payment. Its npm package is allowance-kit, and its source repository is AllowanceKit. Use it when your agent buys individual API responses and you want limits on those purchases.
The buyer supports exact USDC payments on Base and Base Sepolia using x402 v1 or v2. Solana supports exact payments and metered upto channels with escrow and refunds. The public Solana settlement proof is on devnet; see the runnable demo and transaction. The limits apply to calls routed through Wallie. Existing metered LLM-provider and cloud-provider invoices are outside this scope.
Which spending limits can you set?
- Total allowance: the agent can spend up to the smaller of its funded allowance and the configured lifetime budget. This is not a daily budget that resets at midnight.
- Per-payment cap: reject an individual request whose price exceeds your ceiling.
- Spending-rate limit: limit the total spent within a rolling time window to contain repeated purchases.
- Destinations: allow approved host suffixes and block unwanted hosts.
- Human approval: hold purchases above a configured threshold for a decision.
- Kill switch: block the next authorization. It does not reverse settled payments.
Try a $5 allowance with practice money
Use Node.js 20.11 or later and a new, empty directory. These commands use the local practice ledger; they do not fund a real blockchain wallet. Version 0.5.1 is pinned so the example is reproducible.
npx allowance-kit@0.5.1 init npx allowance-kit@0.5.1 topup 5.00 npx allowance-kit@0.5.1 policy totalBudgetUsd 5.00 npx allowance-kit@0.5.1 policy requireApprovalAboveUsd 0.05 npx allowance-kit@0.5.1 policy perCallMaxUsd 0.10 npx allowance-kit@0.5.1 policy windowLimitUsd 1.00 npx allowance-kit@0.5.1 policy windowSeconds 60 npx allowance-kit@0.5.1 status
This allows at most $5 in lifetime purchases, at most $0.10 per payment, and at most $1 in a rolling 60-second window. Requests over $0.05 require approval. The initial destination list permits localhost for the demo; choose your allowed hosts before a live integration.
To see purchases and policy blocks immediately, run the built-in demo. It uses its own .allowance-demo state directory and demonstration policies, separate from the allowance above:
npx allowance-kit@0.5.1 demo
The full tutorial shows how to route requests through payingFetch, read payment and blocked-attempt records, and move from practice money to an explicit live-network setup. Use the same state directory and agent name in the CLI and your application.
What happens if an agent bypasses the runtime?
Wallie only checks payments that pass through its authorization path. Code with access to the wallet environment or policy files can bypass or change those controls. Keep credentials and the wallet runtime separate from untrusted code using your operating system’s access controls. The local JSONL ledger records decisions; it is not a tamper-proof external archive.
Do spending limits require Wallie Cloud?
No. The MIT-licensed runtime and local dashboard work without a subscription. Wallie Cloud is an optional €20-per-month workspace for a shared event feed, email rules, and heartbeat monitoring outside your agent’s machine. Cloud receives events and heartbeats; wallet signing and policy checks stay in your infrastructure.
If the machine stops reporting, Cloud can create a silence event and send email through a configured alert rule. Read how heartbeat alerts work, including the five-minute default silence threshold and the once-per-minute watchdog.
Can this cap my OpenAI or Anthropic API bill?
No. A metered provider account bills usage separately from x402 payments. Wallie does not set a spending limit on that account. Evaluate provider-level billing controls for that requirement.