Skip to main content
This quickstart takes you from installation to a working request through selat-router.

Prerequisites

Before you begin, you must have:
  • Node.js 18 or newer
  • Access to a signer, either a private key, Circle Agent Wallet, or remote signer
  • A wallet funded with USDC on your target chain (see the “Fund your wallet” step below)
  • A target endpoint that is reachable through SELAT

Get started

1

Install

Install the SDK.
npm install @selat-ai/router-client
2

Create a signer

Start with a private key, or switch to a Circle Agent Wallet or remote signer when you are ready to remove secrets from the runtime.The signer reads your key from the X402_CLIENT_PRIVATE_KEY environment variable. If you don’t already have a key, generate one:
# Generate a new private key (requires `npm install viem`)
node -e "console.log(require('viem/accounts').generatePrivateKey())"

# Export it so the signer can read it (use a real secret store in production)
export X402_CLIENT_PRIVATE_KEY=0x...
Then create the signer:
import { createViemSigner } from "@selat-ai/router-client";

const signer = createViemSigner(process.env.X402_CLIENT_PRIVATE_KEY as `0x${string}`);
3

Fund your wallet

Paid requests draw USDC from your signer’s wallet through Circle Gateway. A brand-new key has a zero balance, so fund it before your first paid request — otherwise the request fails with an insufficient-balance error.The simplest way to top up is the SELAT CLI:
npm install -g @selat-ai/selat-cli
selat fund --chain base --amount 2
Use the same chain you pass to RouterClient (here, base) — see Supported chains. You can also deposit USDC into Circle Gateway directly for the wallet behind your signer.
4

Send a paid request

Create the client and call fetch against your target endpoint.
import { RouterClient, createViemSigner } from "@selat-ai/router-client";

const signer = createViemSigner(process.env.X402_CLIENT_PRIVATE_KEY as `0x${string}`);

const client = new RouterClient({
  chain: "base",
  signer
});

const response = await client.fetch("https://upstream.example.com/v1/data", {
  method: "GET"
});

console.log(await response.text());
If you want to keep the signer outside the SDK process, use Circle Agent Wallets or a remote signer.