Streaming
Streaming
toothfairyai@latest…Manager for streaming AI responses.
This manager provides methods to stream responses from AI agents using an iterator pattern similar to OpenAI's Python SDK.
Example:
>>> stream = client.streaming.send_to_agent("Hello", "agent-id")
>>> for event in stream:
... if event.text:
... print(event.text, end="", flush=True)
>>> print()
>>> print(f"Chat ID: {stream.chat_id}")
Accessed via client.streaming.
Methods
| Method | HTTP | Endpoint |
|---|---|---|
send_to_agent | POST | POST /agent |
send_to_agent
Send a message to an agent and receive a streaming response.
def send_to_agent(
message: str,
agent_id: str,
chat_id: Optional[str] = None,
phone_number: Optional[str] = None,
customer_id: Optional[str] = None,
provider_id: Optional[str] = None,
customer_info: Optional[Dict[str, Any]] = None,
attachments: Optional[Attachments] = None,
raw_stream: bool = True
) -> StreamResponse
Endpoint: POST /agent · AI streaming service (SSE)
Request fields
| Python kwarg | Wire field | Type | Required | Description |
|---|---|---|---|---|
workspace_id | workspaceid | string | yes | Unique workspace identifier |
chatid | chatid | string | no | Chat ID. Omit to create a new chat (a new ID is returned in the stream). |
agentid | agentid | string | yes | Agent ID to handle the conversation |
messages | messages | array<object> | yes | Messages to send to the Agent |
chat_history | chat_history | array<object> | no | Provide conversation context from previous turns without persisting. |
base_image | base_image | string | no | Base image key for vision-enabled agents. Used as visual context for the conversation. Upload via document API first. |
store_messages | storeMessages | boolean | no | Whether to persist the generated messages to the chat (camelCase; the backend reads storeMessages, not store_messages) |
next_message_id | nextMessageId | string | no | Optional ID for the next message (for client-side correlation) |
external_channel_type | external_channel_type | string | no | Optional external channel type (e.g. whatsapp, sms, email) when the request originates from a channel |
email_metadata | email_metadata | object | no | Optional email metadata (subject, from, to, etc.) when the request originates from email |
planner_agent | plannerAgent | string | no | Optional planner/orchestrator agent ID for the conversation |
from_planner | from_planner | boolean | no | Whether this request is being made from a planner flow |
name | name | string | no | Optional chat name (defaults to "New Chat" when creating a new chat) |
Always pass
snake_casekeyword arguments — the Python kwarg column shows the exact name to use for each wire field (as a named parameter where it appears in the method signature, otherwise via**kwargs). The SDK converts it deterministically to thecamelCasewire key the API expects. PassingcamelCasedirectly is deprecated: it emits a warning and converts to the same wire key.
Response
This is a streaming endpoint. The response is delivered as Server-Sent Events (SSE) rather than a single JSON object. The method yields SSE events (or resolves with the accumulated text for collect-style helpers).
Example
client.streaming.send_to_agent(message="…", agent_id="agent-id")