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.
- Python
- TypeScript
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="")
import {run} from '@openai/agents';
import {ChatSession, isIztroToolEvent, iztroZiweiAgent} from 'openai-iztro-agents';
const agent = iztroZiweiAgent();
const session = new ChatSession({externalUserId: 'user_42'});
const streamed = await run(agent, 'I was born on 1990-12-21 at 13:00, female. Analyze my relationship and marriage timing from 2026 to 2028.', {session, stream: true});
for await (const event of streamed) {
if (event.type !== 'raw_model_stream_event') continue;
const data = event.data as unknown;
if (isIztroToolEvent(data)) process.stdout.write(`\n iztro computed: ${data.tools.join(', ')}\n`);
else if (event.data.type === 'output_text_delta') process.stdout.write(event.data.delta);
}
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…