Published July 2026 · 8 min read · minia2a + x402 + USDC on Base
Most AI agents today are financially crippled. They can call free APIs, but the moment they need a paid service — CAPTCHA solving, premium data, on-chain reads — they hit a wall. Either the developer pre-pays for everything (expensive, unscalable) or the agent simply can't access paid tools.
x402 changes this. It's an HTTP payment protocol that lets an agent pay for API calls as it makes them — microtransactions in USDC on Base L2. No API keys. No monthly subscriptions. No KYC. The agent carries its own wallet and pays per call.
In this tutorial, you'll build a working agent that registers on minia2a (the x402 marketplace), gets free credits, and starts making paid API calls — all in ~10 minutes.
A Python agent that:
X-x402-Payment) automaticallyEvery agent needs a wallet. minia2a creates one for you automatically — no MetaMask, no seed phrase management (though you should save the private key).
# Register — get wallet + 500 credits instantly
curl -X POST https://minia2a.uk/api/v1/register-simple \
-H "Content-Type: application/json" \
-d '{"name":"my-first-agent"}'
Response:
{
"wallet": "0xYourAgentWallet...",
"privateKey": "0x...",
"credits": 500,
"message": "registered"
}
The private key is shown once. Save it. Without it, you can't spend credits or top up. Store it as an environment variable:
export AGENT_WALLET=0xYourAgentWallet...
export AGENT_KEY=0xYourPrivateKey...
Let's call the token security scanner. It checks any ERC-20 token for honeypots, ownership renouncement, and liquidity — costs 1 credit ($0.005).
# Scan USDC for security risks
curl "https://minia2a.uk/x402/token-security?\
wallet=0xYourAgentWallet...&\
address=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
Under the hood, here's what happens:
Here's a complete Python agent that registers, checks balance, makes calls, and tracks spending:
#!/usr/bin/env python3
"""agent.py — An AI agent that pays for its own API calls via x402"""
import os, json, urllib.request, urllib.error
MINIA2A = "https://minia2a.uk"
# ── Wallet ─────────────────────────────────────────
WALLET = os.getenv("AGENT_WALLET")
PRIVATE_KEY = os.getenv("AGENT_KEY")
def register(name: str) -> dict:
"""Register a new agent — get wallet + 500 credits."""
data = json.dumps({"name": name}).encode()
req = urllib.request.Request(
f"{MINIA2A}/api/v1/register-simple",
data=data,
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as r:
return json.loads(r.read())
def check_credits(wallet: str) -> dict:
"""Check credit balance."""
with urllib.request.urlopen(f"{MINIA2A}/api/my-credits?wallet={wallet}") as r:
return json.loads(r.read())
def call_service(endpoint: str, wallet: str, **params) -> dict:
"""Call any x402 service. Credits deducted automatically."""
qs = "&".join([f"wallet={wallet}"] + [f"{k}={v}" for k, v in params.items()])
url = f"{MINIA2A}{endpoint}?{qs}"
try:
with urllib.request.urlopen(url) as r:
# Check for x402 payment header
payment = r.headers.get("X-x402-Payment")
result = json.loads(r.read())
if payment:
result["_payment"] = payment
return result
except urllib.error.HTTPError as e:
body = e.read().decode()
# 402 = insufficient credits
if e.code == 402:
return {"error": "insufficient_credits", "detail": body}
raise
# ── Main ───────────────────────────────────────────
if __name__ == "__main__":
# 1. Register (first time only)
if not WALLET:
result = register("my-python-agent")
print(f"✓ Registered: {result['wallet'][:16]}...")
print(f" Credits: {result['credits']}")
WALLET = result["wallet"]
# Save to .env
with open(".env", "w") as f:
f.write(f"AGENT_WALLET={WALLET}\n")
f.write(f"AGENT_KEY={result['privateKey']}\n")
else:
print(f"Using wallet: {WALLET[:16]}...")
# 2. Check balance
bal = check_credits(WALLET)
print(f"Balance: {bal.get('credits', '?')} credits")
# 3. Call a paid service
print("\n── Token Security Scan ──")
result = call_service("/x402/token-security", WALLET,
address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
if "error" not in result:
print(f"✓ Token: {result.get('token', 'USDC')}")
print(f" Honeypot risk: {result.get('isHoneypot', '?')}")
print(f" Cost: 1 credit ($0.005)")
else:
print(f"✗ {result['error']}")
# 4. Check balance again
bal = check_credits(WALLET)
print(f"\nNew balance: {bal.get('credits', '?')} credits")
print("Done — agent paid for its own API call ✓")
python3 agent.py
Output:
✓ Registered: 0xf16F0882de08...
Credits: 500
Balance: 500 credits
── Token Security Scan ──
✓ Token: USDC
Honeypot risk: false
Cost: 1 credit ($0.005)
New balance: 499 credits
Done — agent paid for its own API call ✓
x402 is an HTTP standard (RFC 9744, governed by the Linux Foundation) for machine-to-machine payments. Here's the flow:
Agent minia2a Service
│ │ │
│── GET /x402/token-security? ─▶│ │
│ wallet=0x...&address=... │ │
│ │── check credits(0x...) ──▶ │
│ │◀── 500 credits │
│ │── deduct 1 credit │
│ │── GET /token-security ────▶ │
│ │◀── {honeypot: false, ...} │
│◀── 200 {result} ───────────│ │
│ X-x402-Payment: 1 credit │ │
The agent never holds an API key. The service never sees the agent's wallet. minia2a handles the payment settlement, dispute resolution, and service discovery.
| Service | Endpoint | Cost | Use Case |
|---|---|---|---|
| ⛽ Gas Price | /x402/gas | Free | Check gas before submitting tx |
| 🔐 Token Security | /x402/token-security | 1 credit | Audit tokens before trading |
| 🤖 CAPTCHA Solve | /x402/captcha-solve | 2 credits | Bypass CAPTCHAs programmatically |
| 🌐 Web Scrape | /x402/web-scrape | 1 credit | Extract structured data from URLs |
| 📧 Email Verify | /x402/email-verify | 1 credit | Validate email addresses |
| 🏷️ ENS Resolve | /x402/ens-resolve | 1 credit | Resolve .eth names |
| 💱 DEX Price | /x402/dex-price | 1 credit | Get on-chain token prices |
| 📈 Funding Rate | /x402/funding-rate | 1 credit | Perpetual funding rates |
Your agent gets 500 free credits ($2.50) at registration — enough for ~50-500 API calls. When they run out:
0xf16F0882de08315B438E9f3a2Abfb2d2E5d94ECA, paste txHash at /buy.html. 1 USDC = 200 credits./api/buy-credits when low.Your agent can be paying for its own API calls in the next 10 minutes.
Register Your Agent — Get 500 Free CreditsNo KYC. No API keys. No subscription. Just USDC on Base.
List your API on minia2a and let agents pay YOU per call. USDC micropayments, no Stripe, no KYC.
Monetize Your API →📊 Related: x402 Protocol: 2026 State of Agent Payments — the full ecosystem map.