# x402engine > Pay-per-call API gateway for AI agents. 82 tools, sub-cent pricing, instant crypto payments. ## What is this? x402engine is an API gateway that provides 82 pay-per-call tools for AI agents using the HTTP 402 payment protocol. Every API call costs between $0.001 and $0.12, paid instantly with stablecoins (USDC on Base, USDC on Solana, or USDm on MegaETH). ## How to connect - MCP server (recommended): `npx -y x402engine-mcp` - Remote MCP endpoint: https://x402engine.app/mcp - REST API base: https://x402-gateway-production.up.railway.app - Discovery: https://x402-gateway-production.up.railway.app/.well-known/x402.json ## Agent cold start - Fetch `/.well-known/x402.json` first and use its `baseUrl` for API calls. - Optionally read `/api/services` or `/llms.txt` to pick a route. - Call the route without payment to receive `402 Payment Required`. - Read the `PAYMENT-REQUIRED` header, create one accepted payment proof, and retry with `X-PAYMENT`. - On success, read the JSON response and optional `PAYMENT-RESPONSE` settlement header. ## Available tools ### Image Generation - generate_image (fast): $0.015 — AI image generation, fast mode - generate_image (quality): $0.05 — AI image generation, quality mode - generate_image (text): $0.12 — AI image with embedded text - face_swap: $0.08 — identity-preserving face swap via FLUX PuLID; requires `reference_image_url` - generate_image (nano-banana): $0.10 — Google's Nano Banana 2, fast high-quality with aspect ratio control ### Code Execution - execute_code: $0.005 — Sandboxed code execution (Python, JS, Bash, R, Ruby, Go, Rust) ### Audio - transcribe_audio: $0.10 — Audio transcription (Deepgram Nova-3) - text_to_speech (OpenAI): $0.01 — Text-to-speech via OpenAI - text_to_speech (ElevenLabs): $0.02 — Text-to-speech via ElevenLabs - voice_clone_tts (Lux): $0.02 — Voice-cloning TTS at 48kHz; requires `audio_url` reference clip ### LLM Inference (50 models) - GPT-5.4: $0.10 | GPT-5.4 Pro: $0.30 | GPT-5.3 Codex: $0.08 - GPT-5.2 Pro: $0.25 | GPT-5.2: $0.08 | GPT-5.2 Codex: $0.06 | GPT-5.1: $0.035 | GPT-5 Nano: $0.002 - GPT-4o: $0.04 | GPT-4o Mini: $0.003 | o1: $0.03 | o4-mini: $0.03 - Claude Opus 4.7: $0.09 | Claude Opus 4.6: $0.09 | Claude Opus 4.5: $0.09 | Claude Sonnet 4.6: $0.06 | Claude Sonnet 4.5: $0.06 | Claude Haiku 4.5: $0.02 - Gemini 3.1 Pro: $0.05 | Gemini 3.1 Flash Lite: $0.003 | Gemini 3 Pro: $0.045 | Gemini 3 Flash: $0.012 | Gemini 2.5 Pro: $0.035 | Gemini 2.5 Flash: $0.009 | Gemma 4 31B: $0.003 - DeepSeek V3.2 Speciale: $0.008 | DeepSeek V3.2: $0.005 | DeepSeek V3: $0.005 | DeepSeek R1: $0.01 - Grok 4.20: $0.06 | Grok 4: $0.06 | Grok 4 Fast: $0.004 | Grok Code Fast: $0.04 - Qwen 3.6 Plus: $0.008 | Qwen 3.5: $0.006 | Qwen3 235B: $0.004 | Qwen3 Coder: $0.004 - Llama 4 Maverick: $0.003 | Llama 3.3 70B: $0.002 - Mistral Large 3: $0.006 | Devstral 2: $0.02 | Perplexity Sonar Pro: $0.06 | Cohere Command A: $0.04 - Kimi K2.6: $0.03 | Kimi K2.5: $0.03 | MiniMax M2.7: $0.01 | MiniMax M2.5: $0.01 | GLM-5.1: $0.03 | GLM-5: $0.03 | Seed 1.6: $0.02 - Text Embeddings: $0.001 ### Crypto & Market Data - get_crypto_price: $0.001 — Real-time crypto prices - get_crypto_markets: $0.002 — Top coins by market cap - get_crypto_history: $0.003 — Historical price charts - get_trending_crypto: $0.001 — Trending coins - search_crypto: $0.001 — Search for coins ### Blockchain & Wallet Analytics - get_wallet_balances: $0.005 — Token balances for any wallet - get_wallet_transactions: $0.005 — Transaction history - get_wallet_pnl: $0.01 — Realized & unrealized profit/loss per token - get_token_prices: $0.005 — DEX-derived token prices - get_token_metadata: $0.002 — Token metadata ### ENS - resolve_ens: $0.001 — ENS name to address - reverse_ens: $0.001 — Address to ENS name ### IPFS Storage - pin_to_ipfs: $0.01 — Pin JSON to IPFS - get_from_ipfs: $0.001 — Retrieve content from IPFS ### Web - web_scrape: $0.005 — Scrape and extract web page content - web_screenshot: $0.01 — Capture web page screenshot - web_search: $0.01 — Neural web search with highlighted snippets (Exa) - web_content_fetch: $0.005 — Fetch full text content from up to 10 URLs (Exa) ### Travel - search_flights: $0.02 — Search flights via Google Flights (best flights, prices, airlines, price insights) - search_hotels: $0.02 — Search hotels via Google Hotels (properties, ratings, amenities, prices) ### Transaction - simulate_transaction: $0.01 — Simulate EVM transactions ## Payment All payments use the x402 HTTP payment protocol. When you call an endpoint without payment, it returns HTTP 402 with payment requirements in the response header. Pay with: - USDC on Base (EVM, ~2s confirmation) — uses @x402/evm SDK, automatic Permit2 signatures - USDC on Solana (~400ms confirmation) — uses @x402/svm SDK, automatic - USDm on MegaETH (EVM, ~10ms confirmation) — requires custom scheme (see below) ### Base payment (recommended, simplest) **Important:** You must use `registerExactEvmScheme` from `@x402/evm/exact/client` — this produces a Permit2 signature that the facilitator verifies. Sending a raw ERC-20 transfer tx hash will NOT work. ```js import { wrapFetchWithPayment, x402Client } from '@x402/fetch'; import { registerExactEvmScheme } from '@x402/evm/exact/client'; import { privateKeyToAccount } from 'viem/accounts'; const account = privateKeyToAccount(PRIVATE_KEY); const client = new x402Client(); registerExactEvmScheme(client, { signer: account, networks: ['eip155:8453'] }); const paidFetch = wrapFetchWithPayment(fetch, client, { paymentRequirementsSelector: (accepts) => accepts.find(a => a.network === 'eip155:8453'), }); const res = await paidFetch('https://x402-gateway-production.up.railway.app/api/crypto/price?ids=bitcoin'); ``` ### Solana payment ```js import { x402Client, wrapFetchWithPayment } from '@x402/fetch'; import { ExactSvmScheme } from '@x402/svm'; // v2.2.0 import { createKeyPairSignerFromBytes } from '@solana/kit'; const signer = await createKeyPairSignerFromBytes(keypairBytes); const scheme = new ExactSvmScheme(signer); const client = new x402Client().register('solana:*', scheme); const paidFetch = wrapFetchWithPayment(fetch, client); ``` ### MegaETH payment (~10ms, cheapest gas) The @x402/evm SDK doesn't support MegaETH natively. Use this custom scheme with `wrapFetchWithPaymentFromConfig`: ```js import { wrapFetchWithPaymentFromConfig } from '@x402/fetch'; import { privateKeyToAccount } from 'viem/accounts'; import { createWalletClient, createPublicClient, http, getAddress, parseGwei } from 'viem'; const megaethChain = { id: 4326, name: 'MegaETH', nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, rpcUrls: { default: { http: ['https://mainnet.megaeth.com/rpc'] } }, }; const erc20TransferAbi = [{ type: 'function', name: 'transfer', stateMutability: 'nonpayable', inputs: [{ name: 'to', type: 'address' }, { name: 'value', type: 'uint256' }], outputs: [{ name: '', type: 'bool' }], }]; // Custom scheme: sends USDm transfer, returns txHash class MegaethScheme { constructor(wc, pc) { this.scheme = 'exact'; this.wc = wc; this.pc = pc; this.nonce = null; this.queue = Promise.resolve(); } createPaymentPayload(x402Version, req) { const run = async () => { const to = getAddress(req.payTo); const token = getAddress(req.asset); const value = BigInt(req.amount); if (this.nonce === null) this.nonce = await this.pc.getTransactionCount({ address: this.wc.account.address }); try { const txHash = await this.wc.writeContract({ address: token, abi: erc20TransferAbi, functionName: 'transfer', args: [to, value], nonce: this.nonce, maxFeePerGas: parseGwei('0.001'), maxPriorityFeePerGas: 0n, gas: 200_000n, chain: megaethChain, account: this.wc.account, }); await this.pc.waitForTransactionReceipt({ hash: txHash, timeout: 5000 }); this.nonce++; return { x402Version, payload: { txHash } }; } catch (e) { this.nonce = null; throw e; } }; const p = this.queue.then(run); this.queue = p.catch(() => {}); return p; } } const account = privateKeyToAccount(PRIVATE_KEY); const transport = http('https://mainnet.megaeth.com/rpc'); const scheme = new MegaethScheme( createWalletClient({ account, chain: megaethChain, transport }), createPublicClient({ chain: megaethChain, transport }), ); const paidFetch = wrapFetchWithPaymentFromConfig(fetch, { schemes: [{ network: 'eip155:4326', client: scheme }], }); const res = await paidFetch('https://x402-gateway-production.up.railway.app/api/crypto/price?ids=bitcoin'); ``` Key: USDm is 18 decimals (not 6). $0.001 = 1000000000000000 (10^15). Wallet needs USDm + tiny ETH for gas. ## Links - GitHub: https://github.com/agentc22/x402engine-mcp - npm: https://www.npmjs.com/package/x402engine-mcp - Protocol: https://x402.org