The Vending Machine for AI Agents: How x402 + IteraTools Enables Autonomous Micropayments
Source: Dev.to
The Problem: AI Agents Need a Simpler Way to Pay for Tools
When an AI agent needs a tool, it shouldn’t have to:
- Fill out a form
- Wait for API‑key approval
- Manage a monthly subscription
It should just pay $0.001 and get what it needs.
Current Workflow for Every External API Call
- Create an account with the API provider
- Enter a credit card (often with KYC)
- Buy credits or a subscription plan – prepaying for a commitment
- Store and manage an API key (security risk)
- Handle billing, renewals, rate limits
This was fine when humans were integrating. AI agents don’t have credit cards, can’t click “Agree to Terms,” and can’t manage rotating keys in a vault.
The internet was built for humans. But agents are using it now.
Introducing HTTP 402 “Payment Required” via the x402 Protocol
- HTTP 402 was defined in 1991 as a reserved status code – “for future use.”
- It sat unused for over three decades.
- 2024: Coinbase released x402, an open standard that finally gives HTTP 402 its purpose.
The Complete x402 Flow
- Agent sends an HTTP request → Server responds
402with payment requirements. - Agent signs a gas‑less USDC authorization (EIP‑3009, no gas needed).
- Agent retries with an
X-Paymentheader. - Server verifies → settles on Base → returns
200 OK.
No accounts. No API keys. No subscriptions.
The agent carries a wallet, pays per call, and gets the resource – a vending machine for the internet.
Example 402 Response
HTTP/1.1 402 Payment Required
Content-Type: application/json
{
"x402Version": 1,
"error": "X-Payment header is required",
"accepts": [
{
"scheme": "exact",
"network": "base",
"maxAmountRequired": "1000",
"resource": "https://api.iteratools.com/qrcode",
"description": "QR code generation",
"payTo": "0xa81Dbd562436511dE5268BF70cF124C2689Ab11a",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
}
]
}- The payment amount is machine‑readable.
- The wallet address is in the response.
- The agent doesn’t need to ask anyone – it just pays.
Why Traditional APIs Don’t Fit AI Agents
| Human‑Centric Requirement | AI‑Agent Reality |
|---|---|
| Can read Terms of Service | No UI to read/accept |
| Has a credit card | No credit card |
| Waits for approval emails | Needs instant response |
Stores credentials in .env files | Needs programmatic, on‑chain payment |
AI Agents Need
- Autonomous code execution
- Ability to hold crypto wallets (via CDP, viem, etc.)
- Millisecond‑scale payment inside a reasoning loop
- Zero human intervention for a $0.001 API call
x402 matches the agent mental model perfectly:
“I need this resource. How much does it cost? Here’s the payment. Give me the resource.”
It’s exactly the logic of a vending machine: Put money in → get product out. No account, no subscription, no paperwork.
IteraTools: 41 Utility Tools Built for AI Agents (x402‑Compatible)
| Category | Tools | Starting Price |
|---|---|---|
| Text | TTS, translation, summarize, sentiment | $0.001 /call |
| Web | Search, scrape, screenshot | $0.001–$0.002 /call |
| Image | QR code, generate, classify | $0.001–$0.005 /call |
| Data | CSV parse, chart, extract | $0.001–$0.002 /call |
| Communication | WhatsApp send, email | $0.002 /call |
| Code | Execute Python/JS sandbox | $0.001 /call |
- No subscription needed to start.
- No API key to manage.
- Just a Base wallet with a few cents of USDC.
Full Node.js Agent Example (Zero Human Intervention)
import { withPaymentInterceptor } from '@x402/fetch';
import { createWalletClient, http } from 'viem';
import { base } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
// ---------------------------------------------------
// 1️⃣ Agent’s wallet – loaded from environment
// ---------------------------------------------------
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.AGENT_PRIVATE_KEY),
chain: base,
transport: http(),
});
// ---------------------------------------------------
// 2️⃣ Wrap fetch – x402/fetch handles 402 automatically
// ---------------------------------------------------
const payingFetch = withPaymentInterceptor(fetch, wallet);
// ---------------------------------------------------
// 3️⃣ Research a topic (cost $0.001)
// ---------------------------------------------------
const searchRes = await payingFetch('https://api.iteratools.com/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'x402 protocol AI agents', num: 5 }),
});
const searchData = await searchRes.json();
// ---------------------------------------------------
// 4️⃣ Summarize the results (cost $0.002)
// ---------------------------------------------------
const summaryRes = await payingFetch('https://api.iteratools.com/summarize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: searchData.results.map(r => r.snippet).join('\n')
}),
});
const summary = await summaryRes.json();
// ---------------------------------------------------
// 5️⃣ Generate a QR code linking to the source (cost $0.001)
// ---------------------------------------------------
const qrRes = await payingFetch('https://api.iteratools.com/qrcode', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: searchData.results[0].url }),
});
const qr = await qrRes.json();
// ---------------------------------------------------
// 6️⃣ Output (total cost $0.004 USDC)
// ---------------------------------------------------
console.log('Summary:', summary.text);
console.log('QR Code:', qr.qr_url);What withPaymentInterceptor Does
| Step | Action |
|---|---|
| Initial request | Sends the request normally. |
| Receive 402 | Parses maxAmountRequired, payTo, asset, network. |
| Build EIP‑3009 auth | { from, to, value, validAfter, validBefore, nonce }. |
| Sign | Uses EIP‑712 (typed‑data signature) – no gas. |
| Encode | Base64‑encoded JSON placed in X-Payment header. |
| Retry | Sends the request again with the header. |
| Success | Server returns 200 OK with the tool’s response. |
- The agent never knows a payment happened – it just receives data.
- Zero gas for the agent; the server’s settler pays gas on Base.
- The only requirement: the agent holds enough USDC on Base.
How the Server (IteraTools) Handles the Payment
- Verify the EIP‑712 signature.
- Validate recipient, amount, timing window, and nonce.
- Call
USDC.transferWithAuthorizationon Base (settler pays gas). - Execute the requested tool.
- Return the result to the agent.
Bottom Line
- x402 turns HTTP 402 into a practical, machine‑readable payment flow.
- AI agents can pay per call with a crypto wallet, eliminating the need for human‑centric onboarding.
- IteraTools provides a ready‑made catalog of low‑cost, x402‑compatible utilities, enabling agents to operate autonomously across text, web, image, data, communication, and code domains.
The internet was built for humans; with x402, it finally works for agents too.
to‑agent commerce
An orchestrator agent can spin up sub‑agents, each with its own funded wallet, and have them autonomously purchase tools:
Orchestrator Agent
├── Research Agent → pays $0.001 for /search
│ → pays $0.002 for /scrape
├── Writing Agent → pays $0.002 for /summarize
│ → pays $0.001 for /sentiment
└── Media Agent → pays $0.005 for /image/generate
→ pays $0.001 for /ttsTotal: $0.012 USDC — settled on Base, no human involved
This is the multi‑agent economy. Agents don’t share an API key — each has a wallet and pays only for what it uses. The orchestrator can fund sub‑agents with exactly what they need for a task, no more.
Traditional API vs. x402 + IteraTools
| Feature | Traditional API | x402 + IteraTools |
|---|---|---|
| Onboarding | Create account, KYC, credit card | None — just a wallet |
| Access | API key in header | Payment in header |
| Billing | Monthly subscription or prepaid credits | Pay‑per‑call, pennies |
| Automation | Manual key rotation, monitoring | Fully autonomous |
| Agent‑native | No — designed for humans | Yes — designed for agents |
| Privacy | Provider tracks all calls | On‑chain, pseudonymous |
Getting Started
As an agent developer (buyer)
npm install @x402/fetch viem @iteratools/mcpimport { withPaymentInterceptor } from '@x402/fetch';
// Fund your Base wallet with $1 of USDC
// That's ~100‑1000 API calls depending on tools usedAs an MCP user (Claude, Cursor, etc.)
npx @iteratools/mcp- 41 tools available instantly. No API key. Pay per use.
Try the live 402 response
curl -s -X POST https://api.iteratools.com/qrcode \
-H "Content-Type: application/json" \
-d '{"text":"hello world"}'You’ll see a real 402 response with payment instructions.
Why x402?
x402 isn’t just a payment protocol – it’s a capability unlock for autonomous agents.
Today, most AI agents are limited to tools their creators pre‑authorized and pre‑paid for. With x402, an agent can discover and pay for any x402‑compatible service in the world — autonomously, in real time, for pennies.
The internet of APIs becomes the internet of agent tools.
IteraTools is building on this model:
- 41 tools today, more added every month
- Available to any agent with a Base wallet and a few dollars of USDC
The vending machine is open. Put your USDC in. Get your tools out.
IteraTools: https://iteratools.com
Quick Commands
# Test the 402 endpoint
curl -s -X POST https://api.iteratools.com/qrcode \
-H 'Content-Type: application/json' \
-d '{"text":"test"}'
# Run the MCP package
npx @iteratools/mcpResources
- x402 protocol: https://x402.org | https://docs.x402.org
- GitHub (x402): https://github.com/coinbase/x402
- Live 402 demo script: https://github.com/fredpsantos33/iteratools-x402-demo
Contact
IteraTools is built by Iterasoft. If you’re building AI agents, we’d love to hear from you.