Skip to content

Onboarding

This guide walks through using the gateway as a client: add credit with USDC or USDT (x402), create an API key (SIWE), then call the chat completion API.

What You Need

  • A wallet private key for signing
  • USDC on Base mainnet or USDT on Arbitrum
  • The gateway base URL (HTTPS origin, no path). The hosted gateway is https://agent-router.gaib.cloud
  • Node.js if you use the official example script

End-to-End Flow

StepWhat Happens
1. Top upPOST /v1/topup with { "amount": <usd> }. The server responds with 402 and payment instructions. Sign and complete payment per x402, then retry.
2. API keyPOST /v1/auth/keys with a SIWE message and signature. Response includes a secret API key (store it safely).
3. InferencePOST /v1/chat/completions with Authorization: Bearer <api_key> and a chat-style JSON body.

Model IDs are provider-qualified: openrouter/..., gemini/..., kimi/..., minimax/..., bedrock/..., or local/....

Example Automation Script

The repo includes a TypeScript script that runs all three steps:

bash
set -a && source .env && set +a && \
GATEWAY_URL=https://agent-router.gaib.cloud \
SKIP_MINT=1 \
npx tsx scripts/stg-topup-and-inference.ts

Environment Variables

VariablePurpose
TEST_PKRequired. Hex-encoded private key for the wallet.
GATEWAY_URLBase URL of the gateway.
TOPUP_AMOUNT_USDTop-up amount in USD (minimum 1).
MODELChat model id (default: a gemini/... model).
X402_CLIENT_NETWORKCAIP-2 network for payment (e.g. eip155:8453 for Base).

SIWE Message Alignment

The SIWE message must match what the server verifies:

  • domain -- hostname of the gateway (e.g. agent-router.gaib.cloud)
  • uri -- the auth endpoint (e.g. https://agent-router.gaib.cloud/v1/auth/keys)
  • chainId -- must match the gateway's chain

If key creation fails with 4xx, confirm you're using the same public HTTPS host the gateway presents.

After Onboarding

Inference requests are billed against your wallet balance. Send chat completion requests with your Bearer token until limits or balance apply.

Released under the MIT License.