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
| Feature | Description |
|---|---|
| Simple HTTP integration | Add payments to any endpoint by returning a 402 status code. No payment SDKs or third-party dashboards required. |
| Usage-based pricing | Charge per request, per byte, or per any unit of consumption. Set the price on each endpoint independently. |
| Micropayments | Solana's low transaction fees make payments of $0.001 or less economically viable. |
| Agent-friendly | Designed for software agents and automated systems. Clients can discover prices and pay without human intervention. |
| No accounts needed | Buyers pay with a Solana wallet. No registration, no API keys, no subscription management. |
| Fast settlement | Payments 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.
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 resourceStep 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.comStep 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.techThis 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.