DEV Community

Alfred Zhang
Alfred Zhang

Posted on

How to Add Pay-Per-Call Crypto Payments to Any API in 5 Minutes (x402 + Base)

Your API returns 200 OK for free. What if it returned 402 Payment Required and got paid in USDC?

That's exactly what the HTTP 402 spec was designed for — it's just been unused for 30 years. The x402 protocol finally makes it real, on Base.

The Problem

You built a useful API. Maybe it's a data enrichment endpoint, an AI inference wrapper, or a niche scraper. You want to monetize it — but:

  • API keys mean user signup flows
  • Stripe means billing integrations and KYC
  • Rate limiting by IP is trivially bypassed

What if payment was the authentication?

The 3-Line Fix

With the x402 middleware, adding pay-per-call to an Express API takes literally 3 lines:

import { paymentMiddleware } from "x402-express";

app.use(paymentMiddleware(
  "0xYourWalletAddress",
  { "/api/data": { price: "$0.01", network: "base" } }
));
Enter fullscreen mode Exit fullscreen mode

That's it. When an agent or client hits /api/data, they get back:

HTTP 402 Payment Required
X-Payment-Requirements: {"price":"0.01","network":"base","token":"USDC"}
Enter fullscreen mode Exit fullscreen mode

The client pays on-chain, includes the payment proof in the next request header, and gets their 200 OK. No accounts. No billing. No KYC.

How httpay.xyz Does It

httpay.xyz takes this further — it's a hosted gateway that wraps any existing API endpoint with x402 payments.

Instead of deploying middleware yourself, you register an endpoint and httpay issues you a 307 redirect URL:

https://httpay.xyz/r/{your-slug}
  → verifies payment proof
  → forwards to your real API
  → returns response
Enter fullscreen mode Exit fullscreen mode

So your workflow becomes:

  1. POST your endpoint to httpay.xyz
  2. Set a price in USDC (e.g. $0.001 per call)
  3. Share the httpay URL — payment is automatic

No code changes to your existing API. The gateway handles the 402/payment verification layer.

Want to see it live? Try the demo endpoint:

curl https://httpay.xyz/health?demo=true
Enter fullscreen mode Exit fullscreen mode

The MCP Angle (For Claude / Agent Developers)

This gets interesting when your client is an AI agent.

Agents using the Model Context Protocol (MCP) can now autonomously pay for API calls using:

npx @httpay/mcp
Enter fullscreen mode Exit fullscreen mode

Add it to your Claude Desktop config:

{
  "mcpServers": {
    "httpay": {
      "command": "npx",
      "args": ["@httpay/mcp"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Now Claude can discover, call, and pay for httpay-registered APIs autonomously. No human in the loop for payment approval. The agent carries a USDC budget and spends it per-call.

This is what agent-native monetization looks like:

  • No API keys to manage
  • No subscription plans
  • Pay exactly for what you use, per call, on-chain

Try It

The fastest way to see this in action:

# See available endpoints
curl https://httpay.xyz/endpoints?demo=true

# Health check
curl https://httpay.xyz/health
Enter fullscreen mode Exit fullscreen mode

Or open httpay.xyz and register your first paid endpoint in under 5 minutes.

For API sellers: You get a wallet address, set a price, share a URL. Payments settle in USDC on Base — no gas fees for recipients.

For agent developers: Your agent gets a tool that can call any httpay endpoint by paying micro-amounts of USDC. Token budget management built in.


TL;DR

Before After
Free API, no monetization Per-call USDC payments
API keys + auth systems Payment proof = authentication
Stripe integration required On-chain settlement, no KYC
Manual billing Autonomous agent payments

HTTP 402 has been waiting 30 years for the right payment rail. Base + USDC is it.

httpay.xyz — try it with ?demo=true

Top comments (0)