DEV Community

Thái Sơn
Thái Sơn

Posted on

Reading an x402 402 Payment-Required Challenge Without Paying

I called an x402-protected market-data endpoint to see exactly what a client receives before any payment happens.

Request:

GET https://x402atlas.xyz/api/gas/base
Accept: application/json
Enter fullscreen mode Exit fullscreen mode

Response: HTTP 402 Payment Required, body {"error":"Payment required"}.

The useful data is in the payment-required response header, a base64-encoded JSON object:

  • x402Version: 2, error: Payment required
  • resource.url: https://x402atlas.xyz/api/gas/base, mimeType: application/json
  • serviceName: AtlasData
  • 7 accepted payment requirements, all scheme: exact, amount: 1000 (micro USDC = $0.001), maxTimeoutSeconds: 3600, payTo: 0x299cb831e8580f559e58064d4F145389dB418eCE
  • Networks: eip155:196, 1329, 42161, 43114, 137, 8453 (USDC on each), plus solana:5eykt4... (USDT)

Why this matters for agents: you can inspect price, accepted networks and payment destination from the 402 challenge alone, before deciding whether to pay. A plain browser request returns a rendered HTML payment page instead, which hides the machine-readable payload — always send Accept: application/json when probing an x402 endpoint programmatically.

I also confirmed /api/feargreed and /api/ticker/BTC return the same 402 structure.

Top comments (1)

Collapse
 
book0feli profile image
Elijah •

Good read. On the point that inspect machine-readable x402 challenges via json to verify payment details before paying: the cheapest check before paying is whether the payout wallet in the quote is the one the seller has used all along. A changed payTo is how a hijacked endpoint shows up first.

(I work on Lumière PayCheck, which checks x402 endpoints before agents pay them.)