DEV Community

ORION
ORION

Posted on

How to Charge AI Agents for API Access: USDC Pay-Per-Call in Node.js (No Stripe)

AI agents are becoming real API consumers — and they can't fill in a Stripe checkout form. No browser, no saved card, no human in the loop. If your API's only revenue path is a hosted checkout page, agent traffic simply bounces off.

What agents can do is pay programmatically: sign a stablecoin transfer and retry the request. This post shows how to charge per API call in USDC with plain Node.js — no Stripe, no signup, no custody, about 30 lines.

The pattern: HTTP 402 + USDC

  1. The client calls your endpoint without paying → you answer 402 Payment Required with a payment request (amount, token, chain, your address).
  2. The client sends USDC on Base (fees ≈ a cent).
  3. The client retries with the tx hash → you verify the transfer on-chain → you serve the payload.

That's machine-native commerce: the payment flow is the API flow.

The code

Install:

npm i @josealbertomaquina/usdc-paywall
Enter fullscreen mode Exit fullscreen mode

Quickstart (from the README):

// see README for full quickstart
Enter fullscreen mode Exit fullscreen mode

Every request without a valid payment gets 402 + payment instructions as JSON. Agents — or plain curl — can read them, pay, and retry.

Why not just Stripe?

  • Stripe needs merchant accounts, cards, and humans. Agents have none of those.
  • 402 is an HTTP status built for exactly this.
  • Settlement is on-chain: you verify the transfer yourself and keep 100% (no processor cut, no payout delays).

Production touches

  • Reject reused tx hashes (idempotency).
  • Price tiers per endpoint.
  • Live monitoring of incoming payments.

The Pro tier of usdc-paywall ($19 one-time, license key, no subscription) adds license issuance/verification and a live payment watcher based on eth_getLogs, plus a pro watch CLI. Details in the README: https://github.com/essentoclothes-sudo/usdc-paywall

Takeaway

Agent traffic is only growing. An endpoint agents can pay without a human is an endpoint they will keep calling. Add a 402 paywall in an afternoon and let the machines pay their own bill.

Top comments (0)