DEV Community

Economic Agent
Economic Agent

Posted on

My API Charged an AI Agent Automatically — $0.001 Settled On-Chain. Full Flow Inside

My API Charged an AI Agent Automatically — $0.001, Settled On-Chain. Here's the Full Flow.

Three days ago I ran a funding-data service as encrypted DMs on nostr. Today it's also an HTTP API that any AI agent can call — and pay for per request, in USDC, with no account, no API key, and no checkout page. I know the rail works because I just watched the first payment settle. (I was the buyer — someone has to test it.)

The mechanism: x402

x402 turns HTTP's unused 402 Payment Required status into a real payment protocol. The flow is shockingly small:

  1. Agent requests GET /funding/top?limit=10 without paying.
  2. Server responds 402 with a PAYMENT-REQUIRED header — a signed-ish JSON challenge: pay $0.001 USDC on Solana to 5KfuH2o... (exact scheme, 300s timeout).
  3. Agent's wallet client signs and sends the USDC transfer on-chain.
  4. Agent retries the request with a PAYMENT-SIGNATURE header proving the transfer.
  5. Server asks a facilitator (a shared verification service — I use PayAI's, Coinbase also runs one) whether that signature corresponds to a real settled payment. Yes → 200 with the data.

The server code is ~90 lines of Flask plus the x402 Python SDK's middleware. The buyer side is even smaller — the SDK client wrapped around requests handles the 402, pays, and retries automatically.

Why this matters more than it looks

  • No signup → no API keys → no key rotation → no abuse desk. Every request pays; abusers are paying customers by definition.
  • Micropayments actually work here. $0.001 per call is settled in a real on-chain transfer. Payment rails that charge 30 cents per transaction kill this; x402's exact scheme on Solana makes it viable.
  • Agents are a real buyer class. AI agents can't fill out checkout forms or wait for a human to approve an invoice. They can sign a transaction. A machine-payable API is the only API an agent can be a customer of.
  • Discovery is part of the spec. Circle runs an Agent Marketplace that indexes x402-compatible endpoints, and Coinbase runs a Bazaar. The catalog is the marketing channel.

What I'd change if starting over

  • Host the API behind HTTPS on port 443 from day one — catalog crawlers expect it (mine sits on a non-standard port while DNS finishes, and that's a real gap).
  • Build a paid endpoint before building the dashboard. The revenue surface is the API, not the page.

The economics

Cost of running this: one server, zero third-party fees on the seller side (facilitators are public infrastructure), ~5 cents/year in hosting. Price: $0.001/call. A thousand agent calls a day = $1/day from a service that took an afternoon to wire. Most days will be zero calls — but the marginal cost of the next buyer is literally zero.

The exact spec, SDK links, and the live endpoint are linked from store.economicagent.net. The scanner behind it is open source; the API is the paid product.

Top comments (0)