Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

My x402 API couldn't collect a cent for a month — because of a version mismatch nobody documents

My x402 API couldn't collect a cent for a month — because of a version mismatch nobody documents I run an autonomous agent that sells paid API endpoints over x402 — the protocol where callers attach a gasless USDC signa

My x402 API couldn't collect a cent for a month — because of a version mismatch nobody documents

I run an autonomous agent that sells paid API endpoints over x402 — the protocol where callers attach a gasless USDC signature (EIP-3009 transferWithAuthorization) and a facilitator settles it on-chain on Base. The endpoints returned 402 Payment Required correctly, buyers' clients parsed the terms, everything looked healthy.

Zero revenue. For a month.

The root cause is a versioning split that I haven't seen written down anywhere: the ecosystem currently speaks two different dialects of x402, and the two parties you must satisfy speak different ones.

The two dialects

v1 — what the PayAI facilitator (facilitator.payai.network, the free mainnet option) validates on /verify and /settle:

{
  "scheme": "exact",
  "network": "base",
  "maxAmountRequired": "8000",
  "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "payTo": "0xYourWallet",
  "resource": "/jobs/token-verdict",
  "maxTimeoutSeconds": 300,
  "extra": { "name": "USD Coin", "version": "2" }
}

Note: network: "base" — the plain name — and maxAmountRequired.

v2 — what x402scan / Bazaar crawlers (the discovery layer buyers actually use) read from your PAYMENT-REQUIRED header:

{
  "x402Version": 2,
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:8453",
    "amount": "8000",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo": "0xYourWallet",
    ...
  }]
}

Note: network: "eip155:8453" (CAIP-2) and amount.

The failure mode

  • Emit v2 only → PayAI answers invalid_payload on every single verify. Your endpoint looks correct, buyers sign correctly, nothing ever settles.
  • Emit v1 only → settlement works, but discovery crawlers can't parse your origin — you're invisible in the catalog.

I was emitting v2. Every /verify bounced. The error message didn't say "wrong version" — it just said the payload was invalid, which sends you debugging signatures, nonces, and EIP-712 domains that were all perfectly fine.

The fix: bilingual 402

Emit both dialects on every unpaid request:

res.setHeader('PAYMENT-REQUIRED',
  Buffer.from(JSON.stringify(requirementsV2)).toString('base64'));
res.status(402).json({ x402Version: 1, accepts: [requirementsV1] });

Crawlers read the header. PayAI clients read the body. Both worlds work.

Verify ≠ Settle (the second trap)

/verify checks the signature and balance — funds do not move. If you only verify and then run your handler, your earnedUsd counter goes up while your wallet stays flat. You must call /settle to actually submit the authorization on-chain.

Our flow now: verify → settle → run handler → if handler fails, refund the payer (the payer address is inside the signed payload at payload.authorization.from).

After fixing both issues we ran a real $0.008 payment end-to-end: settled on Base, verified on the block explorer, and the auto-refund on a deliberately failed job worked too.

Get discovered

Once payable, register your origin on x402scan so buyers can find you. It's a SIWE-style flow: POST /api/x402/registry/register-origin → you get a 402 back with a sign-in-with-x info blob → sign the message (EIP-191, chainId 8453) → re-POST with a SIGN-IN-WITH-X base64 header. One script, ~60 lines.

I packaged the whole thing — middleware (framework-agnostic + Express signature, bilingual 402, replay-nonce guard, refund hook), the buyer-side EIP-3009 signer, a runnable demo server, and the x402scan registration script — into a starter kit so the next person doesn't lose the month I did:

👉 x402 Paywall Kit on Gumroad — $49

If you're building paid APIs for agents (or agents that pay APIs), happy to answer questions in the comments. The protocol is genuinely good once you're through the dialect wall.

Related tools from our autonomous-revenue lab: CyberSec LLM Assistant ($39), GitHub Bounty Hunter Intel ($19), n8n Bounty Radar ($29).

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.