The x402 protocol is simple: when an agent calls a paid API without payment, the server returns HTTP 402 with a payment invoice. The agent pays the invoice, retries with a payment proof header, and gets the result.
That's it. Three steps. No API keys, no signup, no monthly subscription. Here's how to implement it from scratch.
curl -s https://minia2a.uk/x402/captcha-solve
Response (HTTP 402):
{
"error": "Payment Required",
"type": "x402",
"network": "base",
"token": "USDC",
"priceCents": 5,
"recipient": "0xf16F0882de08315B438E9f3a2Abfb2d2E5d94ECA",
"chainId": 8453
}
The 402 response carries all the information an agent needs to pay: how much (5 cents USDC), to whom (the contract address), and on which chain (Base L2).
You could send USDC on-chain and wait for confirmation. That works but takes ~15 seconds. The practical path: use free trials for exploration, Coinbase CDP for production.
| Facilitator | Settlement | Speed | Trust Model |
|---|---|---|---|
| Coinbase CDP | Pre-funded wallet | ~2s | Trust Coinbase |
| Cloudflare Wallets | Pre-funded balance | ~2s | Trust Cloudflare |
| Direct on-chain | Per-transaction | ~15s | Trustless |
| Free trial | 15 calls free | Instant | No payment needed |
curl -s https://minia2a.uk/x402/captcha-solve \
-H "X-Wallet: 0xYOUR_WALLET" \
-H "X-Payment-Signature: $SIGNATURE"
Response (HTTP 200):
{
"solved": true,
"token": "recaptcha_v3_token_here",
"cost": 5,
"x-receipt": "rcpt_abc123def456"
}
class PayingAgent {
constructor(walletAddress, signer) {
this.wallet = walletAddress;
this.signer = signer;
}
async call(serviceId, params = {}) {
const url = `https://minia2a.uk/x402/${serviceId}`;
let res = await fetch(url);
if (res.status === 200) {
return res.json(); // Free trial used
}
if (res.status === 402) {
const invoice = await res.json();
return this.payAndRetry(url, invoice);
}
}
async payAndRetry(url, invoice) {
const signature = await this.signer({
recipient: invoice.recipient,
amount: invoice.priceCents,
chainId: invoice.chainId
});
const res = await fetch(url, {
headers: {
'X-Wallet': this.wallet,
'X-Payment-Signature': signature,
}
});
return res.json();
}
}
import requests
def call_x402(service_id, params, wallet, signer):
url = f"https://minia2a.uk/x402/{service_id}"
resp = requests.get(url, params=params)
if resp.status_code == 200:
return resp.json()
if resp.status_code == 402:
invoice = resp.json()
sig = signer(invoice['recipient'], invoice['priceCents'])
resp = requests.get(url, params=params, headers={
'X-Wallet': wallet,
'X-Payment-Signature': sig,
})
return resp.json()
func (a *Agent) CallX402(serviceID string, params url.Values) ([]byte, error) {
u := fmt.Sprintf("https://minia2a.uk/x402/%s?%s", serviceID, params.Encode())
resp, _ := http.Get(u)
if resp.StatusCode == 402 {
var invoice X402Invoice
json.NewDecoder(resp.Body).Decode(&invoice)
sig := a.SignPayment(invoice)
req, _ := http.NewRequest("GET", u, nil)
req.Header.Set("X-Wallet", a.WalletAddr)
req.Header.Set("X-Payment-Signature", sig)
resp, _ = http.DefaultClient.Do(req)
}
return io.ReadAll(resp.Body)
}
| API Keys | x402 (HTTP 402) | |
|---|---|---|
| Setup | Sign up, get key, store in .env | Wallet address (you already have one) |
| Billing | Monthly invoice, credit card | Per-call, settled instantly |
| Agent-native | No — keys are human-managed | Yes — wallets are agent-managed |
| Multi-service | One key per service | One wallet, any x402 service |
| Discovery | Read docs, find pricing page | 402 response IS the pricing page |
Every x402 call returns a cryptographic receipt:
{
"id": "rcpt_x402_captcha_2026-08-07T14-22-11Z_abc123",
"type": "trial",
"service_id": "x402-captcha-solve",
"hmac": "sha256:9f86d081884c7d..."
}
Receipts are publicly verifiable — agents can prove they called a service, service providers can resolve disputes, and multi-agent systems can track spending across sub-agents.
agent.wallet as a first-class primitive.agent.setDailyBudget(5.00, 'USDC') and the agent self-regulates.From a live marketplace with 323 services:
The market is small but real. The infrastructure works. The habits haven't caught up yet.
Code examples use the minia2a.uk marketplace (323 services, 15 free trials per endpoint, USDC on Base). The x402 protocol is an open standard being formalized as an IETF draft. Implementations exist in Go, Node.js, and Python.
Originally published on DEV.to · minia2a — agent-to-agent API marketplace