$ GET /quickstart

Your first Agent402 call in 60 seconds

Pick your stack and copy the snippet. The free proof-of-work tools answer right away with no wallet; paid tools need a wallet key holding USDC.

Add to Claude Code

Start with the hosted connector: no install, no wallet. Free tools run with proof-of-work; paid tools answer with their price and a pointer to payment.info.

1. Hosted connector (no install)
claude mcp add --transport http agent402 https://agent402.tools/mcp
2. Free npm install
claude mcp add agent402 -s user -- npx -y agent402-mcp@0.13.31
3. Wallet (optional)

Use a new wallet holding only a few dollars of USDC. Never your main wallet.

claude mcp add agent402 -s user -e AGENT_KEY=0xYOUR_NEW_FUNDED_KEY -- npx -y agent402-mcp@0.13.31
Then ask Claude
# free:        "sha256 this string: hello world"
# with a key:  "extract the text from this PDF"
# with a key:  "fetch Apple's latest 10-K"
What to try next

Call any tool with curl

Standard HTTP - send JSON, get JSON back. No SDK required.

Web search, then a cited answer: see each 402 quote (free)
curl -i "https://agent402.tools/api/search?q=x402+payment+protocol+adoption&count=5"
curl -i "https://agent402.tools/api/answer?q=what+is+the+x402+payment+protocol"

Each 402 carries the price and every way to pay it. A wallet client signs the payment and retries the same request: the Pay with USDC tab shows the same two calls paid from a wallet.

No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown-to-html, json-to-csv and more) run free with proof-of-work and no wallet:

Pay with proof-of-work (free, no wallet)
# Grab a challenge: { "challenge", "difficulty", "token", ... }
curl -s "https://agent402.tools/api/pow/challenge?slug=hash"

# Find an integer nonce so sha256("<challenge>:<nonce>") has at least
# <difficulty> leading zero bits, then send the TOKEN (not the challenge):
curl -X POST https://agent402.tools/api/hash \
  -H "Content-Type: application/json" \
  -H "X-Pow-Solution: <token>:<nonce>" \
  -d '{"text":"hello world","algo":"sha256"}'
What to try next

Use the JavaScript SDK

Install agent402-client: it pays each call from your wallet, and pays the pure-CPU tools with proof-of-work.

Install
npm install agent402-client @x402/fetch @x402/core @x402/evm viem
Web search, then a cited answer

Use a new wallet holding only a few dollars of USDC. Never your main wallet.

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 });  // pays each call from the wallet

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);

No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown-to-html, json-to-csv and more) run free with proof-of-work and no wallet:

const free = new Agent402();  // no fetch: proof-of-work

const result = await free.call("hash", { text: "hello world", algo: "sha256" });
console.log(result);
What to try next
  • Use a.find("geocode") to search tools programmatically
  • Set maxPerCallUsd and dailyLimitUsd on new Agent402() to cap what the wallet spends
  • Enable idempotent retries for production use

Use Agent402 as your model endpoint

Chat, the Anthropic Messages wire and embeddings, paid per request. The metered tier quotes each call from its own body.

Run the local wallet proxy (pays each call from your wallet over x402)
npm i agent402-openclaw @x402/fetch @x402/evm viem   # in one folder
export AGENT402_WALLET_KEY=0x...      # an EVM key holding USDC on Base
export AGENT402_MAX_PER_CALL_USD=2    # per-call ceiling checked before signing
npx agent402-openclaw proxy           # run from that folder; serves http://127.0.0.1:8412/v1
Point any OpenAI SDK at it
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8412/v1", api_key="unused")
r = client.chat.completions.create(model="auto", messages=[{"role": "user", "content": "hi"}])

Every model id and its price: GET https://agent402.tools/v1/models. The proxy also answers the Anthropic wire: for Claude Code, set ANTHROPIC_BASE_URL=http://127.0.0.1:8412. Every host's settings: the agent-hosts guide.

Plug into any LLM framework

Drop-in tool definitions for OpenAI, Anthropic, and Vercel AI SDK.

Install
npm install agent402-openai-tools
# also: agent402-anthropic-tools, agent402-ai-sdk
Wire into your LLM call
import { agent402Tools } from "agent402-openai-tools";
// same shape: agent402-anthropic-tools
// payFetch: the wallet-paying fetch from the Pay with USDC tab

// web search, then a cited answer: both paid per call from the wallet
const { tools, execute } = await agent402Tools({ slugs: ["search", "answer"], freeOnly: false, fetch: payFetch });

// pass tools to your LLM call, e.g. "search the web for x402 adoption, then answer: what is x402?"
// for each tool_call it returns, run:
const result = await execute(call.function.name, JSON.parse(call.function.arguments));

// agent402-ai-sdk returns four meta tools instead, keyed by name:
// const tools = await agent402Tools({ fetch: payFetch }); await generateText({ model, tools, prompt });

No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown-to-html, json-to-csv and more) run free with proof-of-work and no wallet:

// free tier: every compute-payable tool, paid with proof-of-work
const { tools, execute } = await agent402Tools({ slugs: ["hash", "markdown-to-html"] });
What to try next
  • More wallet-only tools (extract, render, screenshot): add their slugs beside freeOnly: false
  • Combine with the MCP connector for Claude-native integration
  • See the playground for live examples

Pay directly with USDC (x402)

Use the x402 protocol for on-chain payment - no API keys, no accounts. This snippet pays on Base or any EVM rail the 402 offers; Solana, Stellar and Algorand need their own scheme (see Paying with x402).

Install
npm install @x402/fetch @x402/core @x402/evm viem
Make a paid call

Use a new wallet holding only a few dollars of USDC. Never your main wallet.

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.(false); // @x402/core 2.23+ refuses anything over $1 or off the pegged-asset list by default; keep your own ceiling in code instead
registerExactEvmScheme(client, {
  signer: privateKeyToAccount(process.env.AGENT_KEY)
});
const payFetch = wrapFetchWithPayment(fetch, client);

// web search, then a cited answer: each call quoted by its 402, then paid and retried
const q = (s) => encodeURIComponent(s);
const found = await (await payFetch("https://agent402.tools/api/search?q=" + q("x402 payment protocol adoption") + "&count=5")).json();
const answer = await (await payFetch("https://agent402.tools/api/answer?q=" + q("what is the x402 payment protocol?"))).json();

console.log(found.results, answer.answer, answer.citations);
What to try next
  • Check /api/pricing for per-tool USDC prices
  • Add an Idempotency-Key header so retries never double-charge
  • See /.well-known/x402 for the machine-readable payment manifest

New to paying per call? The getting started guide walks the whole loop, and the FAQ covers payment, refunds and data.