x402 402 header too large: which clients fail, and how to fit PAYMENT-REQUIRED
Updated 2026-10-15
An x402 v2 seller puts its payment requirements, base64-encoded, in the PAYMENT-REQUIRED header of every 402 (many, us included, repeat them as the JSON body). Nothing in the protocol bounds that header. Once it passes a client's header limit, the client fails before it sees the 402. The buyer gets a parser error instead of a price, and nothing on the seller's side shows it.
We have this on our own API: on 15 Oct, 262 of our 272 paid routes sent a header value too long for Python's aiohttp (measured on tanod.dev). Our fix is merged and goes live with our next release. Below are the client limits, measured here, how to check your own 402, and the order in which we trimmed ours.
1. Which clients fail, and where
Tested on 15 Oct 2026 against a local server that answers 402 with a PAYMENT-REQUIRED header of a chosen size:
client fails when error
aiohttp 3.14.5 header value over 8,190 bytes ClientResponseError: 400, message="Got more than 8190 bytes when reading"
Node 24.21 fetch all response headers over 16 KB together TypeError: fetch failed, cause.code UND_ERR_HEADERS_OVERFLOW
requests 2.34.2 one header line over 65,536 bytes LineTooLong
urllib (Python 3.11) one header line over 65,536 bytes LineTooLong
httpx 0.28.1 read a 70,000-byte header without erroraiohttp's default C parser counts the header value; its pure-Python parser counts the whole line, so keep the line (PAYMENT-REQUIRED: plus the value) under 8,190 bytes to be safe with both. Node's limit is for the whole header block, so other headers and a proxy's count against it too.
Fixes by error message: aiohttp: Got more than 8190 bytes when reading, and, when nginx sits in front of your API, nginx: upstream sent too big header.
2. How common it is
An open issue on the x402 repository, x402-foundation/x402#3803 (opened 14 Oct 2026), surveyed the public CDP Bazaar: of 2,127 origins that answered with a 402, 156 sent a PAYMENT-REQUIRED header over 8,190 bytes and 4 sent more than 16 KB of headers. The issue proposes a documented budget of 8 KB, a server warning above it, and a clearer client error.
3. Measure your 402
curl -s -o /dev/null -D - -X POST https://your.api/v1/route \
-H 'content-type: application/json' -d '{}' \
| tr -d '\r' | awk 'tolower($1)=="payment-required:" {print length($0)}'Over 8,190 means aiohttp buyers can't read it. Run it on your largest routes: the ones with big input or output examples and the most payment networks. To see what fills it, decode the value (base64 -d) and measure the parts.
4. What fills the header
For one of our routes, /v1/pdf/ocr, an outside checker's breakdown of the decoded header (JSON characters; base64 adds about a third) was: Bazaar schema 2,894, accepts 2,355 (one entry per network), Bazaar output example 475, resource 449. The rest was the error text and the other extensions.
Some of it a buyer needs to pay and call the route: every accepts entry, the input example and schema, and resource, which the Bazaar facilitator catalogs from the payment payload. Some of it a buyer never reads from the header: prose for people and the output example, both of which the body still carries.
5. What we trimmed, cheapest first
Only in the header copy, and only when it is over budget. The JSON body, the OpenAPI spec and the MCP 402 keep everything.
1. error text the unpaid error (about 390 characters of price notes) becomes
"Payment required; details in the 402 JSON body."
A failed payment's reason (insufficient_funds, ...) stays.
2. annotations description, title and examples removed from extension schemas
(they don't change what validates); "$schema" dropped outside
the Bazaar extension. Bazaar's input schema is left whole.
3. output example Bazaar output example cut in stages (3,072, 2,048, 1,024, 512
bytes of JSON), output schema reduced to top-level types.
never accepts entries, input example and schema, resource.Released on 15 Oct 2026: on the live API, 23 of 272 paid routes are still over 8,190 bytes (median 7,670, max 9,966), down from 262 before the release; a local run had predicted 24. The 23 left are input-bound: their input example and schema, seven payment entries and resource alone are over the budget. For those the only full fix is a header that points at the body, and that needs buyers whose clients read the body of a 402.
6. If you are the buyer
Raise the limits in your client. Both of these read a 40,000-byte header in the test above:
session = aiohttp.ClientSession(max_line_size=65536, max_field_size=65536)node --max-http-header-size=65536 your-agent.mjsOr read the requirements from the JSON body, when the seller sends them there too.
Questions
Is the header limit 8 KB or 16 KB?
It depends on the buyer's client. In our test aiohttp refused a header value over 8,190 bytes, Node 24 fetch refused more than 16 KB of headers in total, Python requests and urllib refused one header line over 65,536 bytes, and httpx read a 70,000-byte header. Keep PAYMENT-REQUIRED under 8,190 bytes and every client in the table reads it.
Doesn't Node cap headers at 8 KB?
Not by default any more: Node 24's default is 16 KB (--max-http-header-size, http.maxHeaderSize 16384); 8 KB was the default in older releases. Node 24.21 read a 9,000-byte header and refused a 17,000-byte one in our test. The 16 KB covers all response headers together, so other headers and any proxy count against it.
My 402 comes from AWS WAF or Cloudflare, not my code. Does this apply?
Yes. AWS WAF's Monetize action (June 2026) and Cloudflare's Monetization Gateway (InfoQ, July 2026) answer the bots you charge with an x402 402 at the edge. You did not write that header, but the buyer's client applies the same limits, and the CDN adds response headers of its own that count toward Node's 16 KB total. Measure the 402 a charged bot actually receives: the PAYMENT-REQUIRED line with the command in section 3, and the whole header block with curl -s -o /dev/null -D -.
Can chunked transfer encoding carry a large 402 challenge?
No. Chunked encoding splits the body; headers arrive whole before it, so the client's header limits apply either way. Send the same payment requirements in the JSON body too, so a buyer that cannot read the header can still read the price.
Caveats
Limits change between versions; the table lists the versions tested. The survey numbers are the issue author's, not ours. Results from our endpoints are automated and heuristic.
Related guides: aiohttp: Got more than 8190 bytes when reading, nginx: upstream sent too big header, Pay-per-call APIs for AI agents with x402, How to get your x402 API listed in the directories agents search, How AI agents find x402 APIs. Results are automated and heuristic.