TollWarden is a payment security firewall for x402 micropayments. Agents that pay for APIs and data over x402 get drained in predictable ways, through payments triggered by prompt-injected content, replayed authorizations, inflated prices, secrets leaking through payment metadata, lookalike tokens, and address poisoning. @tollwarden/ai-sdk gives a Vercel AI SDK agent an allow / flag / block verdict on every payment before it settles, plus an onStepFinish handler that makes TollWarden's strongest detector work automatically.
npm install @tollwarden/ai-sdk
import { generateText } from "ai";
import { TollWardenClient } from "@tollwarden/client";
import { tollwardenTools, tollwardenProvenance } from "@tollwarden/ai-sdk";
const tollwarden = new TollWardenClient({ agentId: "my-agent" }); // free API key auto-minted (100 free scans)
await generateText({
model,
tools: { ...tollwardenTools(tollwarden), ...yourOtherTools },
onStepFinish: tollwardenProvenance(tollwarden),
prompt: "...",
});
TollWarden's strongest check catches payments whose decision came from content the agent just read (a prompt-injected page or tool result). tollwardenProvenance returns an onStepFinish handler that observes every tool result the step produced automatically, so the next scan is provenance-tagged and that check runs with real input. No prompt engineering required. TollWarden's own tool results are excluded so verdicts never pollute the signal. It reads both the current toolResults[].output shape and the older .result shape, and works the same under streamText.
tollwarden_scan_payment screens a payment before your agent settles it (direction: "outgoing") or before it pays a received 402 offer (direction: "incoming"). Returns allow / flag / block with per-check reasons and an Ed25519-signed verdict. Pass read content as content to enable injection detection.tollwarden_check_reputation checks community reports on a counterparty wallet before dealing with it.tollwarden_report_counterparty reports a bad counterparty (always free) to warn other agents.import { guardedPayment } from "@tollwarden/ai-sdk";
const safePay = guardedPayment(executeX402Payment, tollwarden);
const { result } = await safePay(payment, expectedPriceUsd);
// throws TollWardenBlockedError on a block verdict; the executor is never called
For wallet-level enforcement (the signer itself refuses unscanned payments), see wrapFetchWithTollWarden and TollWardenEnforcer in the @tollwarden/client SDK.
langchain-tollwardencrewai-tollwardenagentkit-tollwardennemo-tollwarden