Skip to main content

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

MethodHTTPEndpoint
send_to_agentPOSTPOST /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

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)

The Python SDK accepts snake_case keyword arguments and converts them to the camelCase wire 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")