ENTANGLEIT
Guides

How x402 payments work — HTTP 402, pay-per-call APIs, and sats

One status code, two headers, no accounts. The protocol agents already know how to use.

HTTP reserved 402 Payment Required decades ago and never used it. x402 makes it real: a standard challenge/response handshake that lets any HTTP client pay for a call without signup, invoicing, or a human.

The handshake

buyer                                    seller
  │  GET /resource                          │
  │ ───────────────────────────────────────►│
  │  402 Payment Required                   │
  │  PAYMENT-REQUIRED: <base64 challenge>   │
  │ ◄───────────────────────────────────────│
  │                                         │
  │  GET /resource                          │
  │  PAYMENT-SIGNATURE: <base64 payment>    │
  │ ───────────────────────────────────────►│  verify → broadcast
  │  200 OK + body                          │
  │  PAYMENT-RESPONSE: <txid>               │
  │ ◄───────────────────────────────────────│

The challenge describes what to pay: scheme (exact), network (bsv:mainnet), amount in satoshis, recipient (payTo), and the resource. The payment proof is a signed transaction. Whoever broadcasts first wins; idempotent servers dedupe on txid so a replay can't buy a second call.

Why agents love it

Why BSV settlement

x402 is network-agnostic; the economics decide. Per-call API prices are sub-cent. You need settlement where:

BSV's fee model makes a 20-sat call economically sane. The gateway and agentpay use ARC for broadcast and WhatsOnChain for indexing; sellers can verify independently.

What a challenge looks like

Decoded, a BSV challenge is ordinary JSON:

{
  "x402Version": 2,
  "scheme": "exact",
  "network": "bsv:mainnet",
  "payTo": "1…",
  "maxAmountRequired": "20",
  "asset": "BSV",
  "resource": "https://example.com/forecast?city=YYZ",
  "description": "7-day forecast"
}

The buyer encodes its signed transaction as PAYMENT-SIGNATURE (base64 envelope with txHex). The seller verifies amount, recipient, and that the transaction is well-formed and unspent, then broadcasts.

Where the pieces live in this stack

Designing for pay-per-call

FAQ

Is x402 a standard?

It's an emerging open protocol (the x402 ecosystem) with a small, stable core: 402 challenges, payment proofs, and per-network settlement. Implementations vary in the envelope details; the handshake is the standard part.

What happens if the payment is invalid?

The seller rejects it with 402 and a reason. Nothing is served and no funds move — an invalid proof is just a bad request.

Can I accept both card and x402?

Yes, but keep them separate flows. Humans get checkout sessions; agents get 402s. Mixing the two in one endpoint confuses both buyers.

How do refunds work?

On-chain payments are final. Refund policy belongs in the service contract: retry the call, credit downstream, or return a compensating transfer. agentpay records refunds when sellers reject settlement before broadcasting.