x402 Protocol

The Internet-Native Payment Layer for Agentic Commerce

Learn how AI agents and businesses are revolutionizing payments with instant, frictionless microtransactions

What is x402?

x402 is an open payment standard that enables instant, autonomous payments for APIs, AI agents, and digital services. It activates the dormant HTTP 402 "Payment Required" status code to create seamless, pay-per-use transactions.

❌ Traditional Payments

  • Account creation required
  • KYC verification delays
  • Subscription commitments
  • API key management
  • Slow transaction processing
  • High fees for small amounts

✅ x402 Protocol

  • No account setup needed
  • Instant onboarding
  • Pay-per-use model
  • No API key required
  • 2-second settlements
  • Near-zero fees

Instant Payments

Transactions settle in 2 seconds using stablecoins like USDC

🤖

AI-Native

Built for autonomous AI agents to pay for services independently

🔗

Blockchain Agnostic

Works with any blockchain network supporting smart contracts

💰

Micropayments

Enable transactions under 1 cent with minimal fees

How x402 Works

The x402 protocol transforms the forgotten HTTP 402 status code into a powerful payment mechanism.

1

Request

AI agent or client requests a resource from a server

2

402 Response

Server responds with "Payment Required" and payment details

3

Payment

Client pays with cryptocurrency (USDC) on blockchain

4

Access Granted

Server verifies payment and delivers the requested resource

Interactive Demo: API Payment Flow

Experience how x402 payments work in real-time

Click the button above to see x402 in action!

// Server Implementation (One line of code!)
paymentMiddleware("0.01", {"/api/data": "$0.01"});

// Client receives HTTP 402 response:
{
  "amount": "0.01",
  "currency": "USDC", 
  "network": "base",
  "recipient": "0x742d35Cc6634C0532925a3b8D6Ac6841..."
}

Real-World Use Cases

Discover how x402 is revolutionizing various industries with frictionless payments.

🎮 Gaming & Metaverse

In-game purchases, virtual assets, and metaverse transactions

Click to learn more

📰 Premium Content

Newsletter subscriptions, articles, and exclusive content access

Click to learn more

🤖 AI Services

Pay-per-inference AI models, data analysis, and automation

Click to learn more

🔌 API Monetization

Weather data, financial APIs, and real-time information services

Click to learn more

🌐 IoT & Edge Computing

Device-to-device payments and autonomous system transactions

Click to learn more

☁️ Cloud Storage

Pay-per-gigabyte storage and computational resources

Click to learn more

Implementation Guide

Integrate x402 into your application with minimal code changes.

Server-Side Integration

// Express.js Example
const express = require('express');
const { x402Middleware } = require('@x402/middleware');

const app = express();

// Add x402 payment requirement
app.use('/api/premium', x402Middleware({
  amount: '0.05',
  currency: 'USDC',
  network: 'base',
  recipient: '0x742d35Cc6634C0532925a3b8D6Ac6841...'
}));

app.get('/api/premium/data', (req, res) => {
  res.json({ data: 'Premium content here!' });
});

Client-Side Payment

// JavaScript Client Example
async function accessPremiumAPI() {
  try {
    // First request - will receive 402
    const response = await fetch('/api/premium/data');
    
    if (response.status === 402) {
      const paymentInfo = await response.json();
      
      // Make payment using web3 wallet
      const payment = await makePayment(paymentInfo);
      
      // Retry request with payment proof
      const finalResponse = await fetch('/api/premium/data', {
        headers: {
          'X-Payment': payment.transactionHash
        }
      });
      
      return await finalResponse.json();
    }
  } catch (error) {
    console.error('Payment failed:', error);
  }
}

Supported Technologies

🔗 Blockchains

Base, Ethereum, Polygon, Solana

💰 Currencies

USDC, USDT, ETH, SOL

⚙️ Frameworks

Express, FastAPI, Django, Rails

👛 Wallets

MetaMask, Coinbase Wallet, WalletConnect

Get Started with x402

Ready to implement frictionless payments in your application?

1

Install SDK

npm install @x402/middleware
2

Configure Wallet

Set up your receiving wallet address on supported networks

3

Add Middleware

app.use(x402Middleware(options))
4

Start Earning

Your API now accepts instant crypto payments!