Skip to main content
The x402 protocol enables pay-per-call USDC micropayments for AI agents, LLM APIs, and any HTTP service. Buyers pay in USDC per request; sellers validate payments server-side with zero configuration overhead.

How It Works

  1. Buyer calls pay(url, amount) with the seller’s URL and the expected USDC amount
  2. The SDK negotiates a payment session with the x402 facilitator, submits an ERC-20 Transfer transaction on-chain, and attaches the authorization header to the request
  3. Seller middleware (@x402/express) validates the header, extracts the payment details, and allows the request through
  4. Both sides receive the on-chain transaction hash as proof of payment

Buyer SDK (@xpaylabs/x402)

Install:

One-shot Payment

Session-based Client

Each call pays independently. The client tracks the last PAYMENT-RESPONSE header for audit.

Payment ID Extraction

Seller Middleware (@x402/express)

AI Agent Payment Flow

x402 is designed for autonomous agent-to-API payments:
No API keys, no subscriptions, no billing dashboard — just pay-per-call with USDC.
Last modified on June 26, 2026