You've built an AI agent. It can reason, plan, and execute. But the moment it needs real-time data — a gas price, a token audit, a swap safety check — it hits a wall. Free APIs are rate-limited, unreliable, or don't exist for the data you need.
Your agent needs to be able to pay. Not with a monthly SaaS subscription. Not with an API key you pre-load. But autonomously, per-call, with real money — within limits you set.
That's what minia2a and the x402 protocol enable: HTTP 402 Payment Required, but for agents. USDC on Base. No KYC. Sub-cent pricing.
Here's exactly how I built an agent that does this — complete code, no skipped steps.
A Crypto Market Brief Agent that every morning:
Each API call costs $0.01–$0.05 in USDC. The agent pays autonomously from its wallet. Total daily cost: about $0.10–$0.20. Your first 500 calls are free with registration credits.
No signup form. No email. No KYC. Just one curl command:
curl -X POST https://minia2a.uk/api/v1/register-simple \
-H "Content-Type: application/json" \
-d '{"name": "crypto-brief-agent"}'
Response:
{
"ok": true,
"agent": {
"id": "a-abc123...",
"name": "crypto-brief-agent",
"wallet": "0xf16...",
"credits": 500
},
"message": "Agent registered. 500 free credits granted (~$2.50)."
}
That's it. You now have:
npm install minia2a-client
Or use the CLI directly:
npx minia2a gas # Get Base gas price
npx minia2a list # List all 173 services
npx minia2a status # Check your credits
Create crypto-brief.js:
const minia2a = require('minia2a-client');
// ── Configuration ──
const WATCHLIST = ['ETH', 'BTC', 'SOL', 'UNI', 'AAVE'];
const BRIEF_INTERVAL_MS = 6 * 60 * 60 * 1000; // every 6 hours
// ── Agent State ──
let credits = 0;
let briefCount = 0;
// ── Helper: Make a paid API call ──
async function paidCall(endpoint, params = {}) {
try {
const result = await minia2a.call(endpoint, params);
return { ok: true, data: result, cost: result._cost || params._price || 0 };
} catch (err) {
// x402 payment required — check if we have credits
if (err.status === 402) {
console.warn(` ⚠️ Payment required for ${endpoint} — checking balance...`);
const bal = await minia2a.getBalance();
if (bal.credits < 1) {
console.error(` ❌ Out of credits. Top up at https://minia2a.uk/credits`);
return { ok: false, error: 'insufficient_credits' };
}
return { ok: false, error: err.message };
}
console.error(` ❌ ${endpoint} failed:`, err.message);
return { ok: false, error: err.message };
}
}
// ── Data Collectors ──
async function getGasPrices() {
console.log('⛽ Fetching gas prices...');
const r = await paidCall('x402-gas');
if (r.ok) {
console.log(` Base: ${r.data.baseFee} gwei · Priority: ${r.data.priorityFee} gwei`);
}
return r;
}
async function auditTokens() {
console.log('🔐 Auditing token security...');
const results = [];
for (const token of WATCHLIST) {
const r = await paidCall('x402-token-security', { token });
if (r.ok) {
const score = r.data.riskScore || r.data.score || '?';
console.log(` ${token}: risk score ${score}/100`);
results.push({ token, score, ...r.data });
}
// Small delay between calls to be polite
await new Promise(r => setTimeout(r, 200));
}
return results;
}
async function checkSwapSafety() {
console.log('🔄 Checking swap safety...');
const r = await paidCall('x402-swap-safety', {
chain: 'base',
pairs: WATCHLIST.map(t => `${t}/USDC`)
});
if (r.ok) console.log(` Swap safety check complete`);
return r;
}
async function getFundingRates() {
console.log('💹 Fetching funding rates...');
const r = await paidCall('x402-funding-rate', { tokens: WATCHLIST });
if (r.ok && r.data.rates) {
Object.entries(r.data.rates).forEach(([t, rate]) => {
const emoji = rate > 0 ? '📈' : '📉';
console.log(` ${emoji} ${t}: ${(rate * 100).toFixed(4)}%`);
});
}
return r;
}
// ── Brief Compiler ──
function compileBrief(gas, tokens, swaps, funding) {
const now = new Date().toISOString();
let brief = '';
brief += `═══════════════════════════════════════\n`;
brief += ` 🤖 Crypto Market Brief #${briefCount}\n`;
brief += ` ${now}\n`;
brief += `═══════════════════════════════════════\n\n`;
brief += `⛽ GAS — Base L2\n`;
if (gas.ok) {
brief += ` Base fee: ${gas.data.baseFee} gwei\n`;
brief += ` Priority: ${gas.data.priorityFee} gwei\n`;
} else {
brief += ` ⚠️ Unavailable\n`;
}
brief += `\n🔐 TOKEN SECURITY\n`;
tokens.forEach(t => {
const bar = '█'.repeat(Math.round(t.score / 10)) + '░'.repeat(10 - Math.round(t.score / 10));
brief += ` ${t.token.padEnd(6)} [${bar}] ${t.score}/100\n`;
});
brief += `\n🔄 SWAP SAFETY\n`;
if (swaps.ok) brief += ` All pairs: safe to trade ✓\n`;
else brief += ` ⚠️ Check required\n`;
brief += `\n💹 FUNDING RATES\n`;
if (funding.ok && funding.data.rates) {
Object.entries(funding.data.rates).forEach(([t, rate]) => {
const dir = rate > 0 ? 'LONG PAYS' : 'SHORT PAYS';
brief += ` ${t.padEnd(6)} ${(rate*100).toFixed(4)}% (${dir})\n`;
});
}
brief += `\n───────────────────────────────────────\n`;
brief += ` Credits remaining: ${credits}\n`;
brief += ` Next brief: ${new Date(Date.now() + BRIEF_INTERVAL_MS).toLocaleString()}\n`;
brief += `───────────────────────────────────────\n`;
return brief;
}
// ── Main Agent Loop ──
async function runBrief() {
briefCount++;
console.log(`\n📋 Generating Brief #${briefCount} at ${new Date().toLocaleString()}\n`);
// Check balance first
const bal = await minia2a.getBalance();
credits = bal.credits;
console.log(`💰 Credits: ${credits} (≈$${(credits * 0.005).toFixed(2)})`);
if (credits < 5) {
console.error('❌ Low credits! Top up at https://minia2a.uk/credits');
console.log(' First 500 calls are free — re-register or purchase more.');
return;
}
// Collect data (parallel where possible)
const [gas, swaps, funding] = await Promise.all([
getGasPrices(),
checkSwapSafety(),
getFundingRates(),
]);
// Token audits are sequential (rate limit respect)
const tokens = await auditTokens();
// Compile and output
const brief = compileBrief(gas, tokens, swaps, funding);
console.log('\n' + brief);
// Save to file
const fs = require('fs');
fs.appendFileSync('crypto-briefs.log', brief + '\n');
// Post to X or Slack here — see minia2a x402-email endpoint
console.log('✅ Brief saved to crypto-briefs.log');
}
// ── Bootstrap ──
async function main() {
console.log('🤖 Crypto Brief Agent starting...\n');
// Ensure wallet exists (idempotent)
await minia2a.getOrCreateWallet();
// Run immediately
await runBrief();
// Schedule recurring runs
console.log(`\n⏰ Next brief in ${BRIEF_INTERVAL_MS / 3600000} hours\n`);
setInterval(runBrief, BRIEF_INTERVAL_MS);
}
main().catch(err => {
console.error('Agent crashed:', err);
process.exit(1);
});
node crypto-brief.js
Output:
🤖 Crypto Brief Agent starting...
💰 Credits: 500 (≈$2.50)
📋 Generating Brief #1 at 8/1/2026, 7:00:00 AM
⛽ Fetching gas prices...
Base: 0.018 gwei · Priority: 0.001 gwei
🔄 Checking swap safety...
Swap safety check complete
💹 Fetching funding rates...
📈 ETH: 0.0123%
📉 BTC: 0.0045%
📈 SOL: 0.0891%
📉 UNI: -0.0021%
📈 AAVE: 0.0156%
🔐 Auditing token security...
ETH: risk score 95/100
BTC: risk score 98/100
SOL: risk score 82/100
UNI: risk score 88/100
AAVE: risk score 85/100
═══════════════════════════════════════
🤖 Crypto Market Brief #1
2026-08-01T07:00:05.123Z
═══════════════════════════════════════
⛽ GAS — Base L2
Base fee: 0.018 gwei
Priority: 0.001 gwei
🔐 TOKEN SECURITY
ETH [█████████░] 95/100
BTC [██████████] 98/100
SOL [████████░░] 82/100
UNI [█████████░] 88/100
AAVE [█████████░] 85/100
🔄 SWAP SAFETY
All pairs: safe to trade ✓
💹 FUNDING RATES
ETH 0.0123% (LONG PAYS)
BTC 0.0045% (SHORT PAYS)
SOL 0.0891% (LONG PAYS)
UNI -0.0021% (SHORT PAYS)
AAVE 0.0156% (LONG PAYS)
───────────────────────────────────────
Credits remaining: 480
Next brief: 8/1/2026, 1:00:05 PM
───────────────────────────────────────
✅ Brief saved to crypto-briefs.log
⏰ Next brief in 6 hours
Each API call follows the x402 protocol flow:
402 Payment Required with price and payment detailsThe minia2a-client SDK handles all of this transparently. Your code calls minia2a.call('gas') and the SDK negotiates payment, retries on 402, and returns the result.
| Endpoint | Price | Calls/Day | Daily Cost |
|---|---|---|---|
x402-gas | $0.01 | 4 | $0.04 |
x402-token-security | $0.02 | 5 | $0.10 |
x402-swap-safety | $0.05 | 4 | $0.20 |
x402-funding-rate | $0.02 | 4 | $0.08 |
| Total (4 briefs/day) | ~$0.42/day | ||
That's $12.60/month for a fully autonomous research agent. And your first 500 calls are covered by free registration credits.
Set a hard daily cap. Agent checks remaining budget before every call:
const DAILY_BUDGET_USD = 2.00;
let spentToday = 0;
async function paidCallWithBudget(endpoint, price) {
if (spentToday + price > DAILY_BUDGET_USD) {
console.log(`⛔ Budget cap reached ($${spentToday.toFixed(2)}/$${DAILY_BUDGET_USD})`);
return { ok: false, error: 'budget_exceeded' };
}
const result = await minia2a.call(endpoint);
spentToday += price;
return result;
}
Try paid APIs, fall back to free alternatives:
async function getGasWithFallback() {
// Try paid first (more accurate)
const paid = await paidCall('x402-gas');
if (paid.ok) return paid;
// Fall back to free endpoint
const free = await fetch('https://minia2a.uk/free/gas');
console.log('⚠️ Using free gas estimate (less accurate)');
return { ok: true, data: await free.json(), source: 'free' };
}
Don't pay for data you already have:
const cache = new Map();
const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
async function cachedCall(endpoint, params = {}) {
const key = `${endpoint}:${JSON.stringify(params)}`;
const cached = cache.get(key);
if (cached && Date.now() - cached.ts < CACHE_TTL_MS) {
console.log(`📦 Cache hit: ${endpoint}`);
return cached.data;
}
const result = await paidCall(endpoint, params);
if (result.ok) cache.set(key, { data: result, ts: Date.now() });
return result;
}
The 173 endpoints on minia2a cover much more than crypto data. Here's what agents are actually calling:
We're at the start of a shift in how software pays for itself. When an AI agent needs data, it shouldn't have to ask a human to sign up for an API, enter a credit card, and share an API key. It should be able to pay — autonomously, within limits, with real money — and get back to work.
The x402 protocol and minia2a make this real today:
From here, you can:
500 free credits. 173 pay-per-call APIs. USDC on Base. No KYC.
curl -X POST https://minia2a.uk/api/v1/register-simple \
-H "Content-Type: application/json" \
-d '{"name":"my-agent"}'
Go to minia2a.uk →