x402 lets HTTP APIs charge micropayments on-chain. Agent Kit exposes discovery and payment tools over MCP so your LLM can find services, pay for them, and read responses — using the agent’s server wallet and stored access key.

Tools involved

transfer and wallet read tools are separate — used for moving funds, not for paying x402 merchants.

High-level flow

Step 1 — Discover payable services

Call discover_services to search the service catalog Agent Kit exposes for x402 merchants. Pass a semantic query and optional filters:
The response includes a catalog summary and services[] entries (each with service_id as the resource URL, accepts, paymentsProtocolConfig, and metadata). Pick a service_id or endpoint URL for the next step. Optionally confirm details with get_service:

Step 2 — Probe with paid_fetch

First call without paymentPayload:
If the origin requires payment, MCP returns payment required (JSON-RPC error -32402 or a paymentRequired object) including:
  • x402Version
  • accepts[] (network, asset, payTo, amount)
  • resource metadata
Your integration must not treat this as a hard failure — it is the signal to sign and retry.

Step 3 — Sign paymentPayload on your backend

Payments must be signed with the agent’s server wallet access key (from createAgent). Never do this in the browser. The sample backend API implements this in AgentSigningService.createX402PaymentPayloadForAgent:
  1. Load agent row with encrypted accessKey.
  2. Decrypt with ENCRYPTION_KEY.
  3. AgentKitClient.getServerSigner().authenticate({ userIdentity, accessKey }).
  4. Build viem public client for the chain in accepts[0].network.
  5. Sign EIP-712 typed data required by x402 v2.
  6. Return PaymentPayload for MCP retry.
Conceptually:
Fund the agent’s EVM address with native gas on the payment network before first x402 payment.

Step 4 — Retry paid_fetch with payment

Pass paymentPayload at the top level of tools/call params (same level as name / arguments):
On success, paid_fetch returns fields such as:

Fixed-price MCP tools (get_token_price)

Tools with a listed price in the dashboard (e.g. $0.001 for get_token_price) use Agent Kit’s internal x402 facilitator:
  1. First tools/callpaymentRequired with accepts built by Agent Kit.
  2. Backend signs paymentPayload (same access key flow).
  3. Retry with paymentPayload.
  4. Spend policy may block the call if the agent exceeded budgetUsd (SDK updateSpendPolicy). Interaction policies are checked before spend policy (interaction policies).
paid_fetch to third-party URLs does not use the same spend-policy price table — filter expensive services in discover_services (maxUsdPrice).

MCP client example (NestJS)

From the sample backend’s McpClientService:
Handle error.code === -32402 by signing and retrying once.

Facilitator (verify / settle)

Hosted facilitators process payment verification and on-chain settlement. Both services pick the facilitator automatically — you do not set a single X402_FACILITATOR_URL for everything. Set CDP_API_KEY_* on the gateway and Agent Kit hosts so mainnet settle/verify works.

Environment (Agent Kit host)

Operational tips

  • Preflight: Use get_balance on the agent’s EVM address before paid calls.
  • Discovery: Prefer URLs from discover_services / get_service over guessing endpoints.
  • GET requests: Put query parameters in the url string, not in custom headers unless the API requires it.
  • Logging: Never log accessKey or full paymentPayload secrets in production.