3 Lines of Code: Make Your AI Agent Pay for APIs with USDC

August 3, 2026 · minia2a · 4 min read · Tutorial

Your AI agent can reason, plan, and execute. But can it pay? Can it autonomously buy the data it needs — token prices, wallet intelligence, gas estimates — without a human pulling out a credit card?

With x402 and minia2a, the answer is yes. Here's how to do it in three lines of code.

The Problem

Traditional API access means API keys, signup forms, rate limits, and monthly subscriptions. AI agents can't fill out signup forms. They can't pass credit checks. They can't negotiate SaaS contracts.

But they can sign a transaction.

x402 (HTTP 402 Payment Required) lets your agent pay for API calls the same way it makes them: programmatically. No human in the loop.

Line 1: Register Your Agent (Get a Wallet)

Step 1
curl -s -X POST https://minia2a.uk/api/v1/register-simple \
  -H "Content-Type: application/json" \
  -d '{"name":"my-first-agent"}'
{ "wallet": "0xabc123...", "name": "my-first-agent", "credits": 500, "message": "500 free credits granted" }

That's it. Your agent now has a self-custody wallet on Base L2, preloaded with 500 free credits (worth ~$2.50 in API calls). No KYC. No gas fees. No waiting.

Line 2: Call a Paid API

Step 2
curl -s "https://minia2a.uk/x402/proxy/x402-time?wallet=0xabc123..."
{"ok":true,"result":{"utc":"2026-08-03T05:30:31.722Z","unix":1785735031}}

Your agent just paid for an API call. Credits were deducted from your balance. The response includes the data you asked for.

No API key. No subscription. No credit card. Just: agent wants data → agent pays → agent gets data.

Line 3: Check Your Balance

Step 3
curl -s "https://minia2a.uk/api/v1/credits?wallet=0xabc123..."
{"wallet":"0xabc123...","credits":499,"name":"my-first-agent"}

499 credits left. One call consumed. Your agent is now a paying customer of the API economy.

What Can Your Agent Pay For?

minia2a lists 180 x402-enabled services your agent can call right now:

ServiceWhat It DoesPrice
x402-timePrecise UTC timestamp$0.001
x402-gasReal-time gas prices across chains$0.003
x402-token-securityToken contract audit (honeypot, tax, ownership)$0.005
x402-wallet-intelWallet age, activity, PnL, tags$0.005
x402-web-scrapeScrape any webpage, clean output$0.005
x402-ens-resolveResolve ENS names → addresses$0.001
x402-funding-ratePerpetual funding rates across exchanges$0.003
x402-sentimentCrypto sentiment analysis$0.003

Full catalog: curl https://minia2a.uk/api/services

From Python: A Real Agent

Here's a Python agent that researches a token before trading — it calls 3 paid APIs and pays for each:

import requests, os

WALLET = os.environ["MINIA2A_WALLET"]
BASE = "https://minia2a.uk/x402/proxy"

def call(service, **params):
    params["wallet"] = WALLET
    r = requests.get(f"{BASE}/{service}", params=params)
    return r.json()

token = "0x1234..."
security = call("x402-token-security", token=token)
funding  = call("x402-funding-rate", symbol="ETH")
sentiment = call("x402-sentiment", symbol="ETH")

print(f"Token safety: {security.get('result',{}).get('isHoneypot')}")
print(f"ETH funding: {funding.get('result',{}).get('rate')}")
print(f"ETH sentiment: {sentiment.get('result',{}).get('sentiment')}")

# Check remaining credits
r = requests.get(f"https://minia2a.uk/api/v1/credits?wallet={WALLET}")
print(f"Credits left: {r.json()['credits']}")

When Credits Run Out

After 500 free calls (or when you need more), your agent hits an HTTP 402:

HTTP 402 Payment Required { "_registration_required": true, "message": "Credits exhausted. Pay with USDC on Base.", "payment": { "amount": "0.005", "token": "USDC", "chain": "Base", "recipient": "0xf16F0882de08315B438E9f3a2Abfb2d2E5d94ECA" } }

Your agent sends $0.005 USDC on Base → retries the request → gets the data. The whole flow takes under 2 seconds. Or use @x402/fetch (npm) which handles the 402 → pay → retry cycle automatically:

import { x402Fetch } from "@x402/fetch";
const res = await x402Fetch("https://minia2a.uk/x402/proxy/x402-gas");
const data = await res.json();

What Just Happened?

In three lines of code, you gave your AI agent:

  1. A wallet — self-custody, on Base L2, no gas fees
  2. Purchasing power — 500 free credits to start, then pay-per-call with USDC
  3. API access — 180 services, any of which your agent can call and pay for autonomously

Your agent is no longer just a reasoning engine. It's an economic actor. It earns. It spends. It decides what data is worth paying for.

Try it now: Paste the 3 curl commands above into your terminal. In 30 seconds, your agent has a wallet, credits, and has made its first paid API call. No signup. No waiting.

minia2a is a live marketplace. 180 services. USDC on Base. Pay per call. minia2a.uk