Skip to content

Connecting & auth

import { FinnClient } from '@riseanalytics/finn-sdk';
const finn = new FinnClient({
url: 'https://finn.example.com',
apiKey: process.env.FINN_API_KEY,
});

Constructing a client does not open a connection — it just holds config. Call connect() when you’re ready:

await finn.connect(); // opens the WebSocket and authenticates
// ... use the client ...
await finn.disconnect(); // closes it

Everything except url is optional.

OptionTypeDefaultDescription
urlstringRequired. Base URL of the Finn backend, e.g. https://finn.example.com or wss://….
apiKeystringStatic API key, sent as the WebSocket handshake auth token.
getApiKey() => string | Promise<string>Alternative to apiKey: resolve the key at connect time (e.g. for rotation).
pathstring'/ws'Socket.IO path on the backend.
sessionIdstringResume a prior session.
systemPromptstringClient-level system-prompt default applied to new conversations. See System prompts.
reconnectionbooleantrueAuto-reconnect on a dropped socket.
timeoutMsnumber10000Connect timeout in milliseconds.

Finn uses a single static API key. Provide it either directly or lazily:

// Direct
const finn = new FinnClient({ url, apiKey: 'your-key' });
// Resolved at connect time — handy for rotating secrets
const finn = new FinnClient({
url,
getApiKey: async () => await vault.read('finn/api-key'),
});

If the key is missing or rejected, connect() rejects with a FinnError whose code is 'unauthorized', and the client emits an unauthorized event.

Subscribe with on(event, handler):

finn.on('unauthorized', () => console.error('API key rejected'));
finn.on('rateLimit', (info) => console.warn('rate limited', info));
finn.on('disconnect', (reason) => console.warn('disconnected:', reason));
EventPayloadFires when
unauthorizedThe API key is missing or rejected.
rateLimitRateLimitInfoThe backend signals a rate limit.
disconnectreason: stringThe socket drops (auto-reconnect may follow if enabled).