API Reference

Complete reference for every class, method, type, and event in the SDK.

XpectrumChat

typescript
import { XpectrumChat } from '@xpectrum/sdk';

Constructor

typescript
const chat = new XpectrumChat(config: XpectrumChatConfig);
PropertyTypeRequiredDefaultDescription
baseUrlstringYesChat API base URL (e.g. https://app.yourserver.com/api/v1)
apiKeystringYesAPI key — sent as Authorization: Bearer {apiKey}
userstringNo'sdk-user'User identifier for conversation history
inputsRecord<string, any>No{}Default input variables for every message

Methods

MethodReturnsDescription
sendMessage(query, options?)Promise<string | undefined>Send a message and stream response. Returns taskId.
stopResponse(taskId)Promise<void>Stop a response mid-generation.
getConversations(opts?)Promise<{ data, has_more }>List conversations. opts: { limit?, lastId?, pinned? }
getMessages(convId, opts?)Promise<{ data, has_more }>Get messages in a conversation. opts: { limit?, lastId? }
deleteConversation(id)Promise<void>Delete a conversation.
renameConversation(id, name)Promise<void>Rename a conversation.
generateConversationName(id)Promise<Conversation>Auto-generate a name based on content.
pinConversation(id)Promise<void>Pin a conversation.
unpinConversation(id)Promise<void>Unpin a conversation.
getAppInfo()Promise<AppInfo>Get app title, icon, description.
getAppParams()Promise<AppParams>Get opening statement, features, config.
submitFeedback(msgId, rating)Promise<void>Like/dislike/clear feedback. rating: 'like' | 'dislike' | null
getSuggestedQuestions(msgId)Promise<string[]>Get AI-suggested follow-up questions.
speechToText(audioFile)Promise<string>Convert audio File to text.
destroy()voidAbort all streams, clean up.

SendMessageOptions

PropertyTypeRequiredDefaultDescription
conversationIdstringNoResume an existing conversation.
inputsRecord<string, any>NoOverride default inputs for this message.
filesMessageFile[]NoAttached files (images).
onMessage(text, messageId, conversationId) => voidNoText chunks — text accumulates the full answer.
onThought(thought: ThoughtEvent) => voidNoAgent reasoning steps.
onFile(file: FileEvent) => voidNoFile attachments from the agent.
onMessageEnd(metadata: MessageEndEvent) => voidNoResponse complete with metadata.
onMessageReplace(text, messageId) => voidNoContent moderation replaced the answer.
onTTSChunk(messageId, audioBase64) => voidNoTTS audio chunk (base64).
onTTSEnd(messageId, audioBase64) => voidNoTTS complete.
onError(error: ErrorEvent) => voidNoError during streaming.
onCompleted() => voidNoStream closed.
getAbortController(controller) => voidNoAccess the AbortController.

MessageFile

PropertyTypeRequiredDefaultDescription
type'image'YesFile type.
transfer_method'remote_url' | 'local_file'YesHow the file is provided.
urlstringNoURL for remote_url method.
upload_file_idstringNoFile ID for local_file method.

ThoughtEvent

PropertyTypeRequiredDefaultDescription
idstringYesThought ID.
thoughtstringYesWhat the agent is thinking.
observationstringNoResult from a tool.
toolstringNoTool name being used.
tool_inputstringNoInput passed to the tool.
message_idstringYesParent message ID.
positionnumberYesOrder in the sequence.

MessageEndEvent

PropertyTypeRequiredDefaultDescription
task_idstringYesTask identifier.
message_idstringYesMessage identifier.
conversation_idstringYesConversation identifier.
metadata.usage{ prompt_tokens, completion_tokens, total_tokens, total_price, currency }NoToken usage stats.
metadata.retriever_resourcesArray<{ dataset_name, document_name, content, score, ... }>NoRAG source documents.

Conversation

PropertyTypeRequiredDefaultDescription
idstringYesConversation ID.
namestringYesConversation name/title.
inputsRecord<string, any>YesInput variables used.
statusstringYesConversation status.
introductionstringYesOpening statement.
created_atnumberYesUnix timestamp.
updated_atnumberYesUnix timestamp.

Message

PropertyTypeRequiredDefaultDescription
idstringYesMessage ID.
conversation_idstringYesParent conversation.
querystringYesUser's question.
answerstringYesAI's response.
message_filesArray<{ id, type, url, belongs_to }>YesAttached files.
feedback{ rating: 'like' | 'dislike' | null } | nullYesUser feedback.
retriever_resourcesArray<{ dataset_name, document_name, content, score }>YesRAG sources.
agent_thoughtsThoughtEvent[]YesReasoning steps.
created_atnumberYesUnix timestamp.

AppInfo

PropertyTypeRequiredDefaultDescription
app_idstringYesApp identifier.
titlestringYesApp display title.
descriptionstringYesApp description.
icon_typestringYesIcon type (emoji, url, etc.).
iconstringYesIcon value.
icon_backgroundstringYesIcon background color.
icon_urlstring | nullYesIcon image URL if applicable.

XpectrumVoice

typescript
import { XpectrumVoice } from '@xpectrum/sdk';

Constructor

typescript
const voice = new XpectrumVoice(config: XpectrumVoiceConfig);
PropertyTypeRequiredDefaultDescription
baseUrlstringYesFastAPI voice server URL.
apiKeystringYesAPI key — sent as x-api-key header.
agentNamestringYesAgent UUID or name to connect to.

Methods

MethodReturnsDescription
connect(callbacks?)Promise<void>Start a voice call. Callbacks are optional (can use events instead).
disconnect()Promise<void>End the call, clean up audio, notify server.
setMicEnabled(enabled)Promise<void>Mute (false) or unmute (true) the microphone.
isMicEnabled()booleanCheck if mic is currently enabled.
getConnectionState()VoiceConnectionStateGet current state: 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'
getRoomName()string | nullGet LiveKit room name (null if not connected).
isConnected()booleanShorthand for getConnectionState() === 'connected'.
on(event, handler)() => voidSubscribe to event. Returns unsubscribe function.
off(event, handler)voidUnsubscribe from event.
removeAllListeners(event?)voidRemove all listeners (optionally for specific event).
destroy()voidDisconnect + remove all listeners.

VoiceConnectCallbacks

PropertyTypeRequiredDefaultDescription
onConnected(roomName: string) => voidNoCall connected.
onDisconnected(reason: string) => voidNoCall ended.
onTranscription(segment: TranscriptionSegment) => voidNoSpeech transcribed.
onAgentSpeaking(isSpeaking: boolean) => voidNoAgent started/stopped speaking.
onConnectionStateChanged(state: VoiceConnectionState) => voidNoState transition.
onReconnecting() => voidNoNetwork reconnecting.
onReconnected() => voidNoNetwork reconnected.
onError(error: { message, code? }) => voidNoError occurred.

TranscriptionSegment

PropertyTypeRequiredDefaultDescription
idstringYesSegment ID. Interim results share the same ID.
textstringYesTranscribed text.
isFinalbooleanYestrue when finalized.
speaker'user' | 'agent'YesWho spoke.

Voice Events

EventPayload
'connected'{ roomName: string }
'disconnected'{ reason: string }
'transcription'TranscriptionSegment
'agentSpeaking'{ isSpeaking: boolean }
'connectionStateChanged'{ state: VoiceConnectionState }
'reconnecting'{}
'reconnected'{}
'error'{ message: string; code?: string }
'microphoneChanged'{ enabled: boolean }

XpectrumApiError

typescript
import { XpectrumApiError } from '@xpectrum/sdk';
PropertyTypeRequiredDefaultDescription
name'XpectrumApiError'YesError name (always 'XpectrumApiError').
messagestringYesHuman-readable error message.
codestringYesError code string.
statusnumberYesHTTP status code (401, 403, 404, 429, 500, etc.).

Widgets

ChatWidget

typescript
import { ChatWidget } from '@xpectrum/sdk';

Methods: open(), close(), toggle(), destroy()

VoiceWidget

typescript
import { VoiceWidget } from '@xpectrum/sdk';

Methods: open(), close(), toggle(), destroy()

OmnichannelWidget

typescript
import { OmnichannelWidget } from '@xpectrum/sdk';

Methods: openChat(), openVoice(), close(), destroy()

See the Widgets Guide for full config options and examples.

TypeScript Type Imports

typescript
import type {
  // Chat
  XpectrumChatConfig,
  SendMessageOptions,
  MessageFile,
  ThoughtEvent,
  FileEvent,
  MessageEndEvent,
  ErrorEvent,
  Conversation,
  ConversationListResponse,
  Message,
  MessageListResponse,
  AppInfo,
  AppParams,

  // Voice
  XpectrumVoiceConfig,
  TokenResponse,
  VoiceConnectionState,
  VoiceEventMap,
  VoiceConnectCallbacks,
  TranscriptionSegment,

  // Core
  RequestOptions,
  ApiError,
  SSEEvent,
  SSEMessageData,
  EventHandler,
  UnsubscribeFn,

  // Widgets
  ChatWidgetConfig,
  VoiceWidgetConfig,
  OmnichannelWidgetConfig,
} from '@xpectrum/sdk';

Internal API Endpoints

These are the HTTP endpoints the SDK calls internally. You don't call them directly — this is for reference/debugging.

Chat

MethodEndpointSDK Method
POST/chat-messagessendMessage()
POST/chat-messages/{taskId}/stopstopResponse()
GET/conversationsgetConversations()
GET/messages?conversation_id={id}getMessages()
DELETE/conversations/{id}deleteConversation()
POST/conversations/{id}/namerenameConversation() / generateConversationName()
PATCH/conversations/{id}/pinpinConversation()
PATCH/conversations/{id}/unpinunpinConversation()
GET/sitegetAppInfo()
GET/parametersgetAppParams()
POST/messages/{id}/feedbackssubmitFeedback()
GET/messages/{id}/suggested-questionsgetSuggestedQuestions()
POST/audio-to-textspeechToText()

Voice

MethodEndpointSDK Method
POST/tokens/generate?agent_name={name}connect()
POST/call-control/end-calldisconnect()