{"slug": "we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h", "title": "We built a free x402 bill-reader — the open internet's headers humbled us in 24h", "summary": "A developer built a free x402 bill-reader at paydlux.com/check that decodes the payment terms servers return in HTTP 402 headers, and within 24 hours a live third-party endpoint exposed three parsing bugs. The parser grabbed the first payment-related header (a version marker) instead of the base64-encoded v2 envelope, and misread atomic USDC units of 3000 as $3,000 rather than $0.003. The team fixed the parser to try every candidate header and added a live assertion against the real endpoint, moving its suite from 18/19 to 19/19.", "body_md": "AI agents are starting to buy things from APIs on their own. The standard they use is x402: the server answers `402 Payment Required` and puts its price in a response header, like a bill slipped under the door. No account, no card — the payment itself is what opens the door.\n\nWe built a free tool so buyers can see that bill before anyone pays: paste an endpoint's address at [paydlux.com/check](https://paydlux.com/check) and we answer in plain words — payee, price, currency, chain. Five checks a day, no signup. (The paid check costs about a cent and adds a receipt on the Stellar ledger, but that part isn't the story today. The story today is that a stranger's server ran circles around our parser in one evening.)\n\nWe pointed our checker at a real, live, third-party x402 endpoint — `https://2s.io/api/weather/current` — the kind of endpoint this whole ecosystem is actually made of. Not our demo. Not a fixture. Somebody else's production server.\n\nOur test suite said:\n\n```\nFAIL  2s.io weather endpoint\n{\"verdict\":\"UNREADABLE\",\"reason\":\"answered 402 with x-payment-requirements,\n but its terms do not fully parse…\"}\n```\n\nThe server had answered correctly. **We** couldn't read the answer. Three bugs, found live, in one evening. If you ship anything that reads x402 headers, all three probably live in your code too.\n\nThe endpoint sent two payment-flavored headers:\n\n```\npayment-required: eyJ4NDAyVmVyc2lvbiI6MiwiYWNjZXB0cyI6Wy...\nx-payment-requirements: x402\n```\n\nOur parser kept the *first* header that looked payment-related. That was `x-payment-requirements` — which is not the bill at all. It's a version marker. A sticky note that says \"x402 here\". The real terms sat in `payment-required`, base64-encoded — v2 ships its JSON envelope as base64, not as raw JSON.\n\nThe fix sounds obvious in hindsight, which is how you know we deserved it: iterate over **all** candidate headers and take the first one that actually *parses*, not the first one that merely exists.\n\n``` js\nfor (const h of PAY_HEADERS) {\n  const terms = tryParse(h)      // raw JSON? base64(JSON)? try both.\n  if (terms) return terms        // the first that PARSES wins\n}\n```\n\nDecoded, the real offer looked like this:\n\n```\n{\n  \"x402Version\": 2,\n  \"accepts\": [{\n    \"scheme\": \"exact\",\n    \"network\": \"eip155:8453\",\n    \"amount\": \"3000\",\n    \"asset\": \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n    \"payTo\": \"0x2b6D49…\"\n  }]\n}\n```\n\nOur v1 parser read `amount: \"3000\"` and would have told the world this endpoint costs **$3,000**.\n\nIt costs **$0.003**. That's USDC on Base, and `3000` is atomic units — six decimal places, like satoshis. (x402 v2 also renamed the list: v1 used `accepted` with `maxAmountRequired` in decimal; v2 uses `accepts` with `amount` in atomic units. Same intent, different wire shape. The open internet does not code-review your assumptions.)\n\nWe now scale USDC explicitly across the chains we know and show unknown token contracts in shortened hex rather than guess. If your chain's stablecoin isn't in our registry yet — PR it, please; the honest failure mode of a registry is an incomplete one.\n\nThis one's meta: the first \"fix\" passed all our *fixture* tests and still failed live, because every fixture was one header with one shape. The lesson we paid for: **at least one test must hit the real internet.** The suite now carries a live assertion against 2s.io itself. It was 18/19 when the assertion caught the mess; it's 19/19 after the fixes — and the failing test is the reason the fixes are real and not vibes.\n\nOur checker answers in four states: `PAYABLE`, `NOT_PAYABLE`, `UNREADABLE`, `UNREACHABLE`. The one that matters is UNREADABLE.\n\nIt's tempting to collapse \"we couldn't parse the bill\" into \"there is no bill\" — fewer states, cleaner API. But a trust product that conflates *silence* with *absence* teaches its users to trust exactly the wrong things: on that 2s.io endpoint, the sloppy answer would have been \"nothing to pay here\" — about a site that is quite literally charging right now. We'd rather print the embarrassing state and mean it.\n\n`2s.io/api/weather/current`\n`stellar/endpoint-probe.ts`, and the live assertion is in `endpoint-probe-check.ts` — if a real endpoint near you makes it say UNREADABLE, that's a bug report and a fix waiting to happen.\nThe open internet's headers are messier than any spec demo. Ours are messier than ours were yesterday, and our tests are stronger for it.", "url": "https://wpnews.pro/news/we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h", "canonical_source": "https://dev.to/paydlux/we-built-a-free-x402-bill-reader-the-open-internets-headers-humbled-us-in-24h-1394", "published_at": "2026-12-05 20:30:30+00:00", "updated_at": "2026-12-05 20:44:45.236929+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["paydlux.com", "x402", "2s.io", "Stellar", "Base", "USDC"], "also_reported_by": [], "takeaway": "When parsing x402 headers, iterate over all payment-related headers and accept the first that actually parses (raw JSON or base64), and scale USDC amounts from atomic units at six decimals so 3000 reads as $0.003, not $3,000.", "recommendation": {"advice": "Parse every candidate x402 header and take the first that decodes, scale stablecoin amounts from atomic units, and keep at least one test asserting against a live third-party endpoint.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h", "markdown": "https://wpnews.pro/news/we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h.md", "text": "https://wpnews.pro/news/we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h.txt", "jsonld": "https://wpnews.pro/news/we-built-a-free-x402-bill-reader-the-open-internet-s-headers-humbled-us-in-24h.jsonld"}}