Buyer SDK
A small buyer-side client: resolve a task to a tool with find(), then call() it with payment handled. Results are cached, spend is capped before anything is sent, and every send carries an Idempotency-Key that is stable per client and operation. Zero dependencies for the free tier.
Install
npm install agent402-client @x402/fetch @x402/core @x402/evm viem
Example
import { Agent402 } from "agent402-client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const payClient = new x402Client();
registerExactEvmScheme(payClient, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, payClient);
const a = new Agent402({ fetch: payFetch }); // https://agent402.tools, paying from the wallet
// web search, then a cited answer: each call paid on its own
const found = await a.call("search", { q: "x402 payment protocol adoption", count: 5 });
const answer = await a.call("answer", { q: "what is the x402 payment protocol?" });
console.log(found.results, answer.answer, answer.citations);
const matches = await a.find("extract the article from a url");
// [{ slug: "extract", route, price, inputSchema, example, ... }]
No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown, JSON and more) run free with proof-of-work and no wallet:
const free = new Agent402(); // no fetch: pure-CPU tools pay with proof-of-work
const out = await free.call("hash", { text: "hello world", algo: "sha256" });
console.log(out.hex);
What it exposes
find(task): the best-matching tools with route, price, input schema and example.call(slug, params): runs the tool and returns its JSON, paying as needed.maxPerCallUsd,dailyLimitUsdandmaxPerHostUsdspend caps, with reservations so concurrent calls cannot overspend.topSellers()and the network helperswithNetworkPreference/withPayeeAllowlistfor an x402 client.
How payment works
- Free pure-CPU tools: built-in proof-of-work, no wallet.
- Wallet-only tools: pass a payment-aware
fetch. A stockmppxfetch pays over MPP (USDC on Base or Celo, or natively on Tempo); an@x402/fetchfetch pays over x402. creditsKey: a credits key bought earlier (a402_...) pays from its balance, debited only on a 200.
import { Fetch, evm, tempo } from "mppx/client";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.AGENT_KEY);
const mppFetch = Fetch.from({ methods: [tempo.charge({ account }), evm.charge({ account })] });
const a = new Agent402({ fetch: mppFetch, maxPerCallUsd: 0.05 });
const verdict = await a.call("sql-guard", { sql: "UPDATE users SET plan = 'pro' WHERE id = 42" });
A call that fails is not charged: settlement runs after the tool and only on a successful response. Background: Pay-per-call APIs · Agent payments.
Tools to try first
Every tool, price and input schema: the catalog.
Links
agent402-client on npm · source on GitHub
Guides: Make your AI agent pay for what it needs: x402 in 5 minutes · x402 and MPP on the same paywall: one server, two payment protocols
All integrations