x402

General Updated Jun 2026

What is x402?

x402 is an open payment protocol that enables HTTP-native micropayments. It repurposes HTTP status code 402 (“Payment Required”) — which has been reserved but unused since HTTP/1.1 (1999) — to create a standardized way for clients to pay for API access, content, or services on a per-request basis.

How x402 Works

The protocol defines a four-step flow:

  1. Client requests — A standard HTTP GET to a paid endpoint
  2. Server responds 402 — Returns a JSON body specifying the payment scheme, amount, asset, network, and recipient address
  3. Client pays — Signs a stablecoin transfer (typically USDC) matching the requirements, then retries the request with an X-PAYMENT header containing the signed payment
  4. Server verifies & serves — Validates the cryptographic signature, settles the payment on-chain, and returns the requested data with HTTP 200

Key Properties

  • No API keys: Authentication is replaced by payment. If you pay, you get the data.
  • No accounts or signups: The client only needs a wallet with sufficient balance.
  • Per-request pricing: Each endpoint can have different pricing. No subscriptions, no tiers.
  • Cryptographic verification: Payments are signed using EIP-3009 transferWithAuthorization, allowing off-chain signature verification without an on-chain transaction per request.
  • Facilitator pattern: A neutral “facilitator” service handles payment verification and settlement, so the API provider doesn’t need to run their own payment infrastructure.

Use Cases

  • Pay-per-request APIs: Risk scoring, data feeds, AI inference, file storage
  • Content monetization: Pay-per-article, pay-per-download
  • Agent-to-agent payments: AI agents paying for API access autonomously

Onchain Diary’s x402 Implementation

The Onchain Diary Risk API uses x402 for its premium tier:

EndpointPriceAssetNetwork
/api/v1/risk/address/{address}$0.01USDCBase Sepolia (testnet)
/api/v1/risk/token/{address}$0.02USDCBase Sepolia (testnet)
/api/v1/gas$0.005USDCBase Sepolia (testnet)

The implementation includes a self-hosted facilitator (/api/v1/facilitator/verify + /api/v1/facilitator/settle) that validates EIP-3009 signatures and settles payments on-chain.

For full integration details, see the Developer API documentation.