How I Built an Autonomous AI Agent That Earns USDC While I Sleep
Description and use
A stateless Cloudflare Worker service that accepts GPT‑4o queries, requires micro‑payments in USDC via x402, and automatically forwards funds to a Base wallet, generating passive income.
Problem
Create a self‑paying AI service that charges a micro‑payment per call and automatically settles in USDC on Base.
Outcome
A stateless, low‑latency AI endpoint that automatically earns USDC per call, with payments routed directly to a Base wallet and no custodial risk.
Workflow
- 1. Client sends JSON POST to Worker URL with question.
- 2. x402 middleware checks Payment header, verifies signed USDC on Base, returns 402 if invalid.
- 3. If payment valid, Worker instantiates Agent class and calls OpenAI chat completion.
- 4. Agent returns answer, Worker sends JSON response.
- 5. x402 forwards USDC to destination address; Worker never holds funds.
Evidence
The result is a service that charges $0.01–$0.10 per call in USDC on the Base L2, with the earnings accruing to a wallet I control.
The Worker itself never holds funds; the x402 library forwards the USDC directly to the destination address encoded in the payment header.
- Record date: 2026-09-14T05:15:41.172Z