402 Payment Required status code into a real, working payment mechanism. When an API or MCP server requires payment, it returns a 402 response with the price and receiving address in the headers. Pay3 handles the entire challenge-response cycle automatically — your AI assistant never needs to manage keys, construct transactions, or interact with blockchain infrastructure directly. It just makes requests, and Pay3 ensures the ones that need payment get paid.
Why x402 Matters for AI Agents
Today’s API monetization relies on subscriptions, credit cards, and monthly billing cycles — all of which are designed for humans. An AI agent cannot hold a credit card. It cannot sign up for a subscription. And paying $99/month for an API your agent calls three times makes no economic sense. x402 changes the model entirely:- Pay per call, not per month — your agent only pays for what it actually uses
- Sub-cent micropayments are viable because Stellar transaction fees are approximately $0.00001
- No account creation at each API provider — the payment itself is the credential
- Instant settlement — Stellar confirms transactions in 3–5 seconds
x402 is built on the existing HTTP specification. The
402 Payment Required status code has been reserved since HTTP/1.0 but was never formally standardized for use. Pay3 implements x402 as a practical micropayment protocol on top of this status code using Stellar as the settlement layer.The x402 Payment Flow
Here is exactly what happens when an AI agent hits a paid API endpoint through Pay3:1
AI makes a request
Your AI assistant makes a standard HTTP GET (or POST) request to a paid API endpoint. No special headers, no authentication token — just a normal request.
2
Server responds with 402
The API server recognizes that no payment has been made and returns
HTTP 402 Payment Required. The response headers include the price, accepted asset, receiving Stellar address, and an optional memo.3
Pay3 SDK constructs and signs the payment
The Pay3 SDK intercepts the 402 response. It checks the payment parameters against your active session policy (daily budget, per-tx limit, asset permissions), then constructs a Stellar transaction, signs it using your session key, and submits it to the Stellar network. The SDK receives a signed payment proof token once Stellar confirms the transaction.
4
AI resends the request with payment proof
The Pay3 SDK retries the original request with the payment proof token attached in the
X-Payment header.5
Server verifies and delivers the resource
The API server decodes the payment proof, verifies the transaction on the Stellar network (checking the amount, asset, receiver address, and memo), and returns the requested resource with a
200 OK response.x402 Payments Go Through Your Policy
x402 payments are not a bypass of your Pay3 spending controls. Every payment triggered by the x402 flow is evaluated by the policy engine first, exactly like a manualtransfer() call.
x402 micropayments count against your session’s daily budget and are subject to per-transaction limits. If a single API call costs $0.01, it adds $0.01 to your daily spend. If an API charges more than your
perTransactionMax, the payment is blocked and the API request is not retried.Use Cases
Pay-per-API-call
Access premium data APIs — financial data, weather, maps, news — without subscriptions. Each call costs a fraction of a cent and is settled instantly on Stellar.
MCP Tool Invocation
AI agents using Model Context Protocol can pay for individual tool executions. An MCP server that runs a web search, code analysis, or document parsing can charge per invocation.
Per-Query Data Access
Research agents can pay for individual database queries or knowledge-base lookups. No bulk subscription required — pay only for the specific records retrieved.
Per-Inference AI Model Calls
AI agents can pay other AI model providers per inference request. One agent can call another agent’s capabilities on a pure pay-per-use basis, enabling agent-to-agent commerce.
The Payment Proof Token
TheX-Payment header contains a base64-encoded Stellar transaction proof. This proof includes:
- The Stellar transaction hash (allows the server to look it up on-chain)
- The paying address (your session key’s public address)
- A cryptographic signature confirming the transaction was submitted
HTTP Header Reference
402 Response from a paid server:Stellar Makes Micropayments Practical
The economic viability of x402 micropayments depends entirely on transaction fees being negligible. Stellar delivers this:
At Stellar’s fee levels, an AI agent can make thousands of micropayments per day with a total fee overhead of less than a cent.