402
Challenge before content
Unauthenticated paid routes should return a structured 402 with amount, resource, network, and payee data before any protected response body is generated.
cloudflare worker / x402 / may 2026
Cloudflare's Agents docs now describe x402 and MPP as agentic-payment paths for HTTP resources and MCP tools. That makes the edge gate important: the Worker should return a readable 402, keep paid responses out of shared caches, and refuse to serve protected content until verification is real.
worker checklist
402
Unauthenticated paid routes should return a structured 402 with amount, resource, network, and payee data before any protected response body is generated.
cors
OPTIONS must allow content-type,x-payment, and the actual 402 response must include Access-Control-Allow-Origin plus exposed payment headers.
cache
Use Cache-Control: no-store, private on payment challenges and protected responses, then vary on origin and payment-relevant headers.
verify
The starter deliberately returns 501 after a placeholder payment header. That is safer than accidentally shipping paid content before settlement validation exists.
resource
Top-level resource metadata and accept-level resource echo should point to the same canonical HTTPS URL the agent is buying.
logs
Log request ids, challenge ids, route, rail, and verification result. Do not place prompts, PII, API keys, or wallet secrets in payment metadata.
starter map
The starter is not a fake payment processor. It is a safe edge shape to copy before adding a real x402 or MPP verifier. The important part is that every risky default is explicit.
src/worker.mjs
OPTIONS /paid/report -> 204 CORS preflight
GET/POST /paid/report -> 402 payment challenge
GET/POST with X-PAYMENT -> 501 until verifier is wired
GET /health -> public cacheable health check
test/smoke.mjs
verifies no-store/private, Vary, CORS,
resource echo, and no grant before verification
Start from the repo, wire your actual verifier, then run the no-payment checker against the deployed Worker before you announce the paid route.
Open the Worker starter or run the broader x402 Surface Check.
commands
git clone https://github.com/TateLyman/x402-cache-safe-worker
cd x402-cache-safe-worker
npm test
npx --yes x402-surface-check@latest \
--endpoint --method POST https://worker.example.com/paid/report \
--origin https://app.example.com \
--body '{"report":"demo"}'
why now
Cloudflare
Cloudflare documents x402 and MPP for agentic payments, including HTTP content, MCP tools, and Agents SDK client flows.
official docsAWS
AgentCore Payments preview points the market toward session spending limits, wallet authentication, observability, and x402 negotiation as managed infrastructure.
official announcementresearch
May 2026 x402 attack research highlights finality, replay, caller binding, header/cache handling, and discovery steering as launch controls, not theoretical footnotes.
open paperpaid pass
Send the deployed route, manifest, repo, intended origin, and what a paid call is supposed to unlock.