Agentic Payments
AI agents need to discover, pay for, and consume resources and services programmatically. Traditional onboarding requires account creation, a payment method, and an API key before an agent can pay for a service. Agentic payments let AI agents purchase resources and services directly through the HTTP 402 Payment Required response code.
Cloudflare's Agents SDK supports agentic payments through two protocols built on the HTTP 402 Payment Required status code: x402 and Machine Payments Protocol (MPP). Both follow the same core flow:
- A client requests a resource or calls a tool.
- The server responds with
402and a payment challenge describing what to pay, how much, and where. - The client fulfills the payment and retries the request with a payment credential.
- The server verifies the payment (optionally through a facilitator service) and returns the resource along with a receipt.
No accounts, sessions, or pre-shared API keys are required. Agents handle the entire exchange programmatically.
x402 ↗ is a payment standard created by Coinbase. It uses on-chain stablecoin payments (USDC on Base, Ethereum, Solana, and other networks) and defines three HTTP headers — PAYMENT-REQUIRED, PAYMENT-SIGNATURE, and PAYMENT-RESPONSE — to carry challenges, credentials, and receipts. Servers can offload verification and settlement to a facilitator service so they do not need direct blockchain connectivity. It is governed by Coinbase and Cloudflare, two of the founding members of the x402 Foundation.
The Agents SDK provides first-class x402 integration:
- Server-side:
withX402andpaidToolfor MCP servers, plusx402-honomiddleware for HTTP Workers. - Client-side:
withX402Clientwraps MCP client connections with automatic 402 handling and optional human-in-the-loop confirmation.
Machine Payments Protocol (MPP) ↗ is a protocol co-authored by Tempo Labs and Stripe. It extends the HTTP 402 pattern with a formal WWW-Authenticate: Payment / Authorization: Payment header scheme and is on the IETF standards track.
MPP supports multiple payment methods beyond blockchain — including cards (via Stripe), Bitcoin Lightning, and stablecoins — and introduces sessions for streaming and pay-as-you-go use cases with sub-millisecond latency and sub-cent costs. MPP is backwards-compatible with x402: MPP clients can consume existing x402 services without modification.
- x402.org ↗ — x402 protocol specification
- mpp.dev ↗ — MPP protocol specification
- Pay Per Crawl — Cloudflare-native monetization for web content
- x402 examples ↗ — Complete working code