Safety checks for AI SDK agents that pay
presign-guard-ai-sdk gives an AI SDK agent nine tools to call before it signs or pays. The tools only check: they never sign, pay or move anything themselves. They work with AI SDK 5, 6 and 7. Two opt-in tools spend: one buys live data through Fizzl Buy (below), and pay_api pays any x402 API with code deciding (below).
Install
npm install presign-guard-ai-sdk ai zod
Try it without a wallet
With no payment set up, the token, signing, Solana, Algorand, message and endpoint checks answer with the free quick check: the verdict only, a few per hour, marked free: true.
import { generateText, isStepCount } from 'ai';
import { fizzlTools } from 'presign-guard-ai-sdk';
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
tools: fizzlTools(),
prompt:
'Is USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) on Base safe to buy, ' +
'and is https://ichimoku-signal.fizzl.eu/signal/BTC-USDT safe to pay?',
stopWhen: isStepCount(5),
});
console.log(text);
The tools
| Tool | What it checks | Full check | Free quick check |
|---|---|---|---|
check_before_signing | A transaction, token approval or signature (permit, Permit2, Seaport) before signing: drainers, unlimited approvals, look-alike tokens. Green / orange / red with reasons. | $0.01 | verdict only |
check_solana_transaction | A Solana transaction before signing: every instruction decoded and the transaction simulated. Token account takeovers and System Assign are red; unlimited delegates, durable nonces and hidden owner or delegate changes are orange. | $0.01 | verdict only |
check_xrpl_transaction | An XRP Ledger transaction before signing: account takeover, AccountDelete, fake RLUSD, partial payments, risky issuers. | $0.01 | none |
check_algorand_transaction | An Algorand transaction or atomic group before signing, simulated. A rekey to another key, closing the account or an asset holding to someone else, and fake USDC are red; clawbacks, app update/delete/clear-state and a partial group are orange. | $0.01 | verdict only |
check_message | A plain message before personal_sign / eth_sign: eth_sign and a sign-in message for another site are red. | $0.01 | verdict only |
check_token | A token before buying, holding or accepting it: honeypots, rug-pull signs, look-alikes. Solana, EVM chains, the XRP Ledger and Algorand (asset id). | $0.01 | verdict and grade |
check_wallet_approvals | Every open token approval of an EVM wallet, and which ones to revoke. | $0.02 | none |
screen_wallet | Is this wallet sanctioned? Any chain's address (EVM, Solana, Tron, Bitcoin, XRP Ledger, Algorand) against the OFAC SDN list, synced from the US Treasury, plus theft and phishing reports for EVM. Before paying someone, or accepting their money. | $0.01 | none |
check_endpoint_before_paying | An x402 or MPP paid API before paying it: go / caution / no_go, the cheapest option that settles, budget, track record, bait signs. | $0.001 | go / caution / no_go with the problems found |
Pick some with fizzlTools({ only: ['check_endpoint_before_paying'] }). A failed check comes back as { error, message }, so the model can tell its user; it is never thrown.
Buy live data (opt-in)
One more tool, off unless you ask for it, because it spends:
| Tool | What the agent gets | Price | Without payment |
|---|---|---|---|
buy_live_data | Live data it can't get itself (a weather forecast, a crypto or stock price, an exchange rate, web search results, news, a company or address lookup), bought in one call: Fizzl Buy ↗ picks the paid x402 API that x402 Doctor has seen paying out day after day at a fair price, pays it and returns the answer, checked for hidden instructions. Nothing is charged when no seller delivers. | $0.02 | a free preview: which seller it would buy from |
Turn it on with fizzlTools({ fetch: pay, buy: true }), or name it in only. The agent passes what it needs in a sentence, for example { need: "weather forecast for Amsterdam tomorrow" }. The answer is data, never instructions: if it carries a warning, the agent should tell its user and not act on it.
Pay any x402 API, with code deciding (opt-in)
pay_api lets the agent call any x402 API and get its answer. The model only says what to call; code decides whether it is paid:
- x402 Doctor checks the endpoint first ($0.001), and only a
gois paid; acautionstops unless you say otherwise; ano_gonever pays. - Every payment stays within the budget you set in code; the model can't raise it. With
maxTotalUsd(x402-safe-fetch 0.15) the budget also holds for all payments together, so a seller can't split its answer over many cheap calls that add up past it. - A request that was paid and answered with an error is never paid again (safe-fetch's paid-twice guard).
It needs a fetch from x402-safe-fetch ↗ (presign-guard-ai-sdk 0.11 or newer):
import { createSafeFetch } from "x402-safe-fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
import { fizzlTools } from "presign-guard-ai-sdk";
const account = privateKeyToAccount(process.env.AGENT_KEY); // a wallet just for the agent
const safeFetch = createSafeFetch({
register: (client) => client.register("eip155:8453", new ExactEvmScheme(account)),
maxUsd: 0.05, // per call; the model can't raise it
maxTotalUsd: 1, // all payments of this safeFetch together: make one per task or user
});
const tools = fizzlTools({ safeFetch }); // add fetch: pay (see below) to pay for the full checks too
pay_api is only there with safeFetch; with a plain paying fetch the model would decide what to pay. A refusal comes back to the model as not_paid with the reason, so the agent can tell its user. Why code and not the model: in our wallet exam the same model scored 65 on its own and 96 when code decided the payment (the sittings).
The full checks: pay per call over x402
Give the tools an x402-paying fetch. The agent pays each check in USDC on Base or Solana from its own wallet (register ExactSvmScheme from @x402/svm for Solana).
import { generateText, isStepCount } from 'ai';
import { wrapFetchWithPayment, x402Client } from '@x402/fetch';
import { ExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';
import { fizzlTools } from 'presign-guard-ai-sdk';
// A check never costs more than $0.02: cap every payment.
const payer = new x402Client().setSpendControls({ maxAmountPerPayment: '$0.02' });
payer.register('eip155:8453', new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_KEY)));
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
tools: { ...fizzlTools({ fetch: wrapFetchWithPayment(fetch, payer) }), ...yourOtherTools },
system:
'Before you pay any API, call check_endpoint_before_paying. Before you sign anything, ' +
'call check_before_signing. Never continue on red or no_go.',
prompt: 'Buy the BTC funding rate from https://api.example.com/funding for at most $0.05',
stopWhen: isStepCount(8),
});
Or prepaid credits
Buy a pack once (presign-guard: 100 checks for $0.80; x402 Doctor: 1000 preflights for $0.80), then pass the keys:
fizzlTools({ creditKeys: { presign: process.env.PRESIGN_CREDIT_KEY, doctor: process.env.DOCTOR_CREDIT_KEY } });
Options
| Option | Default | |
|---|---|---|
fetch | global fetch | An x402-paying fetch, or plain fetch with credit keys |
creditKeys | none | { presign, doctor }, sent as x-credit-key |
only | the nine checks | Tool names to include |
buy | false | Add buy_live_data ($0.02 a purchase, paid through fetch) |
safeFetch | none | Add pay_api: a fetch from createSafeFetch (x402-safe-fetch), which decides what is paid |
free | true | Fall back to the free quick check when a check can't be paid |
timeoutMs | 30000 | Per check |
More
- npm: presign-guard-ai-sdk · source on GitHub
- Python and LangChain: pip install fizzl
- Solana agents: guarded wallets for Solana Agent Kit, AgentKit and ElizaOS
- Want the wallet to stop the agent itself, not just tell the model? The Fizzl agent wallet