# x402 Explained: How AI Agents Pay Per Request Over HTTP

The x402 protocol is an open standard that lets a client, such as an AI agent, pay for a web resource inside the HTTP request itself: the server answers `402 Payment Required` with its price, the client signs a payment and retries, and the server returns the resource once the payment checks out. No account, API key or stored card is needed on the client side.

That one sentence is what most explainers stop at. This post goes further in three places where the guides we read on 1 December 2026 were thin or out of date: the **v2 header names** (several popular guides still show v1's `X-PAYMENT`), a direct **x402 vs Stripe** comparison based on Stripe's own docs, and how **x402 for MCP servers** actually works at the message level, including a client default you should change before you give an agent a wallet.

Facts below were checked on 1 December 2026 against the [x402 repository](https://github.com/x402-foundation/x402), the [v2 specification](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md), [x402.org](https://www.x402.org) and [Stripe's x402 docs](https://docs.stripe.com/payments/machine/x402). Nothing here is financial advice, and x402 has no token you need to buy. If you want SDK picks rather than an explainer, read our [x402 and AP2 tools roundup](https://agxmart.com/blog/best-x402-and-ap2-agent-payment-tools).

## What is x402?

x402 revives an HTTP status code that sat unused for decades, `402 Payment Required`, and gives it a defined payload. It is run by the x402 Foundation at the Linux Foundation, whose [operational launch](https://x402.org/linux-foundation-announces-operational-launch-of-x402-foundation-to-standardize-internet-native-payments-for-ai-agents-and-applications/) was announced on 14 July 2026. Coinbase contributed the protocol, and the main repository is now `x402-foundation/x402`; the older `coinbase/x402` describes itself as a development fork.

The [v2 specification](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md) names three roles:

- **Client:** whatever wants the resource. A browser script, a backend job or an agent making a tool call.
- **Resource server:** the API, page or tool that charges.
- **Facilitator:** an optional service that checks and settles payments so the resource server does not have to run blockchain code itself.

Facilitators expose three endpoints in the spec: `POST /verify` (check a payment without committing it), `POST /settle` (commit it) and `GET /supported` (list the scheme and network pairs it handles).

Networks are named with CAIP-2 identifiers, for example `eip155:8453` for Base mainnet and `eip155:84532` for the Base Sepolia test network. [x402.org](http://x402.org) says the protocol supports all EVM-compatible chains and Solana, charges "zero protocol fees" and leaves only the network's own fees. The same page calls x402 production-ready; that is the project's own claim, and its README is more careful, warning not to assume the public [x402.org](http://x402.org) facilitator is your production path on mainnet.

## How an x402 payment works, header by header (v2)

From the [HTTP transport spec](https://github.com/x402-foundation/x402/blob/main/specs/transports-v2/http.md), as of 1 December 2026:

1. The client requests a resource.
2. The server replies `402 Payment Required` with a `PAYMENT-REQUIRED` header: a base64-encoded list of what it accepts (scheme, network, asset, amount, pay-to address).
3. The client picks one option, signs a payment payload and retries with a `PAYMENT-SIGNATURE` header.
4. The server verifies the payload, itself or through the facilitator's `/verify`.
5. The server does the work, settles through `/settle` or on its own, and returns `200 OK` with a `PAYMENT-RESPONSE` header carrying the settlement result.

**v1 vs v2 headers.** Version 1 used `X-PAYMENT` for the client's payment and `X-PAYMENT-RESPONSE` for the receipt. The spec's version history dates v2 to 9 December 2025, and the HTTP transport doc tells servers that support both versions to handle both sets of names. If a tutorial only shows `X-PAYMENT`, it describes v1.

**Schemes.** The README lists `exact` (fixed price), `upto` (a cap, with the seller charging actual usage) and `batch-settlement` (many small charges settled together). The v2 spec also defines `auth-capture`. Pick `exact` unless you have a reason not to; it is the scheme every example in the official docs uses.

**Package versions.** The repository does not use GitHub Releases. It tags each package instead, and `npm view @x402/mcp version` returned `2.32.0`, published 20 November 2026 (run on 1 December 2026).

## x402 vs Stripe

"x402 vs Stripe" sounds like a choice between rivals. Stripe's own docs show it is not quite that: Stripe [accepts x402 payments](https://docs.stripe.com/payments/machine/x402) as part of its machine payments product, which it previewed in February 2026 according to [The Block](https://www.theblock.co/post/389352/stripe-adds-x402-integration-usdc-agent-payments) (11 February 2026). So the real question is whether you run x402 yourself, run it with Stripe recording the payments, or use Stripe's card flows.

| As of 1 December 2026 | x402 on your own server | x402 through Stripe | Stripe card payments for agents |
| --- | --- | --- | --- |
| **What the client needs** | A wallet holding a supported asset | A wallet with USDC on Base | A card credential; Stripe's docs point to its Machine Payments Protocol (MPP) for this |
| **Networks and assets** | Any network your facilitator supports (EVM chains and Solana per [x402.org](http://x402.org)) | USDC on Base in Stripe's machine payments table | Card networks |
| **Who settles** | Your facilitator, or your own code | The Coinbase Developer Platform facilitator on mainnet, per Stripe's docs | Stripe |
| **Where the money lands** | Your wallet, on-chain | Your Stripe balance, recorded as a PaymentIntent and paid out in fiat | Your Stripe balance |
| **Account or sign-up** | None for the client; none with a third party if you self-settle | Request "Stablecoins and Crypto" in the Stripe Dashboard and wait for approval | A Stripe account |
| **Where it is offered** | Anywhere the network is reachable | US businesses in every state except New York; others email Stripe to request access in 30+ countries | See Stripe's supported countries |
| **Minimum charge** | Set by you and the network | 0.01 USDC | 0.50 USD for card payments via Stripe's agent tokens |
| **Status** | Open spec at version 2 | Uses preview API versions (`2026-05-27.preview` for mainnet in the docs) | Varies by product |

Two details from Stripe's guide that most comparison posts miss:

- **Stripe is not the facilitator.** The flow in the docs is: your server returns a 402 that includes a Stripe deposit address, the CDP facilitator settles on-chain, and then your server calls Stripe to create a PaymentIntent with the transaction hash. Stripe records and pays out; it does not move the stablecoin.
- **Cards need a second protocol.** The docs say that to accept card payments alongside stablecoins, you should also integrate MPP. x402 on Stripe is stablecoin-only.

When to pick which: self-run x402 if you want no third-party account and are happy to hold funds on-chain; x402 through Stripe if your accounting, tax reporting and payouts already live in Stripe; card flows if your buyers are people whose agents hold cards rather than wallets. Refunds and disputes work differently in each. On-chain settlement has no chargeback, so plan refunds yourself.

## x402 for MCP servers

MCP tool calls do not travel as plain HTTP requests to your route, so the HTTP headers above do not apply directly. The x402 repo has a separate [MCP transport spec](https://github.com/x402-foundation/x402/blob/main/specs/transports-v2/mcp.md) for this. Its rules, as of 1 December 2026:

- **Asking for payment.** A server MUST answer an unpaid call to a paid tool with a tool result that has `isError: true`, with the `PaymentRequired` object in both `structuredContent` and `content[0].text`. Clients should read `structuredContent` first.
- **Paying.** The client retries the same tool call with the payment payload in `_meta["x402/payment"]`.
- **Receipt.** The server returns the tool result with settlement details in `_meta["x402/payment-response"]`.
- **Failed settlement.** If settlement fails after the tool already ran, the server should return only the payment error, not the tool's output.

This keeps payments inside normal tool calling, so any MCP client that understands the convention can pay, and one that does not just sees an error result with the price in it.

### Charge for a tool with @x402/mcp

The official package wraps a normal tool handler. Quoted from the [@x402/mcp README](https://github.com/x402-foundation/x402/tree/main/typescript/packages/mcp), not run for this post:

```bash
npm install @x402/mcp @x402/core @modelcontextprotocol/sdk
```

```typescript
const accepts = await resourceServer.buildPaymentRequirements({
  scheme: "exact",
  network: "eip155:84532",
  payTo: "0x...", // Your wallet address
  price: "$0.10",
});

const paid = createPaymentWrapper(resourceServer, { accepts });

mcpServer.tool(
  "financial_analysis",
  "Advanced AI-powered financial analysis. Costs $0.10.",
  { ticker: z.string() },
  paid(async (args) => {
    const analysis = await performAnalysis(args.ticker);
    return { content: [{ type: "text", text: analysis }] };
  })
);
```

Free tools on the same server need no wrapper. The wrapper also takes hooks: `onBeforeExecution` (return `false` to stop the call without charging, useful for rate limits), `onAfterExecution` and `onAfterSettlement` (send a receipt). `eip155:84532` is a test network; switch the network and facilitator together when you go live.

Other routes, if you are already on one of these stacks: Cloudflare's Agents SDK has a [`paidTool`](https://developers.cloudflare.com/agents/x402/charge-for-mcp-tools/) method on a server wrapped with `withX402`, and Vercel's separate `x402-mcp` package, [announced on 12 September 2025](https://vercel.com/blog/introducing-x402-mcp-open-protocol-payments-for-mcp-tools), has its own `paidTool` with a different argument order. Do not mix examples from the three; the function signatures differ.

### The client default to change before an agent gets a wallet

On the paying side, `createx402MCPClient` has `autoPayment` set to `true` by default, and with the default settings the README says the client pays any request that passes its spend controls: default assets only, and `$1` **per payment** unless you set `spendControls`. The `onPaymentRequested` callback is your human-in-the-loop approval gate; return `false` to refuse.

That matters because the server sets the price. A tool description is text the model reads, so a server can change its price or its description between calls, the same pattern as an MCP rug pull. Three habits help:

- Set `spendControls` to the lowest cap that works for your use.
- In `onPaymentRequested`, compare the amount, asset and `payTo` against what you expected, and refuse on a mismatch. The README recommends this to pin terms.
- Give the agent its own wallet with a small balance, treated like any other non-human identity credential: scoped, short-lived where possible, and never your main wallet.

If you run many paid servers, an [MCP gateway](https://agxmart.com/mcp-gateways) is a natural place to apply one spending policy across all of them.

## Where x402 fits next to other agent protocols

x402 settles money. It does not prove what a person agreed to, and it does not move messages between agents.

- **MCP** connects an agent to tools; x402 adds a price to a tool call. Our [MCP vs API post](https://agxmart.com/blog/mcp-vs-api) covers when MCP is worth it at all.
- [**A2A**](https://agxmart.com/a2a) connects agents to agents; Google's [A2A x402 extension](https://github.com/google-agentic-commerce/a2a-x402) carries x402 payments over it.
- [**AP2**](https://agxmart.com/ap2) records what a user authorised an agent to buy, mostly on card rails today. It answers "was this allowed", while x402 answers "was this paid".

The [agent protocols hub](https://agxmart.com/agent-protocols) has the full map, and the [x402 directory](https://agxmart.com/x402) lists x402 projects with a "What it can touch" label on each listing page. Check that label before you connect anything to a wallet.

## FAQ

### What is x402 in simple terms?

It is a way to charge for a URL or a tool call the way a vending machine charges: the server states a price in a `402 Payment Required` response, the client pays and asks again, and the server hands over the result. It works over plain HTTP, and the spec also defines MCP and A2A versions.

### Is x402 a cryptocurrency or a token?

No. x402 is a protocol, not a coin, and you do not need any special token to use it. Payments are usually made in stablecoins such as USDC on networks like Base or Solana. [Ledger's guide](https://www.ledger.com/academy/topics/economics-and-regulation/what-is-x402) warns readers to be wary of any token that claims to be the official x402 coin.

### x402 vs Stripe: do I have to choose?

Not necessarily. Stripe accepts x402 payments in USDC on Base and records them as PaymentIntents in your Stripe balance, with settlement done by the Coinbase Developer Platform facilitator. You can also run x402 with no Stripe account at all, or use Stripe's card flows when buyers hold cards rather than wallets.

### How do I use x402 for MCP servers?

Wrap each paid tool's handler with `createPaymentWrapper` from `@x402/mcp` and set a price, network and pay-to address. Unpaid calls get an `isError: true` result containing the price, and paying clients retry with `_meta["x402/payment"]`. Free tools on the same server stay as they are.

### Does x402 charge fees?

[x402.org](http://x402.org) says the protocol itself charges no fees, and you still pay the payment network's fees. A hosted facilitator or a service like Stripe may set its own terms, so read them before you go live.

### Can an AI agent overspend with x402?

It can if you leave the defaults. The official MCP client pays automatically up to `$1` per payment unless you set spend controls, so set a cap, check each payment request in `onPaymentRequested`, and keep the agent's wallet balance small.

## List your paid MCP server or agent

If you built an x402-enabled MCP server, API or agent, add it to AGXmart so developers can find it next to the rest of the [x402 ecosystem](https://agxmart.com/x402). List it and start selling. [Submit your listing](https://agxmart.com/submit), or see the [API, MCP endpoint and CLI on /developers](https://agxmart.com/developers) to search listings from your own tools. This command was run on 1 December 2026:

```bash
npx https://agxmart.com/cli.tgz search postgres
```

---

*Originally published on* [*AGXmart*](https://agxmart.com/blog/x402-protocol-explained)*. AGXmart is a marketplace for open-source AI agents, MCP servers and agent skills with public security scans. Search and install from your terminal with* `npx agxmart`*, or list your own tool and start selling.*
