# 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 - Discovery alias: https://x402engine.app/.well-known/x402 - Agent card: https://x402engine.app/.well-known/agent-card.json - OpenAPI: https://x402engine.app/openapi.json ## 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-4o: $0.04 — `/api/llm/gpt-4o` - GPT-4o Mini: $0.003 — `/api/llm/gpt-4o-mini` - OpenAI o1: $0.03 — `/api/llm/o1` - Claude Opus 4.6: $0.09 — `/api/llm/claude-opus` - Claude Sonnet 4.5: $0.06 — `/api/llm/claude-sonnet` - Claude Haiku 4.5: $0.02 — `/api/llm/claude-haiku` - Gemini 2.5 Pro: $0.035 — `/api/llm/gemini-pro` - Gemini 2.5 Flash: $0.009 — `/api/llm/gemini-flash` - DeepSeek V3: $0.005 — `/api/llm/deepseek` - DeepSeek R1: $0.01 — `/api/llm/deepseek-r1` - Llama 3.3 70B: $0.002 — `/api/llm/llama` - Grok 4.3: $0.06 — `/api/llm/grok` - Qwen3 235B: $0.004 — `/api/llm/qwen` - Mistral Large 3: $0.006 — `/api/llm/mistral` - Perplexity Sonar Pro: $0.06 — `/api/llm/perplexity` - GPT-5.2: $0.08 — `/api/llm/gpt-5.2` - GPT-5.2 Codex: $0.06 — `/api/llm/gpt-5.2-codex` - Kimi K2.5: $0.03 — `/api/llm/kimi` - MiniMax M2.5: $0.01 — `/api/llm/minimax` - GLM-5: $0.03 — `/api/llm/glm` - Grok Build 0.1: $0.04 — `/api/llm/grok-code` - Seed 1.6: $0.02 — `/api/llm/seed` - Devstral 2: $0.02 — `/api/llm/devstral` - DeepSeek V3.2: $0.005 — `/api/llm/deepseek-v3.2` - Gemini 3.1 Pro: $0.045 — `/api/llm/gemini-3-pro` - Gemini 3 Flash: $0.012 — `/api/llm/gemini-3-flash` - Claude Sonnet 4.6: $0.06 — `/api/llm/claude-sonnet-4.6` - GPT-5.2 Pro: $0.25 — `/api/llm/gpt-5.2-pro` - Qwen3 Coder: $0.004 — `/api/llm/qwen-coder` - GPT-5.1: $0.035 — `/api/llm/gpt-5.1` - GPT-5.4: $0.10 — `/api/llm/gpt-5.4` - GPT-5.4 Pro: $0.30 — `/api/llm/gpt-5.4-pro` - GPT-5.3 Codex: $0.08 — `/api/llm/gpt-5.3-codex` - Claude Opus 4.5: $0.09 — `/api/llm/claude-opus-4.5` - Gemini 3.1 Pro: $0.05 — `/api/llm/gemini-3.1-pro` - Gemini 3.1 Flash Lite: $0.003 — `/api/llm/gemini-3.1-flash-lite` - Qwen 3.5: $0.006 — `/api/llm/qwen3.5` - DeepSeek V3.2: $0.008 — `/api/llm/deepseek-v3.2-speciale` - MiniMax M2.7: $0.01 — `/api/llm/minimax-m2.7` - Llama 4 Maverick: $0.003 — `/api/llm/llama-4-maverick` - GPT-5 Nano: $0.002 — `/api/llm/gpt-5-nano` - OpenAI o4-mini: $0.03 — `/api/llm/o4-mini` - Cohere Command A: $0.04 — `/api/llm/command-a` - Claude Opus 4.8: $0.09 — `/api/llm/claude-opus-4.8` - Qwen 3.7 Plus: $0.006 — `/api/llm/qwen3.7-plus` - Qwen 3.7 Max: $0.015 — `/api/llm/qwen3.7-max` - GLM 5.2: $0.03 — `/api/llm/glm-5.2` - DeepSeek V4 Flash: $0.003 — `/api/llm/deepseek-v4-flash` - DeepSeek V4 Pro: $0.006 — `/api/llm/deepseek-v4-pro` - MiniMax M3: $0.01 — `/api/llm/minimax-m3` - Text Embeddings: $0.001 — `/api/embeddings` ### 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