agentic402

x402 quickstart: your first paid call

Published 3 December 2026 ยท Updated 3 December 2026

x402 quickstart in four steps: put a few dollars of USDC on Base in a wallet the agent controls, send an unpaid request to see the 402 and its price, install an x402 client, and repeat the request through the client. Your first call to fetch costs $0.005, and nothing is taken if it fails.

1. A wallet with USDC on Base

Every agentic402 tool is paid in USDC on Base mainnet (network eip155:8453). Create a new wallet for the agent rather than reusing one you hold other money in, and send it a small amount of USDC on Base. At $0.005 a call, $1 covers 200 fetches.

The agent only signs payment authorizations. The facilitator submits the transfer on-chain. So the wallet needs USDC, not ETH for gas. There is no testnet version of agentic402: the live service accepts mainnet USDC only. Mistakes are cheap anyway, because bad input is rejected before payment and failed calls are never settled.

2. See the 402 with curl

An unpaid request costs nothing and shows you exactly what the server wants:

$ curl -si -X POST https://agentic402.dev/v1/fetch | grep -i '^payment-required' \
    | cut -d' ' -f2 | tr -d '\r' | base64 -d
{"x402Version":2,"error":"Payment required","resource":{"url":"https://agentic402.dev/v1/fetch",...},
 "accepts":[{"scheme":"exact","network":"eip155:8453","amount":"5000",
   "asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
   "payTo":"0xAF3E683729c949538412e3C0709E952A24d1f2C9","maxTimeoutSeconds":300,...}]}

amount is in USDC's smallest unit (6 decimals), so 5000 is $0.005. The request above has no body, which tells the server it's a price check; a request with a body is validated first, and a bad one gets 400 instead of a 402. The payments page explains every field.

3. Install an x402 client

For JavaScript and TypeScript, the official packages are @x402/fetch (wraps fetch), @x402/evm (signs EVM payments) and viem (holds the key):

npm install @x402/fetch @x402/evm viem

Other languages have their own x402 libraries. Any client that speaks x402 version 2 with the exact scheme on Base will work.

4. Make the paid call

import { wrapFetchWithPaymentFromConfig, decodePaymentResponseHeader } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.AGENT_WALLET_KEY);
const payFetch = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:*", client: new ExactEvmScheme(account) }],
});

const res = await payFetch("https://agentic402.dev/v1/fetch", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ url: "https://example.com", format: "json" }),
});
console.log(res.status, await res.json());
const receipt = res.headers.get("payment-response");
if (receipt) console.log(decodePaymentResponseHeader(receipt)); // includes the payer address

The wrapper sends the request, sees the 402, signs a USDC authorization for the exact amount, and sends the request again with a PAYMENT-SIGNATURE header. A 200 comes back with the result and a PAYMENT-RESPONSE receipt. If the tool fails, you get its error status and no receipt, and no money moves.

Keep the private key in an environment variable or a secret store, never in code. The wallet's balance is the most the agent can spend, which makes a small balance the simplest spending limit there is.

Next calls

The same payFetch pays for every tool. POST /v1/inbox with no body creates a webhook inbox. PUT /v1/memory/notes/first with a text body creates a memory space and returns its token. Free calls, such as reading an inbox or memory, need no payment client at all; plain fetch with the token is enough.

If your agent works through MCP instead of HTTP, see the MCP setup. If a call fails, the error reference says what each status means and whether it cost anything.