DEV Community

moralito311-andr
moralito311-andr

Posted on

AI agents are becoming your customers. Here's how they pay.

For twenty years the customer was a human clicking a button. The web is built around that: signup forms, dashboards, credit-card fields, monthly plans. None of it fits an autonomous agent. An agent doesn't click. It calls APIs, and it needs to pay the way it does everything else — programmatically, per call, without a human in the loop.

The x402 protocol is a small, boring, correct answer to this. A resource returns HTTP 402 Payment Required with a challenge. The caller signs an EIP-3009 transferWithAuthorization (USDC on Base), resends it in an X-PAYMENT header, and the server settles it on-chain and returns the result. No account, no key exchange, no invoice. The payer signs with their own key; the server never holds it.

I wrote a LangChain SDK that closes the loop so an agent can pay by itself:

from andreax_langchain_autopay import AndreaxToolkittools = AndreaxToolkit( wallet="0xYourAgentWallet", private_key=os.environ["AGENT_PRIVATE_KEY"], auto_pay=True, max_usdc_per_call=0.10, daily_usdc_budget=5.00,).load()
The interesting design decisions are the guardrails, not the payment:

The key stays with the developer. It's read from your environment and used to sign locally. The SDK never logs it, stores it, or sends it anywhere. Signing an EIP-712 message is a local operation.

Spending is capped in two dimensions. A per-call ceiling and a daily budget. The SDK raises rather than sign a call that would exceed either. Giving an LLM a wallet is powerful; it should be bounded.

auto_pay is off by default. Nothing is ever paid unless you opt in and provide a funded wallet.

The pattern generalizes past any one provider. If you're building tools for agents, serving a 402 with a proper x402 challenge means any x402-aware agent can discover and pay you with zero integration on your side. The buyer is the agent; the human never showed up.

If you try it, I'd genuinely like to see the spend logs — that's where this stops being a demo.

Code and tool catalog: https://pagos.andreax.dev/api/agents/discover

Top comments (0)