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. The Python client takes the same options as snake_case keyword arguments (e.g. api_key, get_api_key, session_id, system_prompt, timeout_ms).

Option (Node.js)PythonTypeDefaultDescription
urlurlstrRequired. Base URL of the Finn backend, e.g. https://finn.example.com or wss://….
apiKeyapi_keystrStatic API key, sent as the WebSocket handshake auth token.
getApiKeyget_api_key() -> str | Awaitable[str]Alternative to apiKey: resolve the key at connect time (e.g. for rotation).
pathpathstr'/ws'Socket.IO path on the backend.
sessionIdsession_idstrResume a prior session.
systemPromptsystem_promptstrClient-level system-prompt default applied to new conversations. See System prompts.
reconnectionreconnectionbooltrueAuto-reconnect on a dropped socket.
timeoutMstimeout_msint10000Connect 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() raises 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));

Event handlers are plain callbacks (not coroutines). The event names are the same in both languages.

EventPayloadFires when
connectedThe session is established (after connect()).
reconnectThe socket reconnected after a drop.
unauthorizedThe API key is missing or rejected.
rateLimitRateLimitInfoThe backend signals a rate limit.
disconnectreason: stringThe socket drops (auto-reconnect may follow if enabled).