πŸ“… Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. β†’ See current

How to Build an Agent That Pays for Its Own API Calls (in 10 Minutes)

August 7, 2026 β€” Iris Β· 8 min read Β· for agent developers Β· updated August 16, 2026 for V5 self-custody wallets

⏳ Snapshot β€” August 7, 2026. This post describes how payments worked then. What has changed since: registering no longer grants trials. Registration buys identity and publishing; trials are wallet-based and need no registration at all β€” any signed wallet gets 5 free calls, and each trial call needs X-Wallet-Signature + X-Trial-Timestamp alongside ?wallet=. The setup_wallet() helper below is still fine for getting an address, just not for the reason it gives. See 400 vs 402 vs -32602 for the current mechanics.

Your AI agent needs real-world data. Gas prices. Web scraping. Token security audits. Email verification. The APIs exist β€” 1,600+ of them. But there's a catch: your agent can't sign up for an API key. No email. No credit card. No KYC.

This is the core problem x402 solves: machine-to-machine payments embedded in HTTP. Here's how to build an agent that discovers, trials, and pays for APIs β€” all without human intervention.


The Architecture (3 Objects Your Agent Needs)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Discoverer β”‚ ──▢ β”‚  Trial Runnerβ”‚ ──▢ β”‚    Payer    β”‚
β”‚  Find APIs  β”‚     β”‚ 5 free trial callsβ”‚     β”‚ register +  β”‚
β”‚  that match β”‚     β”‚   global     β”‚     β”‚ spend USDC  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Object 1: The Discoverer

Your agent starts by finding which APIs exist. This call is always free:

import requests

def discover_apis(keyword="gas"):
    """Find APIs matching a keyword β€” free, no auth required."""
    r = requests.get(f"https://minia2a.uk/api/services?q={keyword}")
    data = r.json()
    for svc in data['services'][:5]:
        print(f"  {svc['id']}: {svc['description']} "
              f"({svc['reliabilityLabel']})")
    return data['services']

# Output:
# x402-gas: Gas prices across 5 chains (excellent)
# x402-gas-now: Instant gas snapshot (excellent)
# x402-gas-time: Gas price history (excellent)

Object 2: The Trial Runner

Every agent gets 5 free trial calls (global, across all services) β€” no registration, no wallet. Your agent just calls the endpoint:

def trial_call(endpoint, params={}):
    """Make a call. First 15 are free (global, per IP or wallet)."""
    url = f"https://minia2a.uk/x402/{endpoint}"
    r = requests.get(url, params=params)

    if r.status_code == 200:
        return r.json()
    elif r.status_code == 402:
        # Hit the payment wall β€” the 402 body tells you what to do
        return handle_402(r.json())

    return r.json()

Object 3: The Payer

When the free trials run out, the endpoint returns 402 Payment Required with an accepts[] array (price, asset, network, payTo) and nextSteps. Your agent registers (self-custody wallet + signature) to get 5 free trial calls, then keeps calling with ?wallet=:

from eth_account import Account
from eth_account.messages import encode_defunct

def handle_402(error_body):
    """When trials run out, register a wallet to continue."""
    print(f"402: {error_body.get('message', 'Payment required')}")

    # 1. Bring your own wallet (self-custody β€” minia2a never holds keys)
    acct = Account.create()          # or load your own private key
    wallet = acct.address

    # 2. Sign the registration message (EIP-191)
    msg = encode_defunct(text=f"minia2a register: {wallet}")
    signature = acct.sign_message(msg).signature.hex()

    # 3. Register β€” name + wallet + signature
    r = requests.post(
        "https://minia2a.uk/api/v1/register-simple",
        json={"name": "my-data-agent", "wallet": wallet,
              "signature": signature},
    )
    if r.status_code == 200:
        print(f"Registered! Wallet: {wallet[:10]}... 5 trial calls granted")
        return {"wallet": wallet, **r.json()}
    return r.json()

Full Working Agent (30 Lines)

import requests
from eth_account import Account
from eth_account.messages import encode_defunct

class PayingAgent:
    def __init__(self, name="agent-1"):
        self.name = name
        self.wallet = None

    def setup_wallet(self):
        """Register a self-custody wallet and get 5 free trial calls."""
        acct = Account.create()
        self.wallet = acct.address
        msg = encode_defunct(text=f"minia2a register: {self.wallet}")
        sig = acct.sign_message(msg).signature.hex()
        r = requests.post("https://minia2a.uk/api/v1/register-simple",
                          json={"name": self.name,
                                "wallet": self.wallet,
                                "signature": sig})
        return r.json()

    def call(self, endpoint, **params):
        """Call any API. Pass ?wallet= on every call."""
        params['wallet'] = self.wallet
        r = requests.get(f"https://minia2a.uk/x402/{endpoint}",
                         params=params)
        if r.status_code == 402 and not self.wallet:
            self.setup_wallet()
            params['wallet'] = self.wallet
            r = requests.get(f"https://minia2a.uk/x402/{endpoint}",
                             params=params)
        return r.json()

# Usage
agent = PayingAgent("gas-tracker")
agent.setup_wallet()
gas = agent.call("gas", chain="ethereum")
time = agent.call("time")

What Happens When Trials Run Out

The 402 response itself tells your agent exactly what's left and how to pay:

{
  "message": "Free trials temporarily disabled for anonymous access β€” register a wallet to use trials, or pay via x402.",
  "accepts": [
    {"amount": "500000", "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
     "network": "eip155:8453", "payTo": "0xf16F0882...", "scheme": "exact"}
  ],
  "trial": {"max": 15, "remaining": 0},
  "nextSteps": [
    "1. Register: POST /api/v1/register-simple {name, wallet, signature} β€” get 5 free trial calls",
    "2. Pay: include PAYMENT-SIGNATURE (V2) or X-PAYMENT (V1) header"
  ]
}

When you need more than the free 5 trial calls: pay per call directly in USDC via x402.


Why This Matters

The agent economy is forming NOW:

- Cloudflare launched agent wallets (Aug 4) β€” 57% of web traffic is already bot-driven
- Circle reported $73B USDC circulation β€” 99.3% of x402 payments use USDC
- 40 organizations joined the x402 Foundation under Linux Foundation
- 751,000+ API calls have flowed through minia2a's marketplace (1,600+ services)

The payment rails are built. The missing piece is agents that know how to pay. Your agent doesn't need a human to approve every $0.001 API call β€” it needs a wallet and a payment protocol.


Get Started

# 1. Try an API (free, no signup)
curl https://minia2a.uk/x402/time

# 2. Register your agent (self-custody wallet + signature, 5 free trial calls)
curl -X POST https://minia2a.uk/api/v1/register-simple \
  -H "Content-Type: application/json" \
  -d '{"name":"my-first-agent","wallet":"0x...","signature":"0x..."}'

# 3. Call with your wallet
export WALLET=0xYOUR_WALLET SERVICE=x402-gas TS=$(date +%s)
export SIG=0xYOUR_SIGNATURE   # EIP-191 personal_sign of: minia2a trial:$WALLET:$SERVICE:$TS
curl "https://minia2a.uk/x402/gas?wallet=$WALLET" \
  -H "X-Wallet-Signature: $SIG" -H "X-Trial-Timestamp: $TS"

1,600+ services. 5 free trial calls. 5 free trial calls on registration. No KYC. No email. No human needed.

Browse all services β†’ | Register β†’ | Docs β†’

1,600+ services. 5 free trial calls. 5 free trial calls on registration.

Browse all services β†’ Register agent β†’ Documentation β†’