Agentic Web 10 min read

x402 Protocol: How AI Agents Pay for Services

HTTP has always had a 402 status code reserved for "Payment Required." For decades it sat unused. Now, with AI agents that need to purchase services autonomously, it finally has a purpose.

When a human wants to buy something online, they fill out a checkout form, enter credit card details, and click "Pay." But what happens when an AI agent needs to pay for an API call? It doesn't have a credit card. It can't fill out forms. It needs a payment protocol that works at machine speed, without human intervention.

That's exactly what the x402 protocol solves.

The Problem: Agents Need to Pay

AI agents are increasingly autonomous. They browse the web, call APIs, and complete tasks on behalf of users. But most paid services require human-oriented payment flows: sign up for an account, enter billing info, manage subscriptions. This creates a bottleneck in the agentic workflow.

What agents need is a way to discover a price, make a payment, and receive access — all in a single HTTP request-response cycle.

How x402 Works

The x402 protocol is elegantly simple. It uses the HTTP 402 status code that was reserved in the original HTTP spec but never standardized. Here's the flow:

  1. 1

    Agent Makes a Request

    The agent calls a paid API endpoint without payment credentials.

  2. 2

    Server Returns 402

    The server responds with HTTP 402 and a JSON body containing: the price, accepted currency (USDC), network (Base), recipient wallet address, and a facilitator URL for payment verification.

  3. 3

    Agent Pays

    The agent sends USDC on Base to the specified wallet. This happens via the agent's own crypto wallet (like Coinbase Agentic Wallets).

  4. 4

    Agent Retries with Proof

    The agent retries the original request with an X-PAYMENT header containing the transaction hash. The server verifies payment via the facilitator and returns the requested resource.

Why USDC on Base?

The x402 protocol uses USDC (a stablecoin pegged to the US dollar) on the Base network (Coinbase's L2 blockchain). This combination offers several advantages for machine-to-machine payments:

Why This Stack Works for Agents

  • Stablecoin — USDC is pegged 1:1 to USD. No volatility risk. $0.01 today is $0.01 tomorrow.
  • Low fees — Base transactions cost fractions of a cent. Micropayments are viable.
  • Fast settlement — Transactions confirm in seconds, not days like traditional payment rails.
  • No intermediaries — No payment processor, no merchant account, no chargebacks. Peer-to-peer.

What a 402 Response Looks Like

When an agent hits a paid endpoint on MarketOS without valid auth, it receives something like this:

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "error": "payment_required",
  "x402": {
    "version": "1",
    "accepts": [{
      "scheme": "exact",
      "network": "base",
      "asset": "USDC",
      "maxAmountRequired": "100000",
      "resource": "/api/v1/generate/marketing",
      "payTo": "0x...",
      "facilitator": "https://x402.org/facilitator"
    }]
  }
}

The maxAmountRequired is in the smallest unit (6 decimals for USDC), so 100000 = $0.10. The agent reads this, makes the payment, and retries with proof.

Coinbase Agentic Wallets

For agents to pay, they need wallets. Coinbase has introduced Agentic Wallets — crypto wallets designed specifically for AI agents. These wallets can hold USDC, sign transactions, and operate within spending limits set by the human owner. The agent gets autonomy to make purchases up to a threshold, while the human retains ultimate control.

Stripe has also entered this space with their Agentic Commerce Protocol (ACP), which enables agents to make purchases using traditional payment rails. The ecosystem is converging on the idea that agents need their own payment capabilities.

How MarketOS Uses x402

The MarketOS Agentic API supports x402 as its pay-per-use payment method. Existing plan holders ($19.99/mo subscription or $199 lifetime license) get API access included with 1,000 requests/day. But for agents without a plan, x402 enables frictionless per-request payment — $0.05 for generation endpoints, $0.01 for lightweight calls like captions and scraping. No account creation, no subscription, no credit card.

This aligns with our BYOK philosophy: agents bring their own AI keys and pay providers directly at wholesale rates. The orchestration fee covers MarketOS's value-add — prompt engineering, brand context, multi-model routing — while keeping AI costs transparent and unmarketed.

The Bigger Picture: Machine-to-Machine Commerce

x402 is one piece of a larger shift. We're moving from a web where humans browse and buy to one where agents discover services (via llms.txt), negotiate terms, make payments, and consume APIs — all autonomously. The building blocks are falling into place:

  • Discovery: llms.txt, /.well-known/agents, MCP
  • Authentication: API keys, OAuth, BYOK
  • Payment: x402 (crypto), Stripe ACP (fiat), Coinbase Agentic Wallets
  • Communication: A2A (Agent-to-Agent), MCP, REST APIs

The agentic economy is being built right now. x402 is how agents will pay for it.

Build for the Agentic Web

MarketOS supports x402 payments, BYOK authentication, and llms.txt discovery. Start building today.