x402 Protocol
x402 implements the long-reserved HTTP 402 “Payment Required” status code for machine-to-machine stablecoin payments. It’s an open protocol — not proprietary to Finance District — and Prism uses it as the primary payment protocol for AI agent commerce. The flow is simple: a client requests a resource, the server responds with 402 and payment requirements, the client pays on-chain, and the server grants access. No API keys to exchange, no OAuth handshakes — just HTTP and stablecoins.This page covers x402 from the merchant/seller perspective — implementing
it with Prism. For the buyer/agent side, see x402 Payments in Agent
Wallet.
The Protocol Flow
- The agent makes a standard HTTP request
- The Prism middleware returns 402 with a JSON body describing the accepted payment
- The agent’s wallet constructs and signs a stablecoin payment
- The agent retries the request with the signed payment in the
X-PAYMENTheader - Prism’s Spectrum layer settles the payment on-chain and verifies it
- The response includes the transaction hash in
X-PAYMENT-RESPONSE
Implementing x402 with Prism
You don’t implement the x402 protocol directly — the Prism SDK handles it. You configure what to charge and the middleware handles the 402 response, payment verification, and settlement automatically.Payment Requirements (402 Response)
When the middleware returns 402, the response body contains:| Field | Type | Description |
|---|---|---|
x402Version | number | Protocol version (currently 1) |
paymentRequired | bool | Always true for 402 responses |
acceptedPayments | array | List of accepted payment options |
description | string | Human-readable description of what’s being purchased |
priceUSD | string | Price in USD |
acceptedPayments contains:
| Field | Type | Description |
|---|---|---|
scheme | string | Payment scheme (e.g., eip3009) |
network | string | Chain identifier (e.g., base, eth-sepolia) |
asset | string | Token (e.g., usdc) |
amount | string | Amount in token base units |
recipient | string | Merchant’s wallet address |
nonce | string | Unique nonce for replay protection |
validBefore | number | Unix timestamp deadline for payment |
Payment Verification
When the agent sends a request with theX-PAYMENT header:
- Prism parses the signed payment from the header
- Forwards it to the Spectrum settlement layer
- Spectrum executes the on-chain transfer and verifies: correct amount, correct token, correct recipient, valid signature
- If settlement succeeds, the request proceeds and the transaction hash is returned in the
X-PAYMENT-RESPONSEheader - If settlement fails, the middleware returns 402 with an error