What is x402 and why does it matter for AI agents?
x402 reactivates HTTP 402 as a machine-to-machine payment protocol. Here's how AI agents discover priced endpoints, settle payments, and where policy fits in.
HTTP 402 was reserved in 1997 for "Payment Required" and sat dormant for nearly thirty years. The x402 protocol finally puts it to work — not for humans, but for AI agents that need to pay for API calls without a credit card form in sight.
What is the x402 protocol?
x402 is an open protocol that uses the HTTP 402 status code to make APIs directly payable by software clients. A server responds to an unpaid request with 402 Payment Required plus a structured payload describing the price, the accepted payment methods, and the settlement endpoint. The client — typically an AI agent — pays, retries the request with a payment proof header, and receives the response.
The protocol was reintroduced by Coinbase in 2025 and has since been adopted by a growing list of API providers targeting agent traffic. It works over standard HTTP, requires no account creation, and settles in seconds. For AI agents, x402 is the closest thing to a native payment rail the web has ever had.
Why does x402 matter for AI agents?
Agents don't have wallets, browsers, or session cookies in the way humans do. Every existing monetization model — API keys, OAuth, subscriptions, marketplace tokens — assumes a human signed up, agreed to terms, and stored a credential. That assumption breaks the moment an autonomous agent discovers a useful endpoint at runtime.
x402 fixes the friction at three specific points:
- Discovery. An agent can hit any URL and learn its price from the 402 response. No pre-registration.
- Negotiation. The 402 payload lists accepted payment methods (USDC on Base, native fiat rails, custom). The agent picks one it supports.
- Settlement. Payment happens in-band — one extra HTTP round trip, not a separate billing system.
The result is a web where any priced resource — a scraping API, a model inference endpoint, a piece of premium data — is reachable by any agent that has spending authority, without integration work on either side.
How does an x402 flow actually work?
A minimal exchange looks like this:
GET /v1/market-data/AAPL HTTP/1.1
Host: api.example.com
HTTP/1.1 402 Payment Required
Content-Type: application/json
{
"amount": "0.01",
"currency": "USDC",
"network": "base-mainnet",
"pay_to": "0xabc...",
"resource": "/v1/market-data/AAPL",
"expires_at": "2026-04-27T12:00:00Z"
}The agent signs and submits the payment, then retries:
GET /v1/market-data/AAPL HTTP/1.1
Host: api.example.com
X-Payment: <base64 settlement proof>
HTTP/1.1 200 OK
Content-Type: application/json
{ "symbol": "AAPL", "price": 187.42, ... }Two requests, no signup, no API key. The settlement proof is verified server-side against the network the agent paid on. Most x402 servers cache the proof so retries on the same resource within a window don't re-charge.
Where does policy fit in an x402 flow?
This is the question most teams miss. x402 makes payment trivial, which means an agent can spend money faster than any human can audit. The protocol itself has no concept of budgets, allowlists, or approvals — it's a payment rail, not a policy-controlled spending architecture.
The policy layer has to sit in the agent's HTTP client, before the retry with X-Payment is sent. Concretely:
from paygraph import PolicyEngine, Policy
import httpx
policy = Policy(
max_per_transaction_usd=5,
daily_cap_usd=100,
allowed_domains=["api.example.com", "data.vendor.io"],
require_approval_above_usd=1,
)
engine = PolicyEngine(policy)
@engine.guarded_x402
def fetch(url: str) -> httpx.Response:
r = httpx.get(url)
if r.status_code == 402:
quote = r.json()
# PolicyEngine evaluates quote against policy here:
# - amount cap
# - domain allowlist
# - approval threshold
# - daily/weekly running total
proof = engine.settle(quote)
r = httpx.get(url, headers={"X-Payment": proof})
return rThe decorator intercepts every 402 quote, evaluates it, and either settles, escalates for approval, or rejects. The agent code stays clean — it asks for a URL and gets bytes back, the same as any HTTP call.
What can go wrong without a policy layer on x402?
The same failure modes that affect any agent payment system apply, but x402 amplifies them because the friction is so low. The protocol is designed for sub-cent micropayments at machine speed — which is exactly the regime where a runaway loop becomes expensive fast.
Specific risks worth naming:
- Quote inflation. A compromised or malicious endpoint returns a 402 with an inflated price. Without a per-call cap, the agent pays it.
- Redirect chains. A 402 points to a settlement endpoint on a different domain. Without a domain allowlist, the agent funds an attacker.
- Replay across sessions. An agent re-fetches the same priced resource thousands of times in a loop because no daily cap exists. Each call is cheap; the bill is not.
- No audit trail. Compliance asks which agent paid which vendor for what. The HTTP logs alone don't tell you — you need the agent's intent recorded alongside the settlement.
The fix for the last one is straightforward: every settled 402 should produce a structured entry in the audit log tying the agent, the resource, the quote, and the settlement proof together. PayGraph emits this entry automatically when you use guarded_x402.
How does x402 compare to other agent payment options?
| x402 | Stripe Issuing card | Internal budget API | |
|---|---|---|---|
| Discovery | In-band via 402 | Out-of-band | Out-of-band |
| Settlement speed | Seconds | Card auth latency | Internal RPC |
| Per-call overhead | One extra round trip | Card network fees | None |
| Best for | Priced APIs, micropayments | Real-world vendors | Internal tools |
| Identity model | Pseudonymous wallet | Cardholder + card | Service account |
| Native to web | Yes | No | No |
x402 is not a replacement for Stripe Issuing for AI agents when the agent needs to pay a SaaS vendor or book a flight. It's the right rail for machine-payable APIs — endpoints designed from day one to be called by software that pays per request.
Where to start
- GitHub: github.com/paygraph-ai/paygraph — MIT-licensed SDK with built-in x402 client and policy enforcement.
- Docs: docs.paygraph.dev — x402 integration guide, quote validation reference, settlement proof schema.
- Discord: discord.gg/PPVZWSMdEm — talk to teams shipping x402-paying agents in production.
x402 makes paying trivial. That's the feature, and it's also the risk. Wrap your client before you let an agent loose on the priced web.