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.
| Client | What it counts | Limit |
|---|---|---|
| aiohttp 3.13–3.14 (Python) | each header line: name, : and value | 8,190 B |
| fetch / undici (Node 24) | name + value, summed over all headers | 16,383 B |
| node:http (Node 24) | status reason phrase, plus name + value of every header | 16,383 B |
| requests / urllib (Python) | each line; number of headers | 65,534 B; 99 |
| httpx / h11 (Python) | nothing, when the head arrives in one piece | passed 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:
- 40 offers estimated over the limit, one per host. 33 answered with a 402, and aiohttp refuses 27 of the 33. The other six serve a smaller header than their listing suggests.
- 40 random offers. 36 answered with a v2 header. The estimate put one over the limit; its served header was smaller, and aiohttp reads all 36.
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.
- 25 are mostly discovery metadata in
extensions. In 18 it is the Bazaar schema (extensions.bazaar.schema), the JSON Schema of the endpoint's input and output; in six, the Bazaar's example input and output (extensions.bazaar.info); in one, a sign-in extension's description. All of it is sent with every 402. - 2 are mostly
accepts. Across the listing, an offer is a median 232 bytes of JSON, so every extra way to pay costs about 310 bytes of header once base64'd. 774 of the 2,846 offers over the line list 12 or more.
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:
- 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 - Keep the Bazaar schema and examples small: one representative item, not a full response. They are advertising, and the listing already has a copy.
- Offer the networks your buyers use, not every network your facilitator supports. Each one costs about 310 bytes.
- 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 estimate is base64 of the compact JSON entry. On my own two routes it overstated the served header by 72 bytes on 31 October; across the 69 offers measured on 18 November the median served header was 120 bytes under its estimate, with a wide spread either way: the listing carries fields the header doesn't (
quality,lastUpdated), and the header carries anerrorstring the listing doesn't. - Serialising the same entries with Python's default
json.dumpsspacing adds about 8% and would push the count to 3,879. "About 2,300" assumes sellers serve compact JSON, which 26 of the 27 measured did. - These are HTTP/1.1 limits. Over HTTP/2 the governing setting is
SETTINGS_MAX_HEADER_LIST_SIZE, which some servers and clients enforce and others ignore. - Client versions are in the table, and a new release can move a limit. That is why the checker's tests run the real aiohttp (both parsers, the header first and last), Node and
http.clientat each boundary. - First published 31 October with that day's listing and a value-only aiohttp rule, the compiled parser's in the usual position. Updated 6 November with the line rule, which the pure-Python parser enforces, a fresh listing and a fresh sample. Checker 0.1.0 had the same value-only rule; 0.2.0 counts the line. Updated 18 November with a fresh listing and sample, which found the first header over Node's limit.
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.