DEV Community

Owen King
Owen King

Posted on

An AI agent paid me $9 with no human involved - here's the full architecture

Last week my API got its first payment from a customer who has never filled in a form, cannot click a checkout button, and does not own a credit card. It was an AI agent. It sent 9 USDC on Base, claimed its upgrade through an API endpoint, and started working. No human touched anything.

I run RagScrape — a URL-to-Markdown API for RAG pipelines (free tier: 50 URLs/month, no signup). Like every SaaS, my upgrade path assumed a human: quota exceeded, please visit the pricing page. For agents that is a dead end. They cannot pay with cards, and most API owners respond by hard-blocking them. I went the other way and made agents a first-class customer.

The design has four parts.

1. A quota wall that sells

When an agent exhausts its free quota, it does not get an HTML pricing page. It gets a machine-readable 402 response with an upgrade object:

{
  "upgrade": {
    "checkout": "POST /create-checkout (a human completes payment)",
    "crypto": "Send 9+ USDC on Base to 0x... then POST /crypto/claim {txHash} - instant, no human"
  }
}
Enter fullscreen mode Exit fullscreen mode

Agents read llms.txt and OpenAPI documents the way humans read homepages, so the same instructions live in both. Your 402 response is your storefront for machines.

2. Crypto where agents actually live

Humans pay with cards. Agents pay with wallets. USDC on Base means roughly one-cent fees, dollar-stable value, and settlement in seconds. There is no payment processor to onboard with, no subscription engine to build - the payment itself is the invoice, and renewal is just another payment plus claim.

3. Trust nothing, verify on-chain

The agent claims its payment by posting a transaction hash. My server then pulls the transaction receipt from Base's public RPC endpoint and checks four things: the USDC contract emitted a Transfer event, the recipient is my address, the amount covers the price, and the transaction succeeded. There is no webhook to secure because the blockchain is the webhook.

4. Idempotency and expiry

Every transaction hash can be claimed exactly once - a registry in Workers KV makes double-claiming impossible. Credits last 31 days, and a daily cron downgrades lapsed keys back to the free tier. Nobody accumulates ghost subscriptions.

The part that surprised me: the whole thing was about 200 lines of code. The hard part was not payments. It was writing documentation a machine can act on - llms.txt, an OpenAPI spec with real examples, and error messages that say what to do next instead of "unauthorized".

If you are building APIs in the agent era, assume your next customer is software. Give it a wall it can read, a rail it can use, and a receipt it can prove.

Free tier (50 URLs/mo, no card): https://rag-scrape-api.owerryking.workers.dev - and yes, agents can pay it in USDC.

Top comments (0)