DEV Community

ORION
ORION

Posted on

How to Monetize an API Without a Billing Platform: Pay-Per-Call in ~30 Lines

If you search "how to monetize an API", most results assume you need a billing platform: Stripe subscriptions, usage tiers, webhooks, dashboards. That's fine at scale. But for a small API — a scraper, a converter, an AI wrapper — the fastest path to first revenue is pay-per-call, and it needs far less machinery than you think.

This post is a decision framework plus a ~30-line implementation using usdc-paywall (MIT core, optional Pro license), a Node.js package that turns any Express route into a paid endpoint with USDC on Base.

When pay-per-call beats subscriptions

Charge per call when:

  • Your API is occasional-use. A user needs it 20 times a month. A $19/mo plan is a hard no; $0.05/call is an easy yes.
  • Your buyers are builders, not companies. Developers will send crypto from a wallet long before they'll open a Stripe account for you.
  • You want zero billing ops. No invoices, no dunning, no chargebacks, no KYC. Payments settle on-chain directly to your wallet.

Charge subscriptions when usage is daily and buyers expect SLAs. Most small APIs are in the first bucket.

The pattern: HTTP 402

The web has a built-in status code for this: 402 Payment Required. The flow:

  1. Client calls /api/convert without paying.
  2. Server answers 402 with a JSON body: price, your USDC address, and the tx hash it wants paid.
  3. Client pays on Base (a few cents in fees) and retries with the tx hash in a header.
  4. Server verifies the transfer on-chain (amount, recipient, not reused) and serves the response.

The verification is the only tricky part — that's what the library does:

import { paywall } from "usdc-paywall";

app.use("/api/convert", paywall({
  wallet: process.env.MY_WALLET,   // your EVM address
  priceUSDC: 0.05,                  // per call
  network: "base",
}));

app.get("/api/convert", (req, res) => {
  res.json(convert(req.query.input)); // only reached after payment
});
Enter fullscreen mode Exit fullscreen mode

Call it without paying and you get a clean 402 with payment instructions — machine-readable, so another agent or script can pay you autonomously. That's increasingly relevant: as AI agents start calling APIs on their own, endpoints they can pay on their own are the ones they'll use.

Economics check

  • USDC on Base: transfer fee ≈ $0.01–0.05.
  • No platform cut: 100% of the price reaches your wallet.
  • At $0.05/call, 1,000 paid calls/month = $50 with no infrastructure beyond your server.

Compare that to wiring Stripe metering for the same volume and deciding whether the complexity ever pays back.

What "done" looks like

A weekend project:

  1. Wrap one route with the middleware above.
  2. Point wallet at a fresh EVM address you control.
  3. Test with a $0.05 payment from a second wallet (or MetaMask).
  4. Your API now has a business model.

The README covers webhook-free verification details, replay protection, and a Pro tier (watch mode + signed licenses) if you want license keys instead of per-call pricing.

Monetizing a small API is not a billing-platform problem. It's a middleware problem — and you can ship it in an afternoon.

Top comments (0)