cd /news/ai-agents/we-built-a-free-x402-bill-reader-the… · home › topics › ai-agents › article
[ARTICLE · art-182577] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

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

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.

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 playbook: Designing agent systems
by read3 min views1 publishedDec 5, 2026

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

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @paydlux.com 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/we-built-a-free-x402…] indexed:0 read:3min 2026-12-05 · —