Why AI agents need spending limits

AI agents are starting to pay for things: data, search, compute. The two usual ways to let them are both bad. Give the agent a funded wallet, and one bug, one hostile web page or one leaked key can empty it. Give it API keys, and you manage an account and a bill with every provider. Either way, the only record of what was spent is the agent's own log.

Inspiration

Two things made a better answer possible this year. Solana shipped its Subscriptions and Allowances program, which lets a wallet set a hard spending limit for another key. And x402 lets a seller charge per request, with no account. We wanted to know whether the two work together with real money and real sellers, not on a test network against a merchant we wrote ourselves.

What it does

Petty Cash lets you set aside a small budget in your own Solana wallet for an AI agent. You choose an amount and an expiry. The money stays in your wallet; Solana records a limit for one agent key.

You then give the agent an errand in plain words. It buys what it needs from real third-party companies over x402, in real USDC on Solana mainnet: web search, page reading, market data, weather, news, even its own reasoning, a fraction of a cent at a time. It holds no API keys.

  • Solana enforces the limit, not us. A pull above what is left is refused by the Allowances program, and you can revoke at any time from your own wallet.
  • Every receipt is checked independently. A QuickNode Stream on Solana mainnet reports each transaction that involves the agent's key. A receipt is stamped "verified" only when the Stream's own data matches the seller's quote.
  • Anything above one cent waits for your approval.
  • You can try it with no wallet on a small public demo budget. To set your own budget, you connect a wallet.

See it work

How we built it

  • Onchain: we did not write or deploy a program. The budget is an allowance account in the Solana Foundation's Subscriptions and Allowances program (De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44). We wrote the instruction builders and account readers for it and checked them against the mainnet build of the program in a local validator.
  • Payments: x402 version 2 with the official SDK. For each purchase the server asks the seller for a price, runs a rule check in plain code, builds the payment and checks that it is exactly one USDC transfer of the quoted amount to the quoted recipient. Only then does it pull exactly that price under the allowance and pay. The seller's own facilitator submits the payment.
  • Verification: a QuickNode Stream (Solana mainnet, block dataset, a JavaScript filter on the agent's key) posts to a signed webhook, and receipts are matched against it.
  • Failure handling: a seller's word is not proof. A purchase stays open until our own read of the chain finds that exact payment. If it can never land, the money goes back to the owner, exactly once.
  • App: Next.js, React, TypeScript and Tailwind on Vercel, with Postgres for errands and receipts.

Challenges we ran into

  • Knowing when a payment is dead. At finalized commitment a brand-new blockhash looks exactly like an expired one. Asking that question would have refunded money while a payment could still land. We switched to a block-height rule.
  • Two identical transactions are one transaction. Two refunds with the same amount, wallet and blockhash share one signature, so the chain runs them once. Every pull and refund now carries a unique note.
  • Refund races. Adversarial reviews of the settlement code found ways to refund twice when two workers looked at the same purchase. Every state change is now a compare-and-set.
  • Real sellers behave differently. Some settle with version 1 transactions, one failed with an HTTP 502 after we had sent payment, and public RPC endpoints rate-limit. Each became a handled case.
  • Our own prompt-injection test was hollow at first. The page reader was dropping the hostile text before the model saw it. We fixed the page, confirmed the text reaches the model, and re-ran the test.

Accomplishments that we're proud of

Everything here happened on Solana mainnet with real USDC, and the README links each transaction:

What we learned

  • A spending limit is only worth something if the party being limited cannot change it. Putting it in a program we do not control was the point.
  • A seller saying "paid" proves nothing. Only the chain does, and it has to be read carefully.
  • Safety must not depend on the model behaving. The model can only answer or name a tool from a fixed list; the limits are code and chain state.
  • Test the test. Our first prompt-injection demo looked fine and proved nothing.

What's next for Petty Cash

  • Pay sellers straight from the allowance, so the agent's key never holds money, even for a few seconds.
  • Recurring daily budgets in the interface. The program already supports them.
  • An open delivery record per seller, built only from Stream-verified receipts.
  • A professional security audit before anyone uses larger amounts. Today the code has tests and AI-assisted reviews, not an audit.

Built With

  • github-actions
  • next.js
  • node.js
  • playwright
  • postgresql
  • quicknode
  • quicknode-streams
  • react
  • solana
  • solana-wallet-adapter
  • solana-web3.js
  • spl-token
  • supabase
  • tailwindcss
  • typescript
  • usdc
  • vercel
  • vitest
  • x402
Share this project:

Updates

Submission history