Overview
X-Router is a payment-enabled AI API gateway that provides access to multiple AI models through a unified interface. All AI inference requests require payment via the x402 protocol - a gasless micropayment system using USDC on Base Mainnet.
Key Features
Gasless Payments
Pay with USDC without needing ETH for gas fees. The x402 protocol handles all gas payments through a facilitator.
Dynamic Pricing with Automatic Refunds
You’re charged an estimated maximum cost upfront based on your request parameters. After the request completes, any difference between the estimate and actual cost is automatically refunded to your wallet.
How it works:
- Upfront charge: You pay the estimated cost when making a request
- Actual cost calculated: After completion, the real cost is determined
- Automatic refund: Any overpayment is returned to your wallet (no action needed)
Pricing is based on:
- Number of input tokens (all messages combined)
- Requested
max_tokensfor output - Model-specific pricing rates
For image generation, estimates account for resolution, model complexity, and generation parameters.
Multiple Models
Access to 290+ AI models from various providers including:
- Anthropic (Claude models)
- OpenAI (GPT models)
- Google (Gemini models)
- Meta (Llama models)
- And many more…
The model list is updated regularly. Use the /v1/models endpoint to see all available models.
Token Transparency
Every response includes detailed token usage information:
- Prompt tokens (input)
- Completion tokens (output)
- Total tokens
This allows you to track your usage patterns and optimize for cost.
Streaming Support
Real-time Server-Sent Events (SSE) streaming for instant responses. Enable streaming with the stream: true parameter to receive tokens as they’re generated.
How x402 Payment Works
The x402 protocol enables gasless micropayments for API requests:
- Client sends request: Your application makes a normal HTTP request to a paid endpoint
- Server responds with 402: The server returns a
402 Payment Requiredstatus with payment details - Client signs authorization: The x402-fetch library automatically signs an ERC-3009 transfer authorization (no blockchain interaction)
- Facilitator executes transfer: The facilitator executes the USDC transfer and pays all gas fees
- Server processes request: The server validates payment and returns the AI response
Key Point: You never interact with the blockchain directly. No gas fees, no transactions to send - just sign a message. The x402-fetch library handles everything automatically.
Requirements
To use X-Router, you need:
- USDC Balance: USDC on Base Mainnet in your wallet (How to get USDC)
- Wallet: Any Ethereum wallet with a private key (no ETH needed!)
- x402 Client Library: The
x402-fetchnpm package
That’s it! No API keys, no account registration, just USDC and a wallet.
Rate Limits
API requests are limited to 100 requests per minute per IP address to ensure fair usage. See Rate Limits for details and best practices.