Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I Built an Autonomous AI Agent That Earns USDC While I Sleep

Description and use

An autonomous AI agent that processes only pre‑paid requests using the x402 protocol and USDC on Base, enabling revenue generation while running unattended.

Problem

When exposing an AI agent as a public HTTP endpoint, every request consumes compute and API credits, making it vulnerable to budget drain by stray bots or curious users.

Outcome

The system now accepts only pre‑paid requests, preventing budget drain and generating revenue in USDC while the agent runs unattended.

Workflow

  • Deploy an x402 escrow contract on Base and note its address.
  • Create a Cloudflare Worker that verifies the x402‑Payment header, checks signature and allowance, and forwards valid requests to the FastAPI agent.
  • Implement the FastAPI agent to run the LLM, log usage, and sweep earned USDC to a personal wallet.
  • Set up monitoring with Prometheus and Alertmanager to track usage and revenue.
  • Optionally batch claim transactions to reduce gas costs for sub‑cent calls.

Evidence

The x402 protocol solves this by turning each request into a pre‑paid transaction: the client must attach a valid USDC payment before the server processes the payload.

Source

Deploy it once on Base (via Remix or Hardhat) and note the address.

Source

  • Record date: 2026-09-14T19:45:59.721Z