@tools402/client
v0.2.1
Published
Node/TypeScript SDK for tools402 — 146 pay-per-use APIs for AI agents via x402 (USDC on Base)
Readme
@tools402/client
Node/TypeScript SDK for tools402 — 146 pay-per-use AI agent APIs via the x402 HTTP payment protocol (USDC on Base mainnet).
Install
npm install @tools402/client viem
# or
bun add @tools402/client viemUsage
import { Client } from "@tools402/client";
const client = new Client({
privateKey: process.env.WALLET_KEY as `0x${string}`,
// baseUrl: "https://api.tools402.dev", // default
// rpcUrl: "https://mainnet.base.org", // default
});
// Any endpoint — SDK handles 402 → USDC payment → retry automatically
const resp = await client._call("/v1/ocr", {
method: "POST",
body: formData,
});
const result = await resp.json();
// List all available endpoints
const meta = await client.meta();
console.log(meta.endpoints);How it works
_call(path, init)sends the request.- If the server returns
402, the SDK reads theaccepts[0]payment requirements. - Sends a USDC ERC-20 transfer on Base mainnet, waits for 1 confirmation.
- Retries the original request with an
X-Paymentheader (base64url-encoded JSON per x402 §3.2). - Returns the successful response.
No API key. No account. The wallet is the identity.
License
MIT
