HTTP 402 Protocol

Understanding the x402 payment protocol that powers AuditAgent.

What is HTTP 402?

HTTP 402 "Payment Required" is an official HTTP status code defined in RFC 2616. It was reserved in 1999 for future digital payment systems but never widely implemented—until now.

With blockchain-based micropayments, x402 finally becomes practical for autonomous agents and pay-per-use APIs.

How It Works

Step 1: Initial Request

Client requests a protected resource:

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

Step 2: Payment Challenge

Server responds with 402 and payment requirements:

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "x402Version": 1,
  "resource": "https://api.example.com/api/premium-data",
  "accepts": [{
    "method": "solana-pay",
    "network": "devnet",
    "asset": "USDC",
    "amount": 1,
    "payTo": "AgentPDAAddress...",
    "extra": {
      "feePayer": "AuthorityPubkey...",
      "decimals": 6
    }
  }]
}

Step 3: Payment Execution

Agent executes payment on Solana and retries request:

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

Step 4: Content Delivery

Server verifies payment and returns content:

HTTP/1.1 200 OK
X-402-Amount: 1
Content-Type: application/json

{
  "data": {
    "insight": "Your premium data here",
    "timestamp": 1701878400000
  }
}

Payment Methods

Solana-Pay (Supported)

Native Solana payments with USDC:

  • Network: devnet or mainnet-beta
  • Asset: USDC (SPL token)
  • Settlement: ~400ms
  • Fees: ~$0.0001 per transaction

Future Support

  • SOL native payments
  • Other SPL tokens (USDT, etc.)
  • Lightning Network

Chained Requests

APIs can suggest follow-up endpoints:

{
  "data": { ... },
  "nextResource": "/api/premium-insights",
  "nextResourceLabel": "follow-up-data"
}

AuditAgent will automatically fetch the follow-up endpoint (with payment if required).

TAP Proofs

Every payment generates a Trusted Agent Proof (TAP) - a cryptographic signature proving:

  • Which agent made the payment
  • What resource was paid for
  • How much was paid
  • When the payment occurred

This enables full auditability and compliance tracking.

Learn More