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
| 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) |
The Python SDK accepts
snake_casekeyword arguments and converts them to thecamelCasewire fields shown above.
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")