Skip to main content
x402 is an open protocol for internet-native payments that activates the HTTP 402 “Payment Required” status code. It enables AI agents and applications to make instant, permissionless micropayments using stablecoins.

Key Features

  • HTTP-Native: Built into existing HTTP requests with no additional communication required
  • Instant Settlement: Sub-second on Celo, compared to days with traditional payments
  • Zero Protocol Fees: Only pay nominal blockchain gas fees
  • Agent-First: Designed for autonomous AI agent transactions
  • Chain Agnostic: Supports 170+ EVM chains including Celo

Why x402?

Traditional payment systems don’t work for AI agents and micropayments:

How It Works

Step-by-step:
  1. Client requests resource - AI agent or app sends HTTP request to API
  2. Server returns 402 - If no payment attached, server responds with HTTP 402 Payment Required and payment details in headers
  3. Client signs payment - Client signs payment authorization using their wallet
  4. Client retries with payment - Request sent again with X-PAYMENT header
  5. Server verifies and settles - Payment is verified and settled on-chain
  6. Server delivers resource - Requested content returned with payment receipt

Using thirdweb SDK

thirdweb provides a complete x402 implementation that supports Celo and 170+ EVM chains. The SDK handles wallet connection, payment signing, and error handling automatically.

Client Side (React)

Use the useFetchWithPayment hook for automatic payment handling:

Client Side (TypeScript)

For non-React applications, use wrapFetchWithPayment:

Server Side (Next.js)

Accept x402 payments in your API endpoints:

Server Side (Express)

x402 on Celo

Celo is an ideal network for x402 due to:
  • Low fees: Gas costs under $0.001 per transaction
  • Fast finality: ~1 second block times
  • Stablecoin support: Native USDC, USDT, USDm for predictable pricing
  • Fee abstraction: Agents can pay gas in the same stablecoins used for x402 payments — no separate CELO balance needed. See Fee Abstraction for Agents

Supported Payment Tokens on Celo

The thirdweb facilitator supports tokens with ERC-2612 permit or ERC-3009 authorization:

Celo Configuration

Use Cases

AI Agent API Access

In this example, an AI agent uses its own wallet to pay for API calls autonomously. The agent doesn’t need API keys or pre-registered accounts—it simply pays per request using the x402 protocol. This enables truly permissionless agent commerce:

Pay-Per-Use AI Inference

This server-side example demonstrates dynamic pricing using the upto scheme. Instead of charging a fixed price upfront, the server:
  1. Verifies the payment authorization is valid for up to the maximum amount
  2. Runs the inference and measures actual token usage
  3. Charges only for what was used (respecting the minimum price)
This is ideal for AI inference where costs vary based on prompt length and output tokens:

Micropayments for Content

Publishers can monetize individual articles instead of requiring subscriptions. Each request is checked for a valid x402 payment—if missing, the server returns 402 Payment Required with pricing details. If present, the payment is settled and content is delivered:

Resources