When an AI agent needs a tool, it shouldn't have to fill out a form, wait for API key approval, and manage a monthly subscription. It should just pay $0.001 and get what it needs.
The Problem With APIs Today
Every time an AI agent needs to call an external API, someone has to:
- Create an account with the API provider
- Enter a credit card (sometimes go through 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 the ones integrating. But AI agents don't have credit cards. They can't click "Agree to Terms." They can't manage a rotating key in a vault.
The internet was built for humans. But agents are using it now.
Enter HTTP 402: The Status Code That Was Waiting for Its Moment
HTTP 402 "Payment Required" was defined in 1991 as a reserved status code — "for future use." It sat unused for over three decades.
Then in 2024, Coinbase released the x402 protocol: an open standard that finally gives HTTP 402 its purpose.
Here's the entire x402 flow:
1. Agent sends HTTP request → server responds 402 with payment requirements
2. Agent signs a gasless USDC authorization (EIP-3009, no gas needed)
3. Agent retries with X-Payment header
4. 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. It's a vending machine for the internet.
HTTP/1.1 402 Payment Required
{
"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 x402 Was Made for AI Agents
Traditional APIs were designed for human developers who:
- Can read terms of service
- Have credit cards
- Can wait for approval emails
- Manage credentials in
.envfiles
AI agents are different:
- They can execute code autonomously
- They can hold crypto wallets (via CDP, viem, etc.)
- They need to pay for tools inside a reasoning loop — in milliseconds
- They shouldn't require human intervention to access 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 the same logic as a vending machine. Put money in, get product out. No account. No subscription. No paperwork.
IteraTools: 41 Pay-Per-Use Tools Ready for Agents
IteraTools is a collection of 41 utility tools built specifically for AI agents, all x402-compatible. Tools range from:
| 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.
Live Code Example
Here's a complete Node.js agent that pays for its own tools with zero human intervention:
import { withPaymentInterceptor } from '@x402/fetch';
import { createWalletClient, http } from 'viem';
import { base } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
// The agent's wallet — loaded from environment
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.AGENT_PRIVATE_KEY),
chain: base,
transport: http(),
});
// Wrap fetch — x402/fetch handles 402 responses automatically
// When the API returns 402, it signs the USDC authorization and retries
const payingFetch = withPaymentInterceptor(fetch, wallet);
// Step 1: Research a topic (costs $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();
// Step 2: Summarize the results (costs $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();
// Step 3: Generate a QR code linking to the source (costs $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();
// Total cost: $0.004 USDC
// No API keys. No subscriptions. No human required.
console.log('Summary:', summary.text);
console.log('QR Code:', qr.qr_url);
The withPaymentInterceptor wrapper from @x402/fetch handles everything:
- Sends the initial request
- Receives the 402 with payment details
- Builds and signs the EIP-3009 gasless authorization
- Retries with the
X-Paymentheader - Returns the 200 response
The agent doesn't even know payment happened — it just gets its data.
What Happens Under the Hood
When withPaymentInterceptor sees a 402 response, it:
-
Parses the payment requirements from the JSON body (
maxAmountRequired,payTo,asset,network) -
Builds an EIP-3009 authorization:
{ from, to, value, validAfter, validBefore, nonce } - Signs it with EIP-712 — a typed data signature, no transaction broadcast needed
-
Encodes it as base64 JSON and puts it in the
X-Paymentheader - Retries the request with the header
On the server side, IteraTools:
- Verifies the EIP-712 signature
- Checks the recipient, amount, timing window, and nonce
- Calls
USDC.transferWithAuthorizationon Base (settler pays gas) - Executes the tool and returns the response
The agent pays zero gas. The server's settler handles on-chain settlement. The agent just needs USDC on Base.
Agent-to-Agent Payments
x402 also enables agent-to-agent commerce. An orchestrator agent can spin up sub-agents, each with their 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 /tts
Total: $0.012 USDC — settled on Base, no human involved
This is the multi-agent economy. Agents don't share an API key — they each have a wallet and pay for what they use. The orchestrator can fund sub-agents with exactly what they need for a task, no more.
Comparison With Traditional API Access
| 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/mcp
import { withPaymentInterceptor } from '@x402/fetch';
// Fund your Base wallet with $1 of USDC
// That's ~100-1000 API calls depending on tools used
As 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.
The Bigger Picture
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 every month, all 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.
Links
- IteraTools: iteratools.com
-
Try it:
curl -s -X POST https://api.iteratools.com/qrcode -H 'Content-Type: application/json' -d '{"text":"test"}' -
MCP package:
npx @iteratools/mcp - x402 protocol: x402.org | docs.x402.org
- GitHub (x402): github.com/coinbase/x402
- Live 402 demo script: github.com/fredpsantos33/iteratools-x402-demo
IteraTools is built by Iterasoft. If you're building AI agents, we'd love to hear from you.
Top comments (0)