The x402 protocol
x402 uses HTTP status code402 Payment Required to signal that content requires payment. When an AI agent hits a gated URL, the server returns a 402 response with payment instructions instead of content.
Payment flow
Gate creation
An AI agent requests a URL. The server detects the bot (via User-Agent), calls the Xenarch API to create a payment gate, and returns HTTP 402 with gate details: price, splitter contract address, publisher wallet, and a verify URL.
On-chain payment
The agent approves USDC and calls
split(collector, amount) on the Xenarch splitter contract. The contract transfers USDC directly to the publisher wallet (minus any platform fee). A Split event is emitted on-chain.Payment verification
The agent sends the transaction hash to the verify endpoint. Xenarch fetches the tx receipt from Base, parses the
Split event, confirms the amount and recipient match, and returns a time-limited HMAC access token.What each party does
Publisher (server-side)
- Register on Xenarch, add your site, set pricing
- Install middleware (Python SDK, WordPress plugin, or Cloudflare Worker)
- Middleware handles bot detection, gate creation, and token verification automatically
Agent (client-side)
- Request a URL, receive HTTP 402
- Parse the 402 response for payment details
- Send USDC on Base via the splitter contract
- Submit tx hash, receive access token
- Re-request with the token
Architecture
Security model
- Non-custodial: Xenarch never holds funds. USDC goes directly from agent to publisher via the splitter contract.
- On-chain verification: Every payment is verifiable on Basescan. No trust required.
- Immutable fee cap: The splitter contract has a
MAX_FEE_BPS = 99constant (0.99%) that cannot be changed after deployment. - Replay protection: Each transaction hash can only be used once per gate. Duplicate submissions return the cached token.
- Token expiry: Access tokens expire after 30 minutes by default. Tokens are HMAC-signed and verified locally by the publisher’s middleware — no API call needed.