Skip to content

How x402 Works

Overview

x402 is an HTTP payment protocol for machine-to-machine transactions. Named after HTTP status code 402 (Payment Required), it enables instant micropayments without accounts, subscriptions, or API keys.

Protocol Flow

1. Client sends GET /price/ETH
2. Server returns 402 with PAYMENT-REQUIRED header
3. Client decodes: pay 0.01 USDC to receiver on Base
4. Client signs EIP-712 typed data with wallet key
5. Client retries GET with X-PAYMENT header (signed proof)
6. Server verifies signature via facilitator
7. Server returns 200 + data

Why x402?

  • No API keys or signup forms
  • Native crypto payment (USDC on Base)
  • Sub-second settlement
  • Works with any HTTP client
  • Open source protocol
  • Built for AI agents

Key Concepts

Payment Requirements (Server -> Client)

When you request a paid endpoint, the server responds with 402 and includes payment details:

{
  "version": "1.0",
  "amount": "10000",
  "token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "network": "base",
  "recipient": "0x4SEC_RECEIVER_ADDRESS",
  "nonce": "unique_nonce_abc123"
}

Amount is in USDC base units (6 decimals): 10000 = $0.01

Payment Proof (Client -> Server)

The client signs the payment and retries with proof:

Headers:
X-PAYMENT: {
  "signature": "0x_signed_data...",
  "nonce": "unique_nonce_abc123",
  "amount": "10000",
  "payer": "0x_your_wallet_address"
}

Facilitator

The facilitator is a trusted service that verifies payments on-chain. Default: https://x402.org/facilitator

You can also self-host a facilitator for lower latency.

Comparison: x402 vs Traditional APIs

FeatureTraditional APIx402
AuthenticationAPI keyWallet signature
PaymentCredit card, subscriptionUSDC per request
SignupEmail, formNone
LatencyAuth check on every requestOne-time payment
AI-friendlyRequires key managementAutonomous payment
Global accessRegion restrictionsPermissionless

Resources

Released under the MIT License.