Skip to content

Introduction to x402

What is x402?

x402 is an open payment protocol that uses the HTTP 402 status code to enable seamless, programmable stablecoin payments on the internet. It allows any server to charge for resources using USDC on Solana, turning API calls, content, and services into payable endpoints with just a few lines of code.

The protocol is designed around a simple idea: payments should be as easy as making an HTTP request.

The Problem

Traditional payment systems create friction at every step:

  • Account registration — Users must sign up, verify identity, and manage credentials before they can pay.
  • Slow settlement — Credit card payments take days to settle and involve multiple intermediaries.
  • High fees — Payment processors charge percentage-based fees that make micropayments impractical.
  • Poor automation — Existing payment flows are built for humans clicking through checkout pages, not for software agents making API calls.
  • Global access barriers — Many payment methods are region-locked or require banking infrastructure that isn't available everywhere.

These problems are especially painful for AI agents, developer tools, and usage-based services where payments need to happen programmatically, instantly, and at scale.

How x402 Solves This

x402 removes the friction by embedding payments directly into HTTP. There are no accounts, no checkout flows, and no intermediaries beyond the blockchain itself. Payments settle in seconds using USDC on Solana, with transaction costs that are a fraction of a cent.

Key Features

FeatureDescription
Simple HTTP integrationAdd payments to any endpoint by returning a 402 status code. No payment SDKs or third-party dashboards required.
Usage-based pricingCharge per request, per byte, or per any unit of consumption. Set the price on each endpoint independently.
MicropaymentsSolana's low transaction fees make payments of $0.001 or less economically viable.
Agent-friendlyDesigned for software agents and automated systems. Clients can discover prices and pay without human intervention.
No accounts neededBuyers pay with a Solana wallet. No registration, no API keys, no subscription management.
Fast settlementPayments confirm on Solana in under a second. Merchants receive USDC directly in their wallet.

How It Works

The x402 protocol follows a four-step flow between the client, the server, and a facilitator that handles payment verification and settlement.

mermaid
sequenceDiagram
    participant Client
    participant Server
    participant Facilitator

    Client->>Server: 1. Request resource
    Server-->>Client: 2. 402 Payment Required (price, token, network)
    Client->>Client: 3. Construct payment payload
    Client->>Server: 4. Request resource + X-PAYMENT header
    Server->>Facilitator: 5. Verify and settle payment
    Facilitator-->>Server: 6. Payment confirmed
    Server-->>Client: 7. Deliver resource

Step 1: Client Requests a Resource

The client makes a standard HTTP request to a server endpoint, just like any normal API call.

GET /api/premium-data HTTP/1.1
Host: example.com

Step 2: Server Responds with Payment Requirements

If the endpoint requires payment, the server responds with HTTP 402 and includes payment details in the response headers and body. This tells the client exactly how much to pay, which token to use, and where to send it.

HTTP/1.1 402 Payment Required
X-PAYMENT-REQUIRED: {"maxAmountRequired": 100000, "resource": "/api/premium-data", ...}

Step 3: Client Constructs and Sends Payment

The client reads the payment requirements, constructs a payment payload (a signed Solana transaction), and retries the original request with the payment attached in the X-PAYMENT header.

GET /api/premium-data HTTP/1.1
Host: example.com
X-PAYMENT: <base64-encoded-payment-payload>

Step 4: Server Verifies and Delivers

The server forwards the payment to the facilitator for verification and settlement. Once the facilitator confirms the payment is valid, the server delivers the requested resource.

The Facilitator

The facilitator is a service that verifies payment payloads, submits transactions to the blockchain, and confirms settlement. It acts as a neutral intermediary that both clients and servers trust to handle the on-chain mechanics.

This documentation uses the SVM Facilitator hosted at:

https://facilitator.svmacc.tech

This is a Solana-native facilitator that supports USDC payments on both Solana mainnet and devnet.

Next Steps

Head to the Quickstart to set up your first x402 server or client.

Powered by SVM Facilitator