DEV Community

umit kuru
umit kuru

Posted on

I built an AI agent that owns a crypto wallet and sells its own API access via x402

I've been building an experiment: an autonomous AI agent that owns its own crypto wallet, sells a paid API, and uses Claude to make its own pricing decisions based on real earnings and costs. It's live on Base mainnet right now, so I wanted to write up how it actually works.

What it does

The agent runs a single paid endpoint -- a text summarizer -- gated behind the x402 protocol (Coinbase's revival of the old, unused HTTP 402 "Payment Required" status code for stablecoin micropayments). No API keys, no signup, no subscription:

POST /api/summarize
{"text": "..."}

An unpaid request gets back a 402 with the price ($0.02) and payment details. An x402-aware client attaches a USDC payment on Base and retries automatically. Once the payment settles, the agent runs the text through Claude and returns:

{"summary": "...", "key_points": ["...", "..."]}

The wallet and the safety rail

The agent's wallet is managed through Coinbase's Developer Platform (CDP) -- the actual private key never touches my code, only an API-scoped credential. More importantly: every code path that could move funds out of the wallet has to go through one function with a hard, tested spend cap. Nothing in the current build actually spends from the wallet at all (it's receive-only for now), but the cap exists so that if I ever add a feature where the agent spends money on its own, there's a hard ceiling on how much it can ever move, enforced in code, not just policy.

The pricing "brain"

Every 30 minutes, a separate loop asks Claude: given the current earnings, costs, and wallet balance, should the price go up, down, stay the same, or should the service pause itself? This is the part I find most interesting -- it's a real (if simple) example of an agent making an economic decision about its own survival, not just executing a fixed script.

What I learned building it

  • Real infrastructure has real edge cases. The mainnet payment facilitator needed different authentication than the free testnet one -- something you only discover by actually deploying to mainnet, not by reading docs.
  • Models change under you. Claude Sonnet 5 started running "adaptive thinking" by default recently, which silently changed the shape of API responses my code assumed were fixed -- a good reminder that "it worked yesterday" isn't the same as "it's correct."
  • Distribution is a completely different problem than building. The hardest part of this project wasn't the code -- it's convincing anyone (human or agent) to actually call the endpoint.

Try it

https://money-agent-production-a0a9.up.railway.app/api/summarize -- it also self-lists on the x402 Bazaar (x402bazaar.org) for agent-to-agent discovery. Would love feedback from anyone else building in the agent-native payments space, or thoughts on where this kind of thing is actually useful vs. a neat toy.

Top comments (0)