Skip to main content

Streaming

Streaming

@toothfairyai/sdk@latest…

Streaming Management Module Provides real-time streaming capabilities for agent interactions.

Accessed via client.streaming.

Methods

MethodHTTPEndpoint
sendToAgentPOSTPOST /agent
sendToAgentWithCallbackPOSTPOST /agent

sendToAgent

Send a message to an agent with streaming response

async sendToAgent(
message: string,
agentId: string,
options: StreamingOptions = {}
)

Endpoint: POST /agent · AI streaming service (SSE)

Request fields

FieldTypeRequiredDescription
workspaceidstringyesUnique workspace identifier
chatidstringnoChat ID. Omit to create a new chat (a new ID is returned in the stream).
agentidstringyesAgent ID to handle the conversation
messagesarray<object>yesMessages to send to the Agent
chat_historyarray<object>noProvide conversation context from previous turns without persisting.
base_imagestringnoBase image key for vision-enabled agents. Used as visual context for the conversation. Upload via document API first.
storeMessagesbooleannoWhether to persist the generated messages to the chat (camelCase; the backend reads storeMessages, not store_messages)
nextMessageIdstringnoOptional ID for the next message (for client-side correlation)
external_channel_typestringnoOptional external channel type (e.g. whatsapp, sms, email) when the request originates from a channel
email_metadataobjectnoOptional email metadata (subject, from, to, etc.) when the request originates from email
plannerAgentstringnoOptional planner/orchestrator agent ID for the conversation
from_plannerbooleannoWhether this request is being made from a planner flow
namestringnoOptional chat name (defaults to "New Chat" when creating a new chat)

Response

This is a streaming endpoint. The response is delivered as Server-Sent Events (SSE) rather than a single JSON object. The returned PredictionStream/event emitter fires data (delta text), chunk (raw SSE object), complete, error, and end events.

Example

const result = await client.streaming.sendToAgent('…', 'agent-id');

sendToAgentWithCallback

Create a streaming session with custom event handling

async sendToAgentWithCallback(
message: string,
agentId: string,
onEvent: StreamEventCallback,
options: StreamingOptions = {}
): Promise<

Endpoint: POST /agent · AI streaming service (SSE)

Request fields

FieldTypeRequiredDescription
workspaceidstringyesUnique workspace identifier
chatidstringnoChat ID. Omit to create a new chat (a new ID is returned in the stream).
agentidstringyesAgent ID to handle the conversation
messagesarray<object>yesMessages to send to the Agent
chat_historyarray<object>noProvide conversation context from previous turns without persisting.
base_imagestringnoBase image key for vision-enabled agents. Used as visual context for the conversation. Upload via document API first.
storeMessagesbooleannoWhether to persist the generated messages to the chat (camelCase; the backend reads storeMessages, not store_messages)
nextMessageIdstringnoOptional ID for the next message (for client-side correlation)
external_channel_typestringnoOptional external channel type (e.g. whatsapp, sms, email) when the request originates from a channel
email_metadataobjectnoOptional email metadata (subject, from, to, etc.) when the request originates from email
plannerAgentstringnoOptional planner/orchestrator agent ID for the conversation
from_plannerbooleannoWhether this request is being made from a planner flow
namestringnoOptional chat name (defaults to "New Chat" when creating a new chat)

Response

This is a streaming endpoint. The response is delivered as Server-Sent Events (SSE) rather than a single JSON object. The returned PredictionStream/event emitter fires data (delta text), chunk (raw SSE object), complete, error, and end events.

Example

const result = await client.streaming.sendToAgentWithCallback('…', 'agent-id', '…');