satledger satledger.org

Notes · 31 October 2026, updated 18 November 2026

About 2,300 x402 payment offers are too big for Python's aiohttp

x402 v2 puts the whole payment offer in one HTTP header. aiohttp refuses any header line over 8,190 bytes, name included, and it fails the whole response rather than truncating it. The buyer gets an exception instead of an offer, and the seller's logs show a normal 402.

x402 lets an HTTP server charge for a request. The server answers 402 Payment Required with an offer, and the client pays and retries. In v2 the offer travels in one response header, PAYMENT-REQUIRED, as base64 of JSON: every accepted network and asset, the resource's description, and often a JSON Schema of its input and output.

Most HTTP clients cap header sizes. None of the ones that do truncates an oversized header: each refuses the whole response.

The limits, measured

I served a 402 of known size from a raw socket and bisected for the largest each client accepts. Then I varied the rest of the response, with an extra header and a longer status line, to find what each one actually counts.

ClientWhat it countsLimit
aiohttp 3.13–3.14 (Python)each header line: name, : and value8,190 B
fetch / undici (Node 24)name + value, summed over all headers16,383 B
node:http (Node 24)status reason phrase, plus name + value of every header16,383 B
requests / urllib (Python)each line; number of headers65,534 B; 99
httpx / h11 (Python)nothing, when the head arrives in one piecepassed 80,000 B

aiohttp's limit is the one that bites. It applies per header, and it is half of everyone else's. With the 18 bytes of PAYMENT-REQUIRED: , a challenge of 8,173 bytes or more is invisible to an aiohttp buyer.

aiohttp has two parsers, and they count differently. The pure-Python one, used when its C extension is missing or switched off, counts the whole line in every position. The compiled one counts name and value for the first header and the value alone for every later one, so it reads up to 8,190 bytes of value there (aiohttp#14295). It is never stricter, and a seller cannot know which one a buyer runs, so the line is the limit to design for.

How many offers are over it

CDP's public discovery listing holds what sellers advertise. Each entry carries the same accepts and extensions that the seller's PAYMENT-REQUIRED header encodes, so base64 of an entry estimates the header. On 18 November the listing had 35,038 entries, and 2,846 of them, from 300 hosts, estimate over the line. One host accounts for 592. Fifteen estimate over 16 KB.

The count moves as sellers list and leave. It was 4,443 on 6 November. About half of the fall since then is one host that now lists far fewer offers, not headers getting smaller. An independent census by smartflowproai-lang matched my 31 October figures, and their repeated reads showed the same sellers over the line day after day, so the set is not a passing spike.

An estimate is not a measurement, so I fetched real headers:

Scaling the first sample, about 2,300 listed offers are unreadable by an aiohttp buyer, with a 95% interval of roughly 1,900 to 2,600.

One sampled offer is also unreadable by Node. Its PAYMENT-REQUIRED value is 15.7 KB, under Node's limit on its own, but Node counts every header together, and the rest of the response takes the total to 16,543 bytes. Node 24's fetch fails with UND_ERR_HEADERS_OVERFLOW, and reads it with the flag below. The listing estimate cannot see this case, because it does not know a seller's other headers.

What makes them big

I decoded the 27 refused challenges.

Only one of the 27 served JSON with whitespace in it. Compacting is good hygiene, but it is not the fix here.

What to do

If you sell:

  1. Measure your 402, including the error branch. The checker below reads the head exactly as it arrives, judges it against each client above, and names the part of the challenge that makes it big.
    python x402_header_check.py --error-branch https://your.host/paid-route
  2. Keep the Bazaar schema and examples small: one representative item, not a full response. They are advertising, and the listing already has a copy.
  3. Offer the networks your buyers use, not every network your facilitator supports. Each one costs about 310 bytes.
  4. Bound anything you echo into the challenge. If an error message can grow, so can the header, on exactly the branch where a buyer has just tried to pay.

If you buy:

aiohttp.ClientSession(max_field_size=16384)
node --max-http-header-size=32768 app.js     # fetch and node:http

I tested both against oversized headers: the aiohttp setting with a 9 KB value, the Node flag with a 20 KB one.

Method and limits

The checker

x402-header-check is one Python file with no dependencies, under Apache-2.0. Point it at a URL. It exits 0 when every client reads the head, and 1 when one refuses it. It never sends a payment that could settle.

I found this while measuring the 402s of my own x402 service, satledger, during a public review of its header sizes on the x402 repository.