DEV Community

Mike Dorian
Mike Dorian

Posted on

I monetized my API in 30 minutes with x402, no accounts, no API keys, USDC straight to my wallet8FWcu69WE6wYKKyLyHB4LZHgi8u

I monetized my API in 30 minutes with x402, no accounts, no API keys, USDC straight to my wallet

TL;DR: x402 turns any HTTP endpoint into a pay-per-call product: your server answers 402 Payment Required, the client pays USDC on-chain (Base or Solana), replays the request, and you serve the data. No accounts, no API keys, no Stripe, no KYC. Settlement lands directly in your wallet. I built a working paid AI API + paid download shop on Cloudflare in an afternoon. Here's the pattern, the gotchas, and a live endpoint you can test right now.

The problem
You built an API maybe an AI endpoint, a data feed, an MCP server. Agents (and humans) hammer it. You want to charge, but every option stings:
• Subscriptions need account systems, user management, billing cycles
• API keys need a dashboard, quotas, abuse handling
• Stripe doesn't love crypto-native builders, and withdrawals are a whole tax event
• Every integration adds surface area you have to maintain

There had to be a simpler way: charge per request, settle on-chain, zero infrastructure.

The x402 pattern (5 minutes to understand)

  1. Client GETs/POSTs your paid endpoint your server repliHTTP 4022 ** withPAYMENT-REQUIREDED` header (base64 JSON: amount, token, destination, network)
  2. Client pays on-chain USDC on Base or Solana, ~$0.0001 in fees, confirms in seconds
  3. Client replays the original request with an x402-receipt header carrying the chain + tx hash
  4. Your server verifies the receipt on-chain, checks replay, serves the response

That's it. Payment and product are one round-trip. No accounts, no keys, no monthly bill.

What I built (live, test it now)
A pay-per-call AI API + digital shop on Cloudflare Workers:

https://6766587364.lol/api/ai/sentiment AI sentiment analysis, 0.005 USDC/call. Send any text, get positive/negative/neutral + confidence.
https://6766587364.lol/api/ai/classify text classification, 0.005 USDC/call
https://6766587364.lol/api/ai/image AI image generation (Flux on Workers AI), 0.01 USDC/image
https://6766587364.lol/api/shop/catalog paid digital downloads (source-code kits, playbooks) from 0.01 USDC
• Free to probe: hit any endpoint with no receipt and you get a clean 402 with the exact price + pay-to addresses. No signup.

Try it:
bash
curl -X POST https://6766587364.lol/api/ai/sentiment \
-H "Content-Type: application/json" \
-d '{"text":"I love this"}'

HTTP 402: payment_required, price 0.005 USDC, pay_to Base + Solana

The full OpenAPI spec (with payment info on every endpoint) is at https://6766587364.lol/openapi.json AI agents can read the price, pay, and use the API entirely on their own..**

How it's built (the stack)

  • Cloudflare Workers as the server (free tier: 100k requests/day)
  • Workers AI for inference (free: 10k neurons/day)
  • KV for replay protection (a tx hash can only be redeemed once); R2 for file storage (digital downloads)
  • x402 for the payment protocol receipts verified directly against Baseth_getTransactionReceiptpt) and SolangetParsedTransactionon)
  • Dual-chain settlement: revenue lands in two static USDC wallets no hot wallet, no withdrawal step

Total infrastructure cost: $0. Every paid call is ~100% margin within the free tier.

Gotchas I hit (save you hours)

  1. Flux returns JPEG, not PNG. Check magic bytes (FF D8 FF) before setting Content-Type I shipped a broken image endpoint because I assumed PNG.
  2. Receipt chains contain colons. eip155:8453:0xabc @ split on*last*last* colon, not the first.
  3. Replay protection is non-negotiable. Without a seen-hash cache, anyone can re-sell your endpoint. One KV read per request, trivial cost, mandatory.
  4. Cache-bust when testing. Cloudflare's CDN caches GET responses ~10-15s after deploy; use a unique query param while iterating.
  5. Discovery is half the product. An API nobody's agent can find earns nothing. Ship /openapi.json with x-payment-info, /llms.txt, and link headers (ai-manifest, service-desc, describedby) so agents find you, read your price, and pay.

Numbers

  • 0.005 USDC sentiment calls, 0.01 USDC images verified round-trips on Base mainnet
  • Settlement verified on-chain: revenue appears directly in the destination wallet, no intermediary
  • ~$2.38 already earned from real paid calls during testing

Want one?

That's the whole point. If your API or data deserves to be paid for, this is the cheapest way to start. I build these for clients reference implementation exists, fast turnaround, fixed price. The starter kit (a minimal pay-per-call API you can run in minutes) is available as a paid download from the shop above or DM me.


Top comments (0)