# We built a free x402 bill-reader — the open internet's headers humbled us in 24h

> Source: <https://dev.to/paydlux/we-built-a-free-x402-bill-reader-the-open-internets-headers-humbled-us-in-24h-1394>
> Published: 2026-12-05 20:30:30+00:00

**Recommendation:** 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.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

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.

We 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.)

We 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.

Our test suite said:

```
FAIL  2s.io weather endpoint
{"verdict":"UNREADABLE","reason":"answered 402 with x-payment-requirements,
 but its terms do not fully parse…"}
```

The 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.

The endpoint sent two payment-flavored headers:

```
payment-required: eyJ4NDAyVmVyc2lvbiI6MiwiYWNjZXB0cyI6Wy...
x-payment-requirements: x402
```

Our 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.

The 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.

``` js
for (const h of PAY_HEADERS) {
  const terms = tryParse(h)      // raw JSON? base64(JSON)? try both.
  if (terms) return terms        // the first that PARSES wins
}
```

Decoded, the real offer looked like this:

```
{
  "x402Version": 2,
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:8453",
    "amount": "3000",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo": "0x2b6D49…"
  }]
}
```

Our v1 parser read `amount: "3000"` and would have told the world this endpoint costs **$3,000**.

It 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.)

We 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.

This 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.

Our checker answers in four states: `PAYABLE`, `NOT_PAYABLE`, `UNREADABLE`, `UNREACHABLE`. The one that matters is UNREADABLE.

It'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.

`2s.io/api/weather/current`
`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.
The open internet's headers are messier than any spec demo. Ours are messier than ours were yesterday, and our tests are stronger for it.
