Skip to main content

Streaming

Waiting for a long model response before showing anything makes a chat interface feel blocked. Streaming solves this by delivering output events as they arrive, while the SDK handles the event transport and incremental response flow for you.

from agents import Agent, Runner
from openai.types.responses import ResponseTextDeltaEvent
from iztro_agents import ChatSession, IztroToolEvent, iztro_ziwei_agent

agent = iztro_ziwei_agent()
session = ChatSession(external_user_id="user_42")
result = Runner.run_streamed(agent, "I was born on 1990-12-21 at 13:00, female. Analyze my relationship and marriage timing from 2026 to 2028.", session=session)
async for event in result.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, IztroToolEvent):
print(f"\n iztro computed: {', '.join(event.data.tools)}\n")
elif event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="")

The HTTP equivalent is POST /v2/platform/sessions/{session_id}/messages/stream and uses Server-Sent Events.

Real example: 03_streaming_chat.py

The recorded Chinese and English streaming outputs are shown inline below, including the live iztro computed event.

Source: examples/03_streaming_chat.py.

Prompt used for this run

I was born on 1990-12-21 at 13:00, female. Please analyze my 2026 relationship outlook.

Complete recorded output

Loading recorded output…