Skip to content

Quickstart

Get your first API call working in 2 minutes.

Prerequisites

RequirementWhy
Ethereum walletSigns SIWE messages & pays USDC
USDC on BaseCredits your gateway balance
Node.js 18+Runs the examples below

Staging / Testnet

The hosted staging gateway at https://agent-router.gaib.cloud uses Base Sepolia. You can mint free test USDC at:

0xB5080336118e55bc5D5Cf5f37771dB5C392FC48D

The contract has a public mint function -- no faucet needed.

Step 1: Top up your balance

ts
import { withPaymentInterceptor } from '@x402/fetch'

const BASE_URL = 'https://agent-router.gaib.cloud'
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

ts
import { SiweMessage } from 'siwe'

const siweMsg = new SiweMessage({
  domain: 'agent-router.gaib.cloud',
  address: walletAddress,
  uri: 'https://agent-router.gaib.cloud/v1/auth/keys',
  version: '1',
  chainId: 1,
  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 once

Step 3: Make an inference call

ts
import OpenAI from 'openai'

const client = new OpenAI({
  baseURL: 'https://agent-router.gaib.cloud/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)
ts
const res = await fetch('https://agent-router.gaib.cloud/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)
bash
curl -X POST https://agent-router.gaib.cloud/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

ts
const res = await fetch(
  'https://agent-router.gaib.cloud/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}`)
bash
curl https://agent-router.gaib.cloud/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 IDProviderPrompt $/1MCompletion $/1M
gemini/gemini-2.5-flashGoogle$0.15$0.60
gemini/gemini-2.5-proGoogle$1.25$10.00
kimi/kimi-k2.5Moonshot$0.60$3.00
minimax/MiniMax-M2.5MiniMax$0.118$0.95
openrouter/anthropic/claude-3-5-sonnetOpenRoutervariesvaries

A 20% markup is applied on top of these downstream costs.

Full list: Models & Pricing

Streaming

Set stream: true for server-sent events:

ts
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 ?? '')
}

What's next?

Released under the MIT License.