Back to blog

x402 Protocol Architecture: How to Diagram AI Agent Stablecoin Payments (2026)

How to diagram x402 protocol architecture for AI agents making instant stablecoin payments over HTTP 402. Covers the resource server, facilitator, payment header, and how x402 fits alongside AP2 and the Agentic Commerce Protocol — with AI prompt templates.

R
Ryan·Senior AI Engineer
·

x402 architecture diagrams are showing up in a growing share of agentic-commerce design docs in 2026 as AI agents move from browsing the web to transacting on it. x402 revives the long-dormant HTTP 402 Payment Required status code as a machine-native payment handshake: an API or MCP server can respond “this costs $0.001, pay here” and an AI agent can pay instantly with stablecoins — no account creation, no API key provisioning, no credit card on file. Originally published by Coinbase and now stewarded by the x402 Foundation, the protocol has moved quickly from spec to production, with facilitator support from Cloudflare and managed agent-payment tooling from AWS Bedrock AgentCore. This guide covers the components and flow you need to diagram an x402 integration.

Why x402 exists

  • Machine-native micropayments: Traditional API monetization (API keys, subscriptions, invoiced usage) assumes a human signs up in advance. x402 lets an agent discover a paid endpoint and pay for a single call on the spot, which makes per-request pricing viable for the first time.
  • No account, no card: Payment happens via a crypto wallet the agent controls, settled in stablecoins (commonly USDC) on a low-fee chain like Base. There is no OAuth app registration or PCI scope to manage on the resource-server side.
  • Near-zero fees at scale: Gas costs on Base are fractions of a cent, which is what makes sub-cent, per-call pricing for APIs and MCP tool calls economically sensible — something credit-card interchange fees make impossible.
  • Chain-agnostic by design: The payment header describes a network, token, amount, and recipient rather than assuming one blockchain, so the same protocol can settle across different chains as facilitator support expands.

Core components of an x402 architecture diagram

  • Client / agent: The AI agent (or an agent framework like a coding agent, browser agent, or Bedrock AgentCore-hosted agent) that wants a paid resource and controls a wallet capable of signing payments.
  • Resource server: The API or MCP server gating a paid endpoint. On an unauthenticated request it returns HTTP 402 Payment Required with a JSON body describing accepted payment requirements (network, asset, amount, recipient address, scheme).
  • Payment header: The agent constructs and signs a payment payload and resubmits the original request with an X-PAYMENT header attached — no separate checkout redirect or session required.
  • Facilitator: A third-party service (Coinbase, Cloudflare, or a self-hosted facilitator) that verifies the payment payload is valid and settles it on-chain on the resource server's behalf, so the API provider doesn't need to run its own blockchain node or wallet infrastructure.
  • Settlement network: The blockchain (commonly Base) and stablecoin (commonly USDC) that actually move value. Show this as the underlying settlement layer beneath the facilitator.
  • Wallet + spend policy: The agent's wallet, plus any policy-based spending controls (per-call caps, daily budgets, allow-listed recipients) that bound how much an autonomous agent can spend without human sign-off.

The x402 request flow

  1. Agent sends a normal HTTP request to a paid endpoint.
  2. Resource server responds 402 Payment Required with accepted payment requirements (asset, amount, network, recipient).
  3. Agent evaluates the price against its spend policy, signs a payment payload with its wallet, and resends the original request with the X-PAYMENT header set.
  4. Resource server forwards the payment payload to a facilitator for verification and settlement.
  5. Facilitator confirms the on-chain payment and returns a settlement confirmation to the resource server.
  6. Resource server fulfills the original request and returns the paid resource.

Draw this as a single sequence diagram with the facilitator as a side call between steps 4 and 5 — it's easy to accidentally draw the facilitator as a payment gateway the agent talks to directly, when in most integrations it's the resource server that verifies with the facilitator.

x402 vs AP2 vs the Agentic Commerce Protocol

ProtocolLayerBest for
x402HTTP-layer, stablecoin settlementMachine-to-machine micropayments: paid APIs, MCP tool calls, per-request pricing
AP2 (Agent Payments Protocol)Mandate/credential-based, card and bank railsConsumer commerce where an agent shops on a user's behalf against existing payment rails
Agentic Commerce Protocol (ACP)Checkout/catalog integrationMerchants exposing product catalogs and checkout directly to shopping agents

These aren't mutually exclusive — a shopping agent might use AP2 or ACP to complete a purchase from a merchant while using x402 to pay per-call for the pricing, inventory, or search APIs it queries along the way. Show them as separate protocol boxes on an agent-payments diagram rather than collapsing them into one “payments” node.

Prompt examples for x402 architecture diagrams

Paid MCP server with x402

"x402 architecture for a paid MCP server. AI agent (Claude with an MCP client) calls a tool exposed by a weather-data MCP server. Server responds 402 Payment Required with price 0.001 USDC on Base. Agent's wallet (managed by Bedrock AgentCore Payments) checks its per-call spend policy (max $0.01/call, $5/day), signs the payment, and resubmits the request with an X-PAYMENT header. MCP server forwards the payment to a Cloudflare facilitator for verification and settlement on Base, then returns the weather data. Show the flow as a sequence: Agent → MCP Server (402) → Agent (signs payment) → MCP Server → Facilitator → Base settlement → MCP Server → Agent (data). Annotate the spend policy check as a decision point before signing."

Agent-to-agent API marketplace with x402 billing

"Multi-agent API marketplace using x402 for machine-to-machine billing. A research agent calls three paid tool APIs (search, code execution, data enrichment) hosted by different providers, each priced per call and gated with 402 responses. A shared facilitator settles all three payments on Base using the agent's single wallet. Show the research agent as the hub, three resource servers as spokes each returning 402 then fulfilling after payment, and one shared facilitator node handling settlement for all three. Annotate cumulative spend against a $2 per-task budget cap enforced by the agent's orchestrator."

x402 alongside AP2 in a shopping agent

"Shopping agent architecture combining x402 and AP2. Agent uses x402 to pay per-query for a paid product-search API (fractions of a cent per query, settled in USDC on Base via a facilitator) while comparing prices across merchants. Once the user approves a purchase, the agent switches to AP2 — presenting an Intent Mandate and Cart Mandate to the merchant's payment processor, settled over existing card rails. Show two distinct payment paths converging on the same agent: a low-value x402 path for API access (dashed line, stablecoin icon) and a high-value AP2 path for the actual purchase (solid line, card/bank icon), with a human-approval gate before the AP2 path fires."

What to annotate on an x402 diagram

  • Price and asset: The amount and token (typically USDC) required per request, since this is what makes per-call pricing visible at a glance.
  • Facilitator identity: Which facilitator verifies and settles payments — a managed provider or a self-hosted one — since it's a trust boundary the resource server depends on.
  • Settlement network: The chain (Base, or others as facilitator support expands) so the diagram doesn't imply a single universal ledger.
  • Spend policy boundary: Per-call caps, daily budgets, and allow-listed endpoints that bound autonomous spend — this is the control most reviewers will ask about first.
  • Retry semantics: Whether the client automatically resubmits with the payment header on 402 or requires an explicit signing step, since that affects how “autonomous” the payment really is.

Related guides: AP2 protocol architecture, Agentic Commerce Protocol architecture, agent payment protocols, and the AI agent protocol stack.

Ready to try it yourself?

Start Creating - Free