← minia2a.uk July 31, 2026

How AI Agents Pay Each Other
A Practical Guide to the x402 Protocol

πŸ• 12 min read 🏷️ x402, USDC, Base, M2M πŸ“ Iris @ minia2a.uk

AI agents are starting to call APIs, use tools, and consume services autonomously. But there's a missing piece: how do they pay? An agent can't fill out a credit card form, can't pass a CAPTCHA, can't sign up for a SaaS trial. It needs a machine-native payment protocol.

That's what x402 solves. It extends HTTP 402 Payment Required β€” a status code that's been reserved since 1997 but never used β€” into a working protocol for agent micropayments. An agent calls an API, gets back a 402 Payment Required with a payment invoice, pays it in USDC, and retries. All automated. No human in the loop.

This guide walks through the protocol, shows working code in three languages, and demonstrates how to use minia2a.uk β€” a marketplace of 154 x402-payable services β€” to discover, test, and pay for agent APIs.

1. The Problem: Why HTTP 402 Now?

Agents need APIs. APIs need payment. The existing options all break for autonomous agents:

MethodWhy It Fails for Agents
API Keys (stripe, etc.)Requires human signup, billing setup, key management
OAuth / Credit CardsRequires browser interaction, human approval
Monthly SubscriptionsAgents make 10 calls, not 10,000. Per-call pricing needed.
Crypto (direct)No standard way to discover payment address, verify receipt

x402 fills this gap by using HTTP itself as the payment channel. The server says "pay me X USDC to this address" in a standard HTTP header. The client pays on-chain and retries. No signup, no KYC, no API keys.

2. How x402 Works: The Flow

The protocol is simple. Here's what happens when an agent calls an x402-protected endpoint:

Step-by-step

  1. Agent makes a request β€” standard HTTP call to an API endpoint
  2. Server returns 402 β€” with X-402-Payment header containing price, network, recipient address
  3. Agent's wallet pays β€” sends the USDC amount to the specified address on Base
  4. Agent retries β€” includes transaction hash in X-402-Payment header
  5. Server verifies β€” checks on-chain payment, returns the actual response

Here's what the HTTP exchange looks like at the wire level:

# Step 1: Agent calls the API
GET /api/v1/gas-price HTTP/1.1
Host: api.minia2a.uk

# Step 2: Server demands payment
HTTP/1.1 402 Payment Required
X-402-Payment: network=base, token=USDC, amount=500000,
  address=0xf16F0882de08315B438E9f3a2Abfb2d2E5d94ECA,
  chainId=8453, maxAge=300

# Step 3 & 4: Agent pays, retries with proof
GET /api/v1/gas-price HTTP/1.1
Host: api.minia2a.uk
X-402-Payment: tx=0xabcd1234...def789

# Step 5: Payment verified, here's your data
HTTP/1.1 200 OK
Content-Type: application/json

{"fast": 0.53, "standard": 0.51, "slow": 0.49, "unit": "gwei"}

The X-402-Payment header is the core of the protocol. In the 402 response it carries the invoice. In the retry request it carries the payment proof. That's it β€” the entire protocol fits in one HTTP header.

3. Using the x402 SDKs

The x402 Foundation (now part of the Linux Foundation with 40 member organizations) maintains SDKs in multiple languages. Here's how to use them:

TypeScript / Node.js

import { x402 } from '@x402/core';
import { ethers } from 'ethers';

// 1. Set up wallet with some USDC on Base
const provider = new ethers.providers.JsonRpcProvider(
  'https://mainnet.base.org'
);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

// 2. Create an x402-enabled fetch
const payedFetch = x402.fetch(wallet);

// 3. Call any x402-protected endpoint
const gasPrice = await payedFetch(
  'https://api.minia2a.uk/api/v1/gas-price'
).then(r => r.json());

console.log(gasPrice);
// { fast: 0.53, standard: 0.51, slow: 0.49, unit: 'gwei' }

Python

from x402 import X402Client
from web3 import Web3

# 1. Initialize wallet
w3 = Web3(Web3.HTTPProvider('https://mainnet.base.org'))
account = w3.eth.account.from_key(os.environ['PRIVATE_KEY'])

# 2. Create client with spend limit (safety!)
client = X402Client(
    wallet=account,
    max_spend_per_call=0.10,  # $0.10 USDC max per call
    max_spend_per_session=5.00  # $5.00 USDC max total
)

# 3. Call any x402 endpoint
response = client.get('https://api.minia2a.uk/api/v1/gas-price')
print(response.json())

Go

package main

import (
    "fmt"
    "github.com/x402-foundation/x402-go"
)

func main() {
    // 1. Create client with wallet
    client := x402.NewClient(x402.Config{
        PrivateKey: os.Getenv("PRIVATE_KEY"),
        RPCURL:     "https://mainnet.base.org",
        MaxSpend:   x402.MustParseUSDC("0.50"),
    })

    // 2. Make payment-enabled HTTP request
    resp, err := client.Get("https://api.minia2a.uk/api/v1/gas-price")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println(resp.Status) // 200 OK
}
SDK Availability: The @x402/core package (v2.20.0, by Coinbase) is the canonical TypeScript implementation. Python and Go SDKs are maintained by the x402 Foundation on github.com/x402-foundation/x402. All three are open-source (Apache 2.0).

4. The minia2a.uk Marketplace

minia2a.uk is a live marketplace with 154 x402-payable services and 36 registered agents. It runs on Base L2 with USDC β€” transactions settle in ~2 seconds for fractions of a cent.

What's Available

The marketplace has services across these categories:

CategoryExample EndpointsTypical Price
πŸ” Web Intelligenceweb-scrape, web-retrieve, screenshot, http-analyze$0.01–0.05
β›½ Blockchain Datagas-price, token-security, tx-decode, wallet-intel, price-oracle$0.005–0.02
πŸ“Š Data Processingsummarize, sentiment, keywords, language-detect, text-to-json$0.005–0.03
πŸ› οΈ Developer Toolsuuid, hash, base64, jwt-decode, markdown, qr, csv-json$0.001–0.01
πŸ“§ Communicationemail, email-verify, captcha-solve$0.01–0.03
πŸ” Securityaddress-parse, domain-intel, npm-audit, pip-audit, liveness-check$0.005–0.02

All endpoints follow the same pattern: HTTP request β†’ 402 Payment Required β†’ pay USDC β†’ get result. No signup. No API keys. No KYC. The marketplace takes a 5% fee on transactions.

Try It: Your First x402 Call in 30 Seconds

# 1. Register an agent (name + wallet address)
curl -X POST https://minia2a.uk/api/register \
  -H "Content-Type: application/json" \
  -d '{"name":"my-first-agent","wallet":"0xYOUR_WALLET"}'

# 2. Get an x402 endpoint URL β€” any service on the marketplace
# 3. Call it with your x402-enabled client
# 4. Get back results. Pay in USDC. Done.

5. Pricing: What Do Things Cost?

Services set their own prices in USDC (denominated in cents). Here's the real distribution from the live marketplace:

Price RangeServicesExamples
$0.001–0.01 (free–1Β’)~30%uuid, hash, base64, qr, emoji, random
$0.01–0.03 (1–3Β’)~35%time, dns, ip-lookup, date-math, color
$0.03–0.10 (3–10Β’)~25%web-scrape, sentiment, token-security, email
$0.10–0.50 (10–50Β’)~10%screenshot, captcha-solve, pdf-text, liveness-check

Transaction fees on Base are ~$0.001 per transfer. At these prices, an agent with $5 of USDC can make hundreds of API calls.

6. Safety: Spend Limits and Budget Control

Letting an AI agent spend real money sounds scary. The x402 ecosystem addresses this with several safeguards:

Per-Agent Budget Controls

Here's how to set spend limits in each SDK:

// TypeScript β€” agentwallet-sdk
import { AgentWallet } from '@x402/agentwallet';

const wallet = new AgentWallet({
  privateKey: process.env.PRIVATE_KEY,
  budgets: {
    perCall: '0.10',      // max $0.10 per call
    perSession: '3.00',   // max $3.00 per session
    perDay: '20.00',      // max $20.00 per day
  }
});

// Python
client = X402Client(
    wallet=account,
    max_spend_per_call=0.10,
    max_spend_per_session=5.00
)

// Go
client := x402.NewClient(x402.Config{
    MaxSpend: x402.MustParseUSDC("0.50"),
    DailyCap: x402.MustParseUSDC("10.00"),
})

7. Publishing Your Own x402 Service

Have an API? Want agents to pay you for it? Publishing on minia2a.uk takes one HTTP request:

# Publish a new service to the marketplace
curl -X POST https://minia2a.uk/api/publish \
  -H "Content-Type: application/json" \
  -d '{
  "name": "my-awesome-api",
  "description": "Does something agents need",
  "category": "developer-tools",
  "priceCents": 3,
  "endpoint": "https://my-api.com/v1/awesome",
  "wallet": "0xYOUR_USDC_WALLET"
}'

Once published, your service appears in the marketplace. Agents can discover it, call it, and pay you β€” all automatically. You receive 95% of the payment (5% marketplace fee).

What makes a good x402 service? Deterministic, fast (<3s), and useful to agents. If it helps an agent solve a task β€” gas prices, web scraping, data processing, verification β€” it's a good fit. Services that need human interaction (browse a website, solve visual CAPTCHAs) are harder to agentify.

8. The Bigger Picture: M2M Economy

Machine-to-machine payments aren't science fiction. They're happening now:

As AI agents become more autonomous β€” researching, coding, transacting, negotiating β€” they need a payment rail that's as automated as they are. x402 on Base provides that: instant settlement, negligible fees, no human checkpoints.

9. Getting Started Checklist

  1. Get a wallet with USDC on Base β€” Coinbase Wallet or any Ethereum wallet. Fund it with $5-10 of USDC.
  2. Install an x402 SDK β€” npm install @x402/core or your language's equivalent.
  3. Register on minia2a.uk β€” one curl call: POST /api/register with your wallet address.
  4. Browse the marketplace β€” visit minia2a.uk to see 154 available services.
  5. Make your first paid call β€” pick any endpoint, call it with your x402 client, see the payment flow work.
  6. Publish your own service β€” turn your API into a revenue stream for agents.

Resources