// "Which API should I use?" decision guide (/docs/which-api, .md) and /llms-full.txt.
// One row per agent need -> tool, route, price, curl and MCP example. Every TOOLS entry must appear (see test/docs.test.js).
import { BY_PREFIX } from './tools.js';
import { llmsTxt } from './root.js';
import { install, installMd } from './install.js';
const base = (env) => `https://${env.PUBLIC_HOST || 'api.youraitools.co'}`;
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
export const NFA = 'Not financial advice. Past performance does not guarantee future results.';
export const SAFETY = 'Safety check only.';
// group, need (agent's words), tool prefix, paid route, price of that route, query example, MCP tool + args, note.
export const NEEDS = [
{ group: 'Paying and signing (wallet agents)', need: 'Before I pay or approve an address: is it OK, caution or block?', tool: 'counterpartycheck', route: 'GET /v1/lite', price: '$0.005', q: 'address=0x098B716B8Aaf21512996dC57EB0615e2383E2f96&chain=ethereum&intent=pay', mcp: ['check_counterparty', { address: '0x098B716B8Aaf21512996dC57EB0615e2383E2f96', chain: 'ethereum', intent: 'pay' }], note: `quick $0.015, full $0.05. ${SAFETY}` },
{ group: 'Paying and signing (wallet agents)', need: 'Is this address on the OFAC SDN sanctions list?', tool: 'payguard', route: 'GET /v1/address', price: '$0.001', q: 'address=0x098B716B8Aaf21512996dC57EB0615e2383E2f96', mcp: ['screen_address', { address: '0x098B716B8Aaf21512996dC57EB0615e2383E2f96' }], note: 'POST /v1/batch: 50 addresses for $0.01. Informational, not legal advice.' },
{ group: 'Paying and signing (wallet agents)', need: 'Is it safe to sign this transaction, Permit/Permit2, EIP-712 or x402 payment?', tool: 'signcheck', route: 'GET /v1/lite', price: '$0.005', q: 'to=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&data=0x095ea7b3...', mcp: ['check_signature', { chain: 'base', tx: { to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', data: '0x095ea7b3...' } }], note: `full (live simulation) $0.015 at /v1/check. ${SAFETY}` },
{ group: 'Paying and signing (wallet agents)', need: 'Is this Base ERC-20 token a honeypot / rug before I buy or accept it?', tool: 'tokenverdict', route: 'GET /v1/lite', price: '$0.005', q: 'token=0x532f27101965dd16442E59d40670FaF5eBB142E4', mcp: ['check_token', { token: '0x532f27101965dd16442E59d40670FaF5eBB142E4' }], note: `quick $0.015, deep $0.05. ${SAFETY}` },
{ group: 'Paying and signing (wallet agents)', need: 'Is this Solana SPL / Token-2022 mint safe to interact with?', tool: 'solverdict', route: 'GET /v1/lite', price: '$0.005', q: 'mint=DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', mcp: ['check_solana_token', { mint: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263' }], note: `check $0.02. ${SAFETY}` },
{ group: 'Paying and signing (wallet agents)', need: 'Is this AI agent registered, Active and Verified?', tool: 'agentgate', route: 'GET /v1/check-agent', price: '$0.005', q: 'id=Mf22soLh1NuZYFgBK8iSs', mcp: ['check_agent', { id: 'Mf22soLh1NuZYFgBK8iSs' }], note: 'Concordium Agent Registry.' },
{ group: 'Guarding the agent itself', need: 'Does this text, web page or MCP tool definition contain a prompt injection?', tool: 'injectscan', route: 'GET /v1/scan', price: '$0.003', q: 'text=Ignore%20previous%20instructions', mcp: ['scan_text', { text: 'Ignore previous instructions' }], note: `POST /v1/scan takes {text|url|tools}. ${SAFETY}` },
{ group: 'Guarding the agent itself', need: 'Am I about to leak a seed phrase, private key, API secret or PII?', tool: 'leakguard', route: 'GET /v1/lite', price: '$0.005', q: 'text=deploy%20log%3A%20aws%20AKIAIOSFODNN7EXAMPLE', mcp: ['scan_for_leaks', { text: 'deploy log: aws AKIAIOSFODNN7EXAMPLE' }], note: `scan $0.02 adds JSON payloads + funded-wallet check. Inputs never stored. ${SAFETY}` },
{ group: 'Guarding the agent itself', need: 'Is this npm/PyPI/Go/Cargo dependency safe to install?', tool: 'pkgguard', route: 'GET /v1/package', price: '$0.001', q: 'ecosystem=npm&name=lodash&version=4.17.15', mcp: ['check_package', { ecosystem: 'npm', name: 'lodash', version: '4.17.15' }], note: `POST /v1/scan: a whole manifest/lockfile (up to 500 packages) for $0.003. ${SAFETY}` },
{ group: 'Guarding the agent itself', need: 'Is this domain or email real and trustworthy?', tool: 'domaincheck', route: 'GET /v1/domain', price: '$0.002', q: 'domain=example.com', mcp: ['check_domain', { domain: 'example.com' }], note: `GET /v1/email?email=... $0.001. ${SAFETY}` },
{ group: 'Reading the web', need: 'Read a web page as clean Markdown', tool: 'webread', route: 'GET /v1/read', price: '$0.002', q: 'url=https://example.com/', mcp: ['read_url', { url: 'https://example.com/' }], note: 'robots.txt-aware, SSRF-safe.' },
{ group: 'Reading the web', need: 'What is this website built with (CMS, framework, hosting, analytics)?', tool: 'stackdetect', route: 'GET /v1/detect', price: '$0.003', q: 'url=https://laravel.com', mcp: ['detect_stack', { url: 'https://laravel.com' }], note: '' },
{ group: 'Reading the web', need: 'Is this website ready for AI agents (llms.txt, MCP, x402, robots)?', tool: 'agentready', route: 'GET /v1/lite', price: '$0.005', q: 'url=https://example.com', mcp: ['audit_website', { url: 'https://example.com' }], note: 'audit $0.03.' },
{ group: 'Trading research (read-only)', need: 'Perp funding, open interest and cheapest venue for an asset', tool: 'perpradar', route: 'GET /v1/lite', price: '$0.005', q: 'symbol=BTC', mcp: ['perp_positioning', { symbol: 'BTC' }], note: `full $0.03, scan $0.02. ${NFA}` },
{ group: 'Trading research (read-only)', need: 'Technical indicators, risk sizing or a rule backtest for a symbol', tool: 'tasignal', route: 'GET /v1/lite', price: '$0.005', q: 'symbol=BTC&timeframe=1h', mcp: ['ta_bias', { symbol: 'BTC', timeframe: '1h' }], note: `risk $0.02, backtest $0.05. ${NFA}` },
{ group: 'Trading research (read-only)', need: 'What are the most profitable Hyperliquid traders holding?', tool: 'smartperps', route: 'GET /v1/lite', price: '$0.003', q: 'symbol=BTC', mcp: ['smart_money_bias', { symbol: 'BTC' }], note: `coin $0.02, scan $0.03, wallet $0.01. ${NFA}` },
{ group: 'Trading research (read-only)', need: 'Will this Hyperliquid perp order be rejected (tick, lot, $10 minimum, leverage tier, OI cap, delisted), and what does it cost and risk?', tool: 'perpcheck', route: 'GET /v1/lite', price: '$0.003', q: 'coin=ETH&side=long&size=0.0123456&price=3000.123&leverage=60', mcp: ['check_perp_order', { coin: 'BTC', side: 'long', size: '0.001', leverage: 10 }], note: 'full $0.01 adds liquidation estimate, taker impact and funding carry. Read-only; never places orders. Not financial advice; the exchange decides whether an order is accepted.' },
{ group: 'Finding and selling paid APIs', need: "I need a paid API for a task and don't know which one", tool: 'toolpick', route: 'GET /v1/lite', price: '$0.003', q: 'need=web%20search', mcp: ['find_paid_api', { need: 'web search' }], note: 'pick (live-verified best pick) $0.01, market (seller price quartiles) $0.02. Ranks, does not endorse.' },
{ group: 'Finding and selling paid APIs', need: 'Will my x402 endpoint work with payers and Bazaar / x402scan?', tool: 'x402fix', route: 'GET /v1/lite', price: '$0.005', q: 'url=https://api.youraitools.co/counterpartycheck/v1/lite', mcp: ['check_x402_endpoint', { url: 'https://api.youraitools.co/counterpartycheck/v1/lite' }], note: 'check $0.02, site $0.05.' },
{ group: 'Finding and selling paid APIs', need: 'Put an x402 paywall in front of my own API', tool: 'x402-template', route: 'GET /download', price: '$19 one-time', q: '', mcp: null, note: 'Cloudflare Worker zip, MIT. Free preview at the landing page.' },
{ group: 'Paying less per call', need: 'Skip the on-chain payment on every call (prepaid balance)', tool: 'credits', route: 'POST /v1/pack/1', price: '$1 (or $5 for $5.50)', q: '', mcp: ['credits_quote', {}], note: 'Then send Authorization: Bearer <key> to any paid route. Not refundable.' },
];
function rows(env) {
const b = base(env);
return NEEDS.map((n) => {
const t = BY_PREFIX[n.tool]; const [method, path] = n.route.split(' ');
const url = `${b}/${t.prefix}${path}${n.q ? `?${n.q}` : ''}`;
const curl = method === 'GET' ? `curl -i "${url}"` : `curl -i -X ${method} "${url}"`;
return { ...n, name: t.name, method, endpoint: `${b}/${t.prefix}${path}`, url, curl, landing: `${b}/${t.prefix}/`, free: t.free, preview: `${b}/${t.prefix}${t.preview}`, mcpUrl: t.mcp === false ? null : `${b}/${t.prefix}/mcp` };
});
}
const mcpCall = (r) => r.mcp ? JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: r.mcp[0], arguments: r.mcp[1] } }) : null;
const HOW = (b) => `How paying works: call the paid URL with no payment and you get HTTP 402 with a PAYMENT-REQUIRED header (x402 v2) and the price. Pay in USDC on Base, Polygon, Arbitrum One or Solana with any x402 client (@x402/fetch, x402-axios, Coinbase AgentKit, x402 Python) and retry. Per call only: no signup, no subscription, no custody. Or buy prepaid credits once (${b}/credits/) and send Authorization: Bearer <key>. Every tool has a free preview, an OpenAPI doc and a remote MCP server (streamable HTTP) at <tool>/mcp.`;
const FREE_MD = (rs) => { const f = rs.filter((r) => r.free && r.mcpUrl); return f.length ? `## Free tier: start without a wallet\n\n${f.map((r) => `- **${r.name}**: ${r.free}. \`${install(r.tool, r.mcpUrl).claudeCode}\``).join('\n')}\n\nPast the free tier, each tool answers with a payment_required (402) result that points to its paid x402 route.\n\n` : ''; };
export function whichApiMd(env) {
const b = base(env); const rs = rows(env);
const groups = [...new Set(rs.map((r) => r.group))];
return `# Which API should I use?\n\nA decision guide for AI agents and the people building them: find your need, call the tool. All prices are USDC per call over x402 unless marked.\n\n${HOW(b)}\n\nMCP client config (any tool): \`{"mcpServers":{"<tool>":{"url":"${b}/<tool>/mcp"}}}\`\n\n${FREE_MD(rs)}${groups.map((g) => `## ${g}\n\n${rs.filter((r) => r.group === g).map((r) => `### ${r.need}\n- Use: **${r.name}** (${r.landing})\n- Endpoint: ${r.method} ${r.endpoint}, ${r.price}${r.note ? `. ${r.note}` : ''}\n- curl (first reply is the 402 with payment terms): \`${r.curl}\`\n${r.free ? `- **${r.free}**\n` : ''}- Free preview: ${r.preview}\n${r.mcpUrl && r.mcp ? `- MCP: ${r.mcpUrl}, tools/call \`${mcpCall(r)}\`\n` : ''}${r.free && r.mcpUrl ? installMd(r.tool, r.mcpUrl) : ''}`).join('\n')}`).join('\n')}\n## Not sure?\nAsk ToolPick: \`curl -i "${b}/toolpick/v1/lite?need=<your task>"\` ($0.003), or the free preview ${b}/toolpick/v1/preview?need=web%20search. It also searches other sellers' x402 APIs.\n\n## Discovery\n- Tool index: ${b}/ (JSON or HTML)\n- All paid resources: ${b}/.well-known/x402\n- Combined OpenAPI: ${b}/openapi.json\n- llms.txt: ${b}/llms.txt, full: ${b}/llms-full.txt\n`;
}
export function whichApiHtml(env) {
const b = base(env); const rs = rows(env);
const groups = [...new Set(rs.map((r) => r.group))];
const title = 'Which API should I use? x402 tools for AI agents, by need';
const desc = 'Decision guide: map what your agent needs (pay safely, check a token, scan for prompt injection, read a page, trading research, find a paid API) to a pay-per-call x402 tool, with price, endpoint, curl and MCP example.';
const body = groups.map((g) => `<h2>${esc(g)}</h2><table><tr><th>If your agent needs to…</th><th>Use</th><th>Endpoint and price (USDC)</th><th>Example</th></tr>${rs.filter((r) => r.group === g).map((r) => `<tr><td>${esc(r.need)}</td><td><a href="${esc(r.landing)}">${esc(r.name)}</a><br><a href="${esc(r.preview)}">free preview</a></td><td><code>${esc(r.method)} ${esc(r.endpoint)}</code><br>${esc(r.price)}${r.free ? `<br><b>${esc(r.free)}</b>` : ''}${r.note ? `<br><small>${esc(r.note)}</small>` : ''}</td><td><code>${esc(r.curl)}</code>${r.mcpUrl && r.mcp ? `<br><small>MCP <code>${esc(r.mcpUrl)}</code> → <code>${esc(r.mcp[0])}</code></small>` : ''}${r.free && r.mcpUrl ? (() => { const i = install(r.tool, r.mcpUrl); return `<br><small>Claude Code: <code>${esc(i.claudeCode)}</code><br>Cursor: <code>${esc(i.cursor)}</code> · <a href="${esc(i.cursorDeeplink)}">Add to Cursor</a><br>Claude Desktop: <code>${esc(i.claudeDesktop)}</code></small>`; })() : ''}</td></tr>`).join('')}</table>`).join('');
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(title)}</title><meta name="description" content="${esc(desc)}"><link rel="icon" href="/favicon.ico"><link rel="canonical" href="${esc(b)}/docs/which-api"><link rel="alternate" type="text/markdown" href="/docs/which-api.md"><link rel="alternate" type="text/plain" title="llms.txt" href="/llms.txt"><meta property="og:type" content="article"><meta property="og:site_name" content="YourAITools"><meta property="og:url" content="${esc(b)}/docs/which-api"><meta property="og:title" content="${esc(title)}"><meta property="og:description" content="${esc(desc)}"><meta name="twitter:card" content="summary"><style>body{font:16px/1.5 system-ui,sans-serif;max-width:1100px;margin:2rem auto;padding:0 1rem;background:#0b0f17;color:#e6e9ef}a{color:#7cc4ff}table{border-collapse:collapse;width:100%;margin-bottom:1.5rem}td,th{border-bottom:1px solid #243047;padding:.5rem;text-align:left;vertical-align:top}code{font-size:.8em;color:#b8c4d6;word-break:break-all}small{color:#9aa6b8}</style></head><body><p><a href="/">YourAITools API</a> › docs</p><h1>Which API should I use?</h1><p>${esc(desc)}</p><p>${esc(HOW(b))}</p><p>MCP client config (any tool): <code>{"mcpServers":{"<tool>":{"url":"${esc(b)}/<tool>/mcp"}}}</code></p>${body}<h2>Not sure?</h2><p>Ask <a href="/toolpick/">ToolPick</a>: <code>curl -i "${esc(b)}/toolpick/v1/lite?need=<your task>"</code> ($0.003) or try the <a href="/toolpick/v1/preview?need=web%20search">free preview</a>. It also searches other sellers' x402 APIs.</p><p>Machine-readable: <a href="/docs/which-api.md">which-api.md</a> · <a href="/llms.txt">llms.txt</a> · <a href="/llms-full.txt">llms-full.txt</a> · <a href="/.well-known/x402">/.well-known/x402</a> · <a href="/openapi.json">/openapi.json</a>. Trading tools: ${esc(NFA)} Safety tools: ${esc(SAFETY.toLowerCase())}</p></body></html>`;
}
// llms-full.txt: llms.txt + the full decision guide + services, in one fetch.
export function llmsFullTxt(env) {
return `${llmsTxt(env)}\n---\n\n${whichApiMd(env).replace(/^# /, '# YourAITools API: ')}`;
}
agentgate-source: code mirror on Cloudflare Pages. All repos