agentgrade

← Knowledge Base

What is x402?

x402 turns the HTTP 402 "Payment Required" status code into a real payment protocol. When an agent hits a paid endpoint, the server returns a 402 with a Payment-Required header containing payment instructions. The agent pays on-chain, attaches the receipt, and retries.

How it works

  • Agent sends a request to a paid endpoint
  • Server returns HTTP 402 with a base64-encoded Payment-Required header
  • The header contains: amount, asset (USDC), network (Base), recipient wallet, and facilitator
  • Agent pays via the facilitator (e.g., Coinbase)
  • Agent retries the request with a Payment header containing the receipt
  • Server verifies the payment through the facilitator and serves the response
  • Key concepts

    How to add x402 to your service

    1. Install the SDK

    npm install @coinbase/x402-express
    

    2. Add middleware to your Express app

    import { paymentMiddleware } from '@coinbase/x402-express';
    
    app.use('/api/paid-endpoint', paymentMiddleware({
      payTo: '0xYourWalletAddress',
      amount: '100000', // in smallest unit (0.10 USDC)
      network: 'base',
      facilitator: 'coinbase',
    }));
    

    3. Publish discovery file

    Serve /.well-known/x402.json so agents can find your paid endpoints:

    {
      "x402Version": 2,
      "name": "Your Service",
      "network": "base",
      "facilitator": "coinbase",
      "payTo": "0xYourWalletAddress",
      "services": [{
        "method": "POST",
        "path": "/api/paid-endpoint",
        "amount": "100000",
        "discoverable": true
      }]
    }
    

    Spec maturity

    Production-ready. x402 v2 launched December 2025. Supported by Coinbase with official SDKs in TypeScript, Go, and Python.

    Learn more