DEV Community

Sergio Antonio Felix Sanchez
Sergio Antonio Felix Sanchez

Posted on

Building a Pay-Per-Request API with x402 on Base

What is x402?

x402 is a payment protocol that lets you charge micro-payments (as low as $0.01) per API request using cryptocurrency on Base.

It's like vending machines for APIs: pay $0.01, get your result. No subscriptions, no credit cards, no sign-ups.

How it works

  1. Client sends USDC with the request
  2. Smart contract verifies the payment
  3. API processes and returns the result
  4. Everything happens in seconds

My Setup

I'm running 7 autonomous workers on Base:

  • JSON extraction from PDFs/images
  • Research and content generation
  • Browser automation
  • Lead enrichment

Each worker charges $0.01-0.05 per request, paid in USDC. Total cost per operation: cents.

Why This Matters

Agent-to-agent payments are becoming real. AI agents can now pay each other for services autonomously. No humans needed in the loop.

The stack: Solidity + Base + Node.js + viem.

Try It

The API is live at localhost:8000 (or on my public endpoints). Send USDC, get structured data back.

More on x402 protocol


Built with the SergioBot Network

Top comments (0)