Skip to main content
RouterClient is the main entry point in the SDK.
import { RouterClient, createViemSigner } from "@selat-ai/router-client";

Constructor

new RouterClient({
  chain,
  privateKey,
  signer,
  routerUrl,
  requestTimeoutMs,
  defaultHeaders
})

Parameters

ParameterTypeRequiredDefaultDescription
chainSupportedChainNameYesNoneThe chain to settle the payment on. See Supported chains.
privateKey0x${string}NoNoneBuilds a signer inside the SDK process. Use this only when in-process private key handling is acceptable.
signerPaymentSignerNoNoneA fully constructed signer object. Use this when you want more control or want to keep secrets elsewhere.
routerUrlstringNohttps://router.selat.aiRouter base URL used to build the proxy request.
requestTimeoutMsnumberNo30000Request timeout in milliseconds for each router call.
defaultHeadersRecord<string, string>No{}Headers applied to every request before per-call overrides.
You must provide either signer or privateKey.

Returns

Return valueTypeDescription
new RouterClient(...)RouterClient instanceCreates a client that can send paid requests through selat-router.

Supported chains

The chain option selects the chain SELAT settles your payment on. Pass the chain key as a string (the SDK’s SupportedChainName), for example chain: "base". Payments settle in USDC over Circle Gateway, so the supported set tracks the EVM chains Circle Gateway supports, plus Arc. These keys are confirmed across the SELAT stack:
ChainKeyNotes
BasebaseDefault throughout the docs; most widely tested.
Optimismoptimism
Arbitrumarbitrum
ArcarcPrivate-access mainnet (eip155:5042). Requires raw-key signing — Circle’s MPC signer can’t sign Arc yet — and gasless (eco) funding is not available.
Base, Optimism, and Arbitrum additionally support gasless deposits into Circle Gateway via Eco — no native gas needed in the wallet, settling on Polygon. Top up with selat fund --method eco. Circle Gateway supports additional EVM mainnets. For the authoritative list your runtime actually accepts, run:
npx @selat-ai/selat-pay --list-chains

Methods

fetch(input, init?)

Fetches a target URL through SELAT and returns the final response.
const response = await client.fetch("https://upstream.example.com/v1/data", {
  method: "GET",
  preferProtocol: "mpp"
});

Parameters

ParameterTypeRequiredDefaultDescription
inputstringYesNoneThe target URL to fetch through SELAT.
initRouterFetchOptionsNo{}Request options forwarded to the router proxy call.
preferProtocol accepts:
  • mpp
  • x402

Request options

OptionTypeRequiredDefaultDescription
methodstringNoGETHTTP method for the target request.
headersHeadersInitNo{}Headers added to the proxied request.
bodyBodyInit | nullNoNoneRequest body for POST, PUT, PATCH, or other body-bearing methods.
signalAbortSignalNoNoneCancels the request and any retry flow.
preferProtocol"mpp" | "x402"NomppHints which paid-rail protocol to prefer.

Returns

Return valueTypeDescription
client.fetch(...)Promise<Response>Resolves to the final upstream Response. If payment is not required, the first response is returned directly.
If the upstream response does not require payment, the SDK returns it directly.

createFetch({ baseUrl })

Creates a fetch-like helper for relative paths.
const apiFetch = client.createFetch({ baseUrl: "https://upstream.example.com" });

const response = await apiFetch("/v1/data");

Parameters

ParameterTypeRequiredDefaultDescription
baseUrlstringYesNoneBase URL used to resolve relative paths before routing through SELAT.

Returns

Return valueTypeDescription
client.createFetch(...)(path: string, init?: RouterFetchOptions) => Promise<Response>Returns a fetch-like function bound to the provided base URL.

Errors

The main configuration and payment flow can raise these public errors:
  • RouterClientConfigError
  • QuoteParseError
Use RouterClientConfigError to catch configuration issues early, such as missing chain or missing signer input.