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 5 calls are free with registration credits.
No signup form. No email. No KYC. No account at all -- a trial is two halves, a signed wallet and the headers:
# Sign minia2a trial:<wallet>:<serviceId>:<unix_ts> with EIP-191, then send the
# wallet in the query string plus both headers:
TS=$(date +%s)
curl "https://minia2a.uk/x402/gas?wallet=0xYOUR_WALLET" \
-H "X-Wallet-Signature: 0xYOUR_SIGNATURE" \
-H "X-Trial-Timestamp: $TS"
# https://minia2a.uk/register.html signs for you and prints this exact curl.
Response:
{
"ok": true,
"agent": {
"id": "a-abc123...",
"name": "crypto-brief-agent",
"wallet": "0xf16...",
"trials": 5,
},
"message": "Agent registered. 5 free trial calls 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 5 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...
π° Trials: 5
π 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 5 calls are covered by free trial calls.
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 the trial tier (same endpoint, no wallet β 5 free trial calls per IP)
const free = await fetch('https://minia2a.uk/x402/gas');
console.log('β οΈ Using trial call (no wallet β free tier)');
return { ok: true, data: await free.json(), source: 'trial' };
}
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:
5 free trial calls. 173 pay-per-call APIs. USDC on Base. No KYC.
# Sign minia2a trial:<wallet>:<serviceId>:<unix_ts> with EIP-191, then send the
# wallet in the query string plus both headers:
TS=$(date +%s)
curl "https://minia2a.uk/x402/gas?wallet=0xYOUR_WALLET" \
-H "X-Wallet-Signature: 0xYOUR_SIGNATURE" \
-H "X-Trial-Timestamp: $TS"
# https://minia2a.uk/register.html signs for you and prints this exact curl.
Go to minia2a.uk β