How to charge per API call
To charge per API call you need three things: a way to identify or pay for each call, a counter you trust, and a way to collect the money. The usual options are metered billing with API keys and a monthly invoice, prepaid credits, an API marketplace that bills for you, or x402, where each request carries its own stablecoin payment. On iamai.markets you can list your endpoint as a pay-per-call API from $0.01, and we forward each paid call to you signed.
The four billing models
| Model | How the buyer pays | You build | Fits |
|---|---|---|---|
| Metered billing (for example Stripe usage-based billing) | Card on file, invoiced for usage | Sign-up, API keys, usage reporting | Businesses with steady usage |
| Prepaid credits | Buys a credit pack, calls draw it down | Balance tracking, top-ups | Spiky usage, fewer unpaid invoices |
| API marketplace | Through the marketplace's plans | Listing and docs | Reaching developers who browse marketplaces |
| x402 per request | Stablecoin payment inside each call | A 402 answer and payment checks, or a host that does it | AI agents and one-off callers, cent-sized prices |
Pick a price that survives fees
- Card fees have a fixed part per payment, so a $0.01 card charge loses money. That's why card-based APIs bill monthly or sell credits.
- With x402 each call can be priced at a cent, because the payment is a small on-chain transfer.
- Price above your own cost per call (servers, third-party APIs, model tokens) with room for retries and abuse.
- Charge only for calls that succeed. Buyers, and agents especially, will avoid an API that bills for errors.
Verify forwarded calls on your server
When your listing is a pay-per-call API on iamai.markets, buyers pay us with x402 and we forward the call to your endpoint. Each forwarded call carries X-Iamai-Timestamp, X-Iamai-Call-Id and X-Iamai-Signature (version 2). Check the signature with your signing_secret before doing any work:
import crypto from 'node:crypto';
function isFromIamai(req, rawBody, secret) {
const ts = req.headers['x-iamai-timestamp'];
const id = req.headers['x-iamai-call-id'];
const sig = req.headers['x-iamai-signature'] || '';
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // older than 5 minutes
const pathAndQuery = req.url; // e.g. "/summarize?lang=en"
const msg = `${ts}.${id}.${req.method}.${pathAndQuery}.${rawBody}`; // body is "" for GET
const want = crypto.createHmac('sha256', secret).update(msg).digest('hex');
return sig.length === want.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want));
}
Rules of the forwarded call
- Answer with HTTP 2xx and your result (JSON preferred, up to 1 MB) within 25 seconds. The buyer is charged only if you answer 2xx.
- A call can rarely end unpaid, so don't let one call trigger costly or irreversible actions without your own checks.
- Price per call: $0.01 to $100. You keep 95%; payouts follow the 7-day buyer protection hold.
- If your secret leaks, rotate it; the old one stops working at once.
When not to use per-call pricing
If your customers are companies that want one predictable bill, or calls are long-running jobs, a monthly plan or credits will suit them better. Per-call pricing shines when callers are many, small and anonymous, which is the shape of AI agent traffic.
Questions
Do buyers need an account to pay per call?
Not with x402. They need a wallet with USDC on Base and an x402 v2 client.
What does listing an API cost?
Your first listing is free forever; extra listings are $19 a month each. There's a 5% fee per paid call.
Can one listing sell both a download and API calls?
Yes. By default a pay-per-use listing keeps its normal sale too; you can switch it to API only.
Related
Updated 2026-12-01