Streaming
Streaming
@toothfairyai/sdk@latest…Streaming Management Module Provides real-time streaming capabilities for agent interactions.
Accessed via client.streaming.
Methods
| Method | HTTP | Endpoint |
|---|---|---|
sendToAgent | POST | POST /agent |
sendToAgentWithCallback | POST | POST /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
| Field | Type | Required | Description |
|---|---|---|---|
workspaceid | string | yes | Unique workspace identifier |
chatid | string | no | Chat ID. Omit to create a new chat (a new ID is returned in the stream). |
agentid | string | yes | Agent ID to handle the conversation |
messages | array<object> | yes | Messages to send to the Agent |
chat_history | array<object> | no | Provide conversation context from previous turns without persisting. |
base_image | string | no | Base image key for vision-enabled agents. Used as visual context for the conversation. Upload via document API first. |
storeMessages | boolean | no | Whether to persist the generated messages to the chat (camelCase; the backend reads storeMessages, not store_messages) |
nextMessageId | string | no | Optional ID for the next message (for client-side correlation) |
external_channel_type | string | no | Optional external channel type (e.g. whatsapp, sms, email) when the request originates from a channel |
email_metadata | object | no | Optional email metadata (subject, from, to, etc.) when the request originates from email |
plannerAgent | string | no | Optional planner/orchestrator agent ID for the conversation |
from_planner | boolean | no | Whether this request is being made from a planner flow |
name | string | no | Optional 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
| Field | Type | Required | Description |
|---|---|---|---|
workspaceid | string | yes | Unique workspace identifier |
chatid | string | no | Chat ID. Omit to create a new chat (a new ID is returned in the stream). |
agentid | string | yes | Agent ID to handle the conversation |
messages | array<object> | yes | Messages to send to the Agent |
chat_history | array<object> | no | Provide conversation context from previous turns without persisting. |
base_image | string | no | Base image key for vision-enabled agents. Used as visual context for the conversation. Upload via document API first. |
storeMessages | boolean | no | Whether to persist the generated messages to the chat (camelCase; the backend reads storeMessages, not store_messages) |
nextMessageId | string | no | Optional ID for the next message (for client-side correlation) |
external_channel_type | string | no | Optional external channel type (e.g. whatsapp, sms, email) when the request originates from a channel |
email_metadata | object | no | Optional email metadata (subject, from, to, etc.) when the request originates from email |
plannerAgent | string | no | Optional planner/orchestrator agent ID for the conversation |
from_planner | boolean | no | Whether this request is being made from a planner flow |
name | string | no | Optional 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', '…');