# HTTP 402 response reference

> The PAYMENT-REQUIRED, PAYMENT-SIGNATURE and PAYMENT-RESPONSE headers of a real Algorand x402 payment, decoded field by field.

Use this page to read or debug x402 traffic: the three headers of one real payment, captured on LocalNet with `x402-algorand` 0.3.0 and the official `x402` 2.28.0 SDK: a FastAPI route `GET /weather` priced at 10,000 microALGO, protected by `payment_middleware` with an in-process facilitator whose account is both `payTo` and fee payer (the setup on [FastAPI](https://x402-avm.github.io/build/paywall-http-api#fastapi)). The buyer paid with `x402Client` and `PayerAvmSigner`. Addresses, the LocalNet network id and transaction ids differ on every machine and run.

The headers are defined by the x402 [HTTP transport (v2)](https://github.com/x402-foundation/x402/blob/main/specs/transports-v2/http.md), their JSON objects by the [x402 v2 specification](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md), and the Algorand-specific parts by the [exact scheme on Algorand](https://github.com/x402-foundation/x402/blob/main/specs/schemes/exact/scheme_exact_algo.md).

| Header | Direction | Status | Content |
|---|---|---|---|
| `PAYMENT-REQUIRED` | server to client | `402` | base64 of a JSON `PaymentRequired` |
| `PAYMENT-SIGNATURE` | client to server | (request) | base64 of a JSON `PaymentPayload` |
| `PAYMENT-RESPONSE` | server to client | `200` | base64 of a JSON `SettlementResponse` |

Each header value is standard base64 of UTF-8 JSON. Decode it with `json.loads(base64.b64decode(value))` in Python, `decodePaymentRequired(value)` in x402-avm-js, or `decode_payment_required_header` / `decode_payment_signature_header` / `decode_payment_response_header` from `x402.http`.

## 1. The 402 response

The unpaid request `GET /weather` returned:

```http
HTTP/1.1 402 Payment Required
content-type: application/json
cache-control: no-store
payment-required: eyJ4NDAyVmVyc2lvbiI6MiwiZXJyb3IiOiJQYXltZW50IHJlcXVpcmVkIiwicmVzb3VyY2UiOnsidXJsIjoiaHR0cDovLzEyNy4wLjAuMTo5MzAyL3dlYXRoZXIiLCJkZXNjcmlwdGlvbiI6IiIsIm1pbWVUeXBlIjoiIn0sImFjY2VwdHMiOlt7InNjaGVtZSI6ImV4YWN0IiwibmV0d29yayI6ImFsZ29yYW5kOnRnMGN5akV6MTRGWks5QlRwTDJxMFRPeUZiYzBNY3dZIiwiYXNzZXQiOiIwIiwiYW1vdW50IjoiMTAwMDAiLCJwYXlUbyI6IlVRUFgzQUdKRlY2Tk5aVzRXRUpET1ZDSTdUUUZRQjJYWlFQQUVOTTdCUFY0UUNCQ1Y1N0tOTTJRS1UiLCJtYXhUaW1lb3V0U2Vjb25kcyI6MzAwLCJleHRyYSI6eyJkZWNpbWFscyI6NiwiZmVlUGF5ZXIiOiJVUVBYM0FHSkZWNk5OWlc0V0VKRE9WQ0k3VFFGUUIyWFpRUEFFTk03QlBWNFFDQkNWNTdLTk0yUUtVIn19XX0=

{"error":"Payment required"}
```

Decoded `PAYMENT-REQUIRED`:

```json
{
  "x402Version": 2,
  "error": "Payment required",
  "resource": {
    "url": "http://127.0.0.1:9302/weather",
    "description": "",
    "mimeType": ""
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "algorand:tg0cyjEz14FZK9BTpL2q0TOyFbc0McwY",
      "asset": "0",
      "amount": "10000",
      "payTo": "UQPX3AGJFV6NNZW4WEJDOVCI7TQFQB2XZQPAENM7BPV4QCBCV57KNM2QKU",
      "maxTimeoutSeconds": 300,
      "extra": {
        "decimals": 6,
        "feePayer": "UQPX3AGJFV6NNZW4WEJDOVCI7TQFQB2XZQPAENM7BPV4QCBCV57KNM2QKU"
      }
    }
  ]
}
```

| Field | Value here | Meaning |
|---|---|---|
| `x402Version` | `2` | Protocol version. Must be 2 for this header format ([spec §5.1](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md#51-paymentrequired-schema)). |
| `error` | `"Payment required"` | Optional human-readable reason. |
| `resource.url` | the requested URL | The protected resource. |
| `resource.description`, `resource.mimeType` | `""` | Optional; set from the route configuration (`PaymentGate` sets the description to `"Paid MCP tool call"`). |
| `accepts` | one entry | The payment options the server accepts. A server may list several (for example MainNet USDC and TestNet ALGO); clients pick one they can pay. |
| `accepts[].scheme` | `"exact"` | Pay exactly `amount`. |
| `accepts[].network` | `"algorand:tg0cyjEz14FZK9BTpL2q0TOyFbc0McwY"` | CAIP-2 id: `algorand:` plus the first 32 characters of the URL-safe base64 genesis hash. This is the default LocalNet id. See [Networks](https://x402-avm.github.io/production/networks). |
| `accepts[].asset` | `"0"` | ASA id as a string. `"0"` (native ALGO, paid with a `pay` transaction) is an extension of `x402-algorand`; the specification defines ASA ids such as USDC `"31566704"`. |
| `accepts[].amount` | `"10000"` | Amount in base units, as a string: 10,000 microALGO = 0.01 ALGO. |
| `accepts[].payTo` | 58-character address | The recipient. |
| `accepts[].maxTimeoutSeconds` | `300` | How long the payment may take to complete. |
| `accepts[].extra.decimals` | `6` | Decimals of the asset, for display. Added by `x402-algorand`'s server scheme. |
| `accepts[].extra.feePayer` | an address of the facilitator | Optional in the specification. When present, the client builds a two-transaction group in which this account pays all fees. Here it equals `payTo` because one account plays both roles. |

### From a PaymentGate MCP server

A `tools/call` posted to a `PaymentGate` server (`POST /mcp`, Streamable HTTP) without payment gets the same kind of `402`. The decoded header captured from a server built like the [Quickstart](https://x402-avm.github.io/quickstart) server (here on port 9303, `echo` at 5,000 microALGO) differs in these fields:

```json
{
  "resource": { "url": "http://127.0.0.1:9303/mcp", "description": "Paid MCP tool call", "mimeType": "" },
  "accepts": [
    {
      "amount": "5000",
      "extra": {
        "decimals": 6,
        "feePayer": "<server address>",
        "genesisHash": "tg0cyjEz14FZK9BTpL2q0TOyFbc0McwYsFJbszmFANk=",
        "genesisId": "dockernet-v1"
      }
    }
  ]
}
```

`extra.genesisHash` and `extra.genesisId` are optional hints added by `x402-algorand`'s server scheme when the network is registered (as `ai-economy-sdk` does for `"localnet"`, and as MainNet and TestNet always are). x402-avm-js 0.4.0 refuses to pay a requirement whose hints disagree with its algod (`NetworkMismatchError`).

## 2. The paid retry

The client retried `GET /weather` with a `PAYMENT-SIGNATURE` header. Decoded:

```json
{
  "x402Version": 2,
  "payload": {
    "paymentGroup": [
      "iqNmZWXNB9CiZnbNBk+jZ2VurGRvY2tlcm5ldC12MaJnaMQgtg0cyjEz14FZK9BTpL2q0TOyFbc0McwYsFJbszmFANmjZ3JwxCCCufmcdC8hsJUS97zRK4wR7ETp1mhBbrxnweg/EerpmaJsds0KN6Rub3RlxCJ4NDAyLWZlZS1wYXllci0xNzk1MDcxODUyODkxNjY5Njc0o3JjdsQgpB99gMktfNbm3LESN1RI/OBYB1fMHgI1nwvryAgir36jc25kxCCkH32AyS181ubcsRI3VEj84FgHV8weAjWfC+vICCKvfqR0eXBlo3BheQ==",
      "gqNzaWfEQBGwW+LIuRKcEOqamNuvfwgAFw4SwON2endRckyU+qGecunwgLkiur/A3aW9rgdspsQNBre7IpQqAmSMSfKz/QOjdHhuiqNhbXTNJxCiZnbNBk+jZ2VurGRvY2tlcm5ldC12MaJnaMQgtg0cyjEz14FZK9BTpL2q0TOyFbc0McwYsFJbszmFANmjZ3JwxCCCufmcdC8hsJUS97zRK4wR7ETp1mhBbrxnweg/EerpmaJsds0KN6Rub3RlxCB4NDAyLXBheW1lbnQtMTc5NTA3MTg1Mjg5MTY4MTcyN6NyY3bEIKQffYDJLXzW5tyxEjdUSPzgWAdXzB4CNZ8L68gIIq9+o3NuZMQg7SrCQfscmlZIcOcTNKBlDOHS6X+CkHRfDujoAbl9LqykdHlwZaNwYXk="
    ],
    "paymentIndex": 1
  },
  "accepted": {
    "scheme": "exact",
    "network": "algorand:tg0cyjEz14FZK9BTpL2q0TOyFbc0McwY",
    "asset": "0",
    "amount": "10000",
    "payTo": "UQPX3AGJFV6NNZW4WEJDOVCI7TQFQB2XZQPAENM7BPV4QCBCV57KNM2QKU",
    "maxTimeoutSeconds": 300,
    "extra": {
      "decimals": 6,
      "feePayer": "UQPX3AGJFV6NNZW4WEJDOVCI7TQFQB2XZQPAENM7BPV4QCBCV57KNM2QKU"
    }
  },
  "resource": {
    "url": "http://127.0.0.1:9302/weather",
    "description": "",
    "mimeType": ""
  }
}
```

| Field | Meaning |
|---|---|
| `x402Version` | `2`. |
| `accepted` | The `accepts` entry the client chose, copied unchanged. The facilitator rejects the payment if its `scheme` or `network` differs from the server's requirement (`unsupported_scheme`, `network_mismatch`). |
| `resource` | Optional copy of the resource. |
| `payload` | Scheme-specific data ([spec §5.2](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md#52-paymentpayload-schema)). For Algorand: |
| `payload.paymentGroup` | Every transaction of the atomic group, in order, each base64 msgpack. Signed transactions are encoded as signed transactions; the fee payer's transaction is sent unsigned. At most 16 entries. |
| `payload.paymentIndex` | Index of the transaction that pays the resource server: `1` with a fee payer, `0` without. |

The two transactions, decoded with `algosdk.encoding.msgpack_decode` (msgpack field names):

| Field | Transaction 0 (fee payer, unsigned) | Transaction 1 (buyer, signed) |
|---|---|---|
| `type` | `pay` | `pay` (`axfer` for an ASA) |
| `snd` | fee payer | buyer |
| `rcv` | fee payer (a payment to itself) | `payTo` |
| `amt` | 0 (omitted) | `10000` |
| `fee` | `2000`: twice the 1,000 microALGO minimum, covering both transactions | 0 (omitted) |
| `fv`, `lv` | `1615`, `2615` | `1615`, `2615` (a window of 1,000 rounds) |
| `gen`, `gh` | `dockernet-v1`, the LocalNet genesis hash | same |
| `grp` | the group id | same group id |
| `note` | `x402-fee-payer-<nanosecond timestamp>` | `x402-payment-<nanosecond timestamp>` |
| `sig` | none: the facilitator signs it after verification | the buyer's Ed25519 signature |

The notes make each group, and so each payment hash, unique. What the facilitator checks before it signs transaction 0 is listed on [AVM exact scheme](https://x402-avm.github.io/reference/protocol/avm-exact-scheme#verification-steps).

## 3. The 200 response

The facilitator verified the group, the route ran, and the middleware settled the payment:

```http
HTTP/1.1 200 OK
content-type: application/json
payment-response: eyJzdWNjZXNzIjogdHJ1ZSwgInBheWVyIjogIjVVVk1FUVAzRFNORk1TRFE0NEpUSklERkJUUTVGMkw3UUtJSElYWU81RFVBRE9MNUYyV01UQ0pFQUEiLCAidHJhbnNhY3Rpb24iOiAiNTRNRzYyNFpXTE43WVRLSFBGSE5ZSTRaTTQ1S1M1SDROUVBPRkNCU0VGRlhHVVYySDRXQSIsICJuZXR3b3JrIjogImFsZ29yYW5kOnRnMGN5akV6MTRGWks5QlRwTDJxMFRPeUZiYzBNY3dZIn0=

{"city":"Boston","temperature":68}
```

Decoded `PAYMENT-RESPONSE`:

```json
{
  "success": true,
  "payer": "5UVMEQP3DSNFMSDQ44JTJIDFBTQ5F2L7QKIHIXYO5DUADOL5F2WMTCJEAA",
  "transaction": "54MG624ZWLN7YTKHPFHNYI4ZM45KS5H4NQPOFCBSEFFXGUV2H4WA",
  "network": "algorand:tg0cyjEz14FZK9BTpL2q0TOyFbc0McwY"
}
```

| Field | Meaning |
|---|---|
| `success` | `true` when the group was submitted and confirmed. |
| `payer` | The buyer's address. |
| `transaction` | The ID of `paymentGroup[paymentIndex]`, the buyer's payment, as the [Algorand exact scheme](https://github.com/x402-foundation/x402/blob/main/specs/schemes/exact/scheme_exact_algo.md) requires. Here it is transaction 1's ID; x402-algorand 0.2.x returned the fee payer transaction's ID instead. Look it up on algod (`/v2/transactions/pending/<id>`) or an explorer. |
| `network` | CAIP-2 id of the network it settled on. |
| `errorReason` | Only on failure, with one of the [error codes](https://x402-avm.github.io/reference/errors). |

The buyer's balance fell by exactly 10,000 microALGO; the fee payer paid the 2,000 microALGO fee.

### From a PaymentGate MCP server

On Streamable HTTP, the paid `tools/call` returns `200` with `content-type: text/event-stream`, the JSON-RPC result in the body, and a `PAYMENT-RESPONSE` header of the same shape. The header is only sent when the tool succeeded and the payment settled: a failed tool returns an MCP error result and nothing is submitted.

Sending the same `PAYMENT-SIGNATURE` again after it settled returns `402` with `{"error":"transaction_simulation_failed"}`: the group is already on chain, so it fails verification. A duplicate sent while the first use is still in progress gets `402` with `{"error":"Replay detected"}`.

## Reproduce it

Run the [FastAPI paywall](https://x402-avm.github.io/build/paywall-http-api#fastapi) on LocalNet, then:

```python
import base64, json
import httpx

r = httpx.get("http://127.0.0.1:9211/weather")
print(r.status_code, json.dumps(json.loads(base64.b64decode(r.headers["payment-required"])), indent=2))
```

For the paid side, use the [HTTPX client](https://x402-avm.github.io/build/pay-from-python#pay-http-apis) and print `response.headers["payment-response"]` the same way.

Source: https://x402-avm.github.io/reference/protocol/http-402
