Buyer SDK

agent402-client · npm · MIT

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

Example

import { Agent402 } from "agent402-client";

const a = new Agent402();   // https://agent402.tools

const matches = await a.find("extract the article from a url");
// [{ slug: "extract", route, price, inputSchema, example, ... }]

const out = await a.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, dailyLimitUsd and maxPerHostUsd spend caps, with reservations so concurrent calls cannot overspend.
  • topSellers() and the network helpers withNetworkPreference / withPayeeAllowlist for 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 stock mppx fetch pays over MPP (USDC on Base or Celo, or natively on Tempo); an @x402/fetch fetch pays over x402.
  • creditsKey: a prepaid a402_... key pays by card 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

Extract article$0.010
extract
Hash$0.001
hash
SQL execution certificate firewall$0.004
sql-guard
Domain WHOIS (RDAP)$0.005
whois
Web search$0.02
search

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