Monetizing APIs with x402 and USDC on Base
Learn how x402 protocol enables pay-per-use API monetization using USDC micropayments on Base, eliminating subscriptions and unlocking usage-based pricing.
What Dropped
The x402 protocol launched as an open standard for HTTP 402 Payment Required responses, enabling APIs to request micropayments before serving requests. Combined with USDC on Base, developers can now monetize APIs with sub-cent precision and near-zero fees.
Why It Matters
Traditional API monetization requires upfront subscriptions, credit card processors, and minimum billing amounts. This excludes experimental usage, one-time calls, and international users. With x402 + USDC, you can charge $0.0001 per API call with no middleman, no chargebacks, and instant settlement.
- Eliminate subscription friction - users pay only for what they use
- Accept international payments without currency conversion
- Settle instantly in USDC on Base with <$0.01 gas fees
- Enable AI agents to autonomously pay for API access
What We Built
We created a reference implementation showing a weather API that charges 0.001 USDC per forecast request. The demo includes a Next.js API route with x402 payment verification, a React client that handles 402 responses, and Coinbase Smart Wallet integration for seamless payments.
// API route with x402 payment check
export async function GET(request: Request) {
const payment = await verifyX402Payment(request)
if (!payment.verified) {
return new Response(null, {
status: 402,
headers: {
"X-Accept-Payment": "USDC/Base",
"X-Payment-Amount": "1000", // 0.001 USDC
"X-Payment-Address": MERCHANT_WALLET
}
})
}
return Response.json({ forecast: "Sunny, 72°F" })
}How to Try It
Clone the repo and run it locally with your own Coinbase API keys. The demo works on Base Sepolia testnet - you can get free test USDC from the faucet. The complete implementation is under 200 lines of code.
