Quickstart
Get your first API call working in 2 minutes.
Prerequisites
| Requirement | Why |
|---|---|
| Ethereum wallet | Signs SIWE messages & pays USDC or USDT |
| USDC or USDT on Base or Arbitrum | Credits your gateway balance |
| Node.js 18+ | Runs the examples below |
The hosted gateway at https://agent-router.gaib.ai runs on mainnet. Top up with real USDC or USDT on Base or Arbitrum — the live 402 response lists the exact assets and networks it accepts.
Step 1: Top up your balance
import { withPaymentInterceptor } from '@x402/fetch'
const BASE_URL = 'https://agent-router.gaib.ai'
const fetchWithPayment = withPaymentInterceptor(fetch, walletClient)
const res = await fetchWithPayment(`${BASE_URL}/v1/topup`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 5 }), // $5 USD minimum $1
})
const { balance_usdc } = await res.json()
// balance_usdc: 5000000 (micro-USDC, divide by 1_000_000 for USD)Step 2: Create an API key
import { SiweMessage } from 'siwe'
const siweMsg = new SiweMessage({
domain: 'agent-router.gaib.ai',
address: walletAddress,
uri: 'https://agent-router.gaib.ai/v1/auth/keys',
version: '1',
chainId: 8453, // Base mainnet
nonce: crypto.randomUUID().replace(/-/g, '').slice(0, 16),
issuedAt: new Date().toISOString(),
statement: 'Sign in to the AI Gateway',
})
const message = siweMsg.prepareMessage()
const signature = await walletClient.signMessage({ account: address, message })
const res = await fetch(`${BASE_URL}/v1/auth/keys`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message, signature, label: 'my-first-key' }),
})
const { key } = await res.json()
// key: "sk-a3f9..." ← save this, it's shown only onceStep 3: Make an inference call
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://agent-router.gaib.ai/v1',
apiKey: 'sk-your-api-key',
})
const res = await client.chat.completions.create({
model: 'gemini/gemini-2.5-flash',
messages: [{ role: 'user', content: 'What is x402?' }],
max_tokens: 256,
})
console.log(res.choices[0].message.content)const res = await fetch('https://agent-router.gaib.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gemini/gemini-2.5-flash',
messages: [{ role: 'user', content: 'What is x402?' }],
max_tokens: 256,
}),
})
const data = await res.json()
console.log(data.choices[0].message.content)curl -X POST https://agent-router.gaib.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini/gemini-2.5-flash",
"messages": [{"role": "user", "content": "What is x402?"}],
"max_tokens": 256
}'Step 4: Check your balance
const res = await fetch(
'https://agent-router.gaib.ai/v1/usage/0xYourWalletAddress',
{ headers: { 'Authorization': 'Bearer sk-your-api-key' } },
)
const usage = await res.json()
console.log(`Balance: $${usage.available_usdc / 1_000_000}`)
console.log(`Requests: ${usage.keys[0].request_count}`)curl https://agent-router.gaib.ai/v1/usage/0xYourWalletAddress \
-H "Authorization: Bearer sk-your-api-key"Available models
Use GET /v1/models to list all models, or pick from these popular options:
| Model ID | Provider | Prompt $/1M | Completion $/1M |
|---|---|---|---|
gemini/gemini-2.5-flash | $0.15 | $0.60 | |
gemini/gemini-2.5-pro | $1.25 | $10.00 | |
kimi/kimi-k2.5 | Moonshot | $0.60 | $3.00 |
minimax/MiniMax-M2.5 | MiniMax | $0.118 | $0.95 |
bedrock/nova-pro | AWS Bedrock | $0.80 | $3.20 |
bedrock/qwen3-32b | AWS Bedrock | $0.155 | $0.618 |
These are the rates you're billed at. See the live model catalog for the full list.
Streaming
Set stream: true for server-sent events:
const stream = await client.chat.completions.create({
model: 'gemini/gemini-2.5-flash',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '')
}