Skip to content

API reference

Everything the package exports.

import { FinnClient, FinnError, VERSION } from '@riseanalytics/finn-sdk';
import type {
FinnClientOptions,
SendMessageOptions,
MessageTurn,
TokenChunk,
TurnResult,
AskResult,
RateLimitInfo,
FinnErrorCode,
} from '@riseanalytics/finn-sdk';
new FinnClient(options: FinnClientOptions)
MethodNode.js signaturePython signatureDescription
connectconnect() => Promise<void>await connect()Open the WebSocket and authenticate. Fails with a FinnError.
disconnectdisconnect() => Promise<void>await disconnect()Close the connection.
send messagesendMessage(text, options?) => MessageTurnawait send_message(text, *, conversation_id=None, system_prompt=None) -> MessageTurnSend a message; returns a MessageTurn to stream from.
askask(text, options?) => Promise<AskResult>await ask(text, ...) -> AskResultNon-streaming: send and resolve once with the full answer text + result.
ask JSONaskJson<T>(text, options?) => Promise<T>await ask_json(text, ...) -> AnyLike ask, but extracts and parses the answer as JSON. Fails invalid_json if it can’t parse. Prompt for JSON yourself.
onon(event, handler) => thison(event, handler) -> selfSubscribe to a lifecycle event: connected, reconnect, unauthorized, rateLimit, disconnect.

The Python client is also an async context managerasync with FinnClient(...) as finn: connects on enter and disconnects on exit.

Node.js (FinnClientOptions)Python (kwargs)Description
url (required)urlBackend base URL.
apiKeyapi_keyStatic API key.
getApiKeyget_api_keyResolve the key at connect time.
path ('/ws')pathSocket.IO path.
sessionIdsession_idResume a prior session.
systemPromptsystem_promptClient default for new conversations.
reconnection (true)reconnectionAuto-reconnect.
timeoutMs (10000)timeout_msConnect timeout (ms).

See Connecting & auth for details on each option.

Continue a conversation or override the system prompt when sending a message.

Node.js (SendMessageOptions)Python (kwargs)Description
conversationIdconversation_idContinue an existing conversation.
systemPromptsystem_promptPer-conversation override (new conversations only).

The return value of sendMessage() / send_message(). It’s an async-iterable of token chunks, plus:

interface MessageTurn extends AsyncIterable<TokenChunk> {
readonly conversationId: Promise<string>; // resolves once the conversation exists
readonly completed: Promise<TurnResult>; // resolves when the turn finishes
interrupt(): void; // ask the backend to stop this turn
}

completed fails with a FinnError if the turn breaks. See Sending messages & streaming.

interface TokenChunk {
text: string; // a piece of the streamed answer
messageId: string;
conversationId: string;
}
interface TurnResult {
conversationId: string;
messageId?: string;
tokenUsage?: { input: number; output: number; total: number };
turnState?: string;
interrupted: boolean; // true if interrupt() ended the turn
}

Returned by ask() — a TurnResult plus the complete answer text (text).

class FinnError extends Error {
code: FinnErrorCode;
conversationId?: string;
details?: unknown;
}
type FinnErrorCode =
| 'unauthorized'
| 'rate_limited'
| 'timeout'
| 'conversation_read_only'
| 'stream_error'
| 'disconnected'
| 'invalid_json';

See Error handling for what each code means.

The payload of the rateLimit event — a free-form object of backend-provided rate-limit metadata.

VERSION (Node.js) / __version__ (Python) — the SDK package version string, e.g. '0.1.0'.