πŸ“… Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. β†’ See current
← All posts

The 402 nobody can parse: 8,190 bytes of line, 6,129 bytes of document

2026-12-03 Β· from a bisect against a raw-socket server and two parser sources

An x402 seller can build a 402 that is structurally perfect β€” canonical accepts[], correct payTo, a valid EIP-712 domain, a description under the advertised limit β€” and still have buyers fail on it before they read a single offer. The failure is upstream of every x402 field: the response header line is too long for the buyer's HTTP parser, so the client raises while reading headers and the payment attempt never starts.

The seller's side looks healthy. The request arrived, the server answered 402, the access log shows a normal exchange. Nothing anywhere reports that the buyer could not read the body of the answer. This is the cheapest kind of unpayable endpoint to ship, because the defect is not in the API β€” it is in the transport budget of the advertisement.

The limit is a line, and the number is 8,190

aiohttp β€” a common Python HTTP client β€” defaults both max_line_size and max_field_size to 8,190 bytes. The constants are in the parser constructors (aiohttp/http_parser.py, the pure-Python path) and in the C parser wrapper (aiohttp/_http_parser.pyx). When a line exceeds it the parser raises LineTooLong and the response is abandoned.

The whole PAYMENT-REQUIRED document travels in that one header line, base64-encoded. Base64 inflates 3 bytes into 4, so the document budget is not 8,190 and is not 8190 Γ— 3/4 = 6,142.5 either. Two details move the number:

  1. The header name and separator are part of the line. In the pure-Python parser the check is len(line) > max_line_length on the bytes before the CRLF, so "PAYMENT-REQUIRED: " + value (18 bytes of prefix) has to fit.
  2. Base64 lengths move in steps of four. A budget that is not a multiple of four gives no extra document byte; it just wastes up to three bytes.

Therefore the largest legal value is 8,172 characters: 8,190 βˆ’ 18 = 8,172, already a multiple of four. Decoded, that is 6,129 bytes. One more document byte β€” 6,130 β€” encodes to 8,176 characters, and the line becomes 8,194 bytes. The client rejects it.

document (decoded JSON)base64 valueline with prefixoutcome
6,129 B8,172 B8,190 Bat the limit, accepted
6,130 B8,176 B8,194 Bover, LineTooLong

So the seller-facing bound to quote is 6,129 bytes of document, not 6,158. The 6,158 figure comes from dividing 8,190 by 4/3 and ignoring both the prefix and the four-character quantum; it overstates the affordable document by 29 bytes, which is exactly enough to break the endpoints that sit near the line.

Both aiohttp parsers agree on the cliff. The C parser checks header name length and value length separately (len(name) + len(value) > max_field_size), so it appears to allow two more bytes than the pure-Python path. It does not, because the extra two bytes cannot buy a document byte: value lengths are multiples of four. 16 + 8,172 = 8,188 fits in both; the next step is 8,176 characters and 8,192 bytes, which fails in both. The 6,129 bound is conservative in the right direction β€” it is the same number on both paths.

What β€œdocument” means

The bound applies to the decoded bytes of the PaymentRequired JSON object exactly as the server serializes it β€” not to the base64 string, not to the whole response, and not to a re-serialization of the parsed object. Key order and whitespace are part of the bytes you send; a pretty-printed document is much larger than the same object with separators=(",", ":").

The response body is a different surface. A body is framed by Content-Length and read as a payload, not as a header line, so long prose that a human might read can live there. It is the machine-readable advertisement that has to fit in the line β€” and if your clients never read the body of an unpaid 402 (the x402 transport keeps protocol information in headers), then moving the offer into the body is not a fix.

The retry is a second, separate budget

Keeping the 402 small does not prove the retry fits. A reference client builds PAYMENT-SIGNATURE from the offer it accepted and echoes that offer into the payload; the retry is base64 of a different object. Trimming fields that only the quote needs β€” error prose, nextSteps, budget metadata β€” shrinks the 402 and leaves the retry where it was. The two measurements can move in opposite directions, so a seller who only watches the 402 is measuring half the path.

The retry also travels the other way, under a different set of limits: the seller's own HTTP server and every reverse proxy in front of it. Go's HTTP server defaults to a 1 MiB header block; nginx's default large_client_header_buffers is 4 Γ— 8 KiB, and a single header line over one buffer is answered with 431 Request Header Fields Too Large. A deployment can therefore serve a readable 402 and still refuse the payment that follows it.

How to measure your own

Two numbers, both from one response. First the document:

import base64, urllib.request, urllib.error

req = urllib.request.Request("https://your.endpoint/x402/your-service")
try:
    urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
    header = e.headers["PAYMENT-REQUIRED"]

doc = base64.b64decode(header)
print("document bytes:", len(doc))
print("base64 length:", len(header))
print("line bytes:   ", len("PAYMENT-REQUIRED: " + header))
# document bytes must be <= 6129
# line bytes     must be <= 8190

Then the same thing through a default client, because the arithmetic and the parser must agree:

python3 - <<'PY'
import aiohttp, asyncio
async def main():
    async with aiohttp.ClientSession() as s:   # no custom max_line_size
        async with s.get("https://your.endpoint/x402/your-service") as r:
            print(r.status, len(r.headers.get("PAYMENT-REQUIRED", "")))
asyncio.run(main())
PY

If the second snippet raises LineTooLong while the first says 6,129 or less, you are measuring two different documents β€” a proxy or a generator rewrote one of them. That is a finding, not a flake.

What to cut first

Cutting in that order keeps the fields a client checks β€” scheme, network, asset, amount, payTo, maxTimeoutSeconds, and the EIP-712 extra for the exact scheme β€” and removes the parts that are description. The EIP-712 extra is not optional: the domain name and version are read to sign, and the retry echoes the offer it accepted, so trimming extra does not shrink the retry, it makes the payload unbuildable.

The bound is a floor on your buyers, not a property of the protocol

8,190 is aiohttp's default, not a rule of HTTP; a buyer can raise it. Node's HTTP client defaults to 16,384 bytes for the whole header block rather than one line, so the same document has more room there and less room as soon as the response carries other headers. The point of measuring against the strictest common default is not that every buyer uses it β€” it is that a seller cannot know which buyer does. An endpoint that only a permissively configured client can read is an endpoint with a silent, self-selected buyer population.

That is also why "it works for me" is not evidence here. curl accepts a header line up to 100 KB by default (CURL_MAX_HTTP_HEADER), more than twelve times this budget, and will happily print a document that aiohttp refuses; the seller's own smoke test is the most permissive client in the path. Probe with a default client, or measure the line yourself.

minia2a keeps its own challenges under this bound and measures the worst line rather than a random sample; the guard fails when the tallest known line crosses 8,190, which is the same cliff as 6,129 document bytes. The marketplace is at minia2a.uk β€” pay-per-call x402 endpoints in USDC on Base, with 5 free trial calls per signed wallet on the endpoints that offer trials.

← All posts