SDK quickstart
The Agent SDK solves the repeated work of calling a model, carrying conversation history, parsing streaming events, and wiring application tools into every product. It gives Python and TypeScript developers one Agent runtime with persistent sessions, streaming, tools, and MCP support.
This is the recommended starting path: install the SDK, bind a ChatSession to a business user ID, and stream an answer without manually rebuilding the conversation context on every request.
This page uses iztro-ziwei-v3. All four public models support one-off requests and ongoing conversations. See Use cases and models for customer details and prompt examples.
iztro-ziwei-v3 and iztro-qimen-v3 enable thinking by default; their -fast variants disable it. Override the default with the Agents SDK's ModelSettings.reasoning / modelSettings.reasoning: high enables thinking and none disables it. See Model settings.
1. Install
- Python
- TypeScript
pip install openai-iztro-agents
export ZIWEI_API_KEY="sk_ziwei_..."
npm install openai-iztro-agents @openai/agents
export ZIWEI_API_KEY="sk_ziwei_..."
The SDK reads ZIWEI_API_KEY automatically. Keep it in your backend environment or secret manager; never expose it in browser code.
On PowerShell, set the same variable with $env:ZIWEI_API_KEY="sk_ziwei_...".
2. Why use ChatSession
ChatSession keeps a conversation associated with your application user. Pass your own stable external_user_id—for example, the ID from your users table—and you can find that user's sessions without copying chart data or conversation history into every request.
The same identifier lets your backend manage the user's conversations: list sessions, open one session, read its messages, edit or resend a message, and apply retention or deletion policies. See ChatSession management for the complete lifecycle.
3. Stream a complete ChatSession request
The example below is intentionally self-contained. It creates or resumes a session for user_42, sends one request, and prints the streamed text as it arrives.
- Python
- TypeScript
import asyncio
from agents import Runner
from openai.types.responses import ResponseTextDeltaEvent
from iztro_agents import ChatSession, IztroToolEvent, iztro_ziwei_agent
PROMPT = "I was born on 1990-12-21 at 13:00, female. Please analyze my relationship and marriage timing from 2026 to 2028."
async def main():
agent = iztro_ziwei_agent()
session = ChatSession(external_user_id="user_42")
result = Runner.run_streamed(agent, PROMPT, 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="")
print("\nSession:", session.session_id)
asyncio.run(main())
import {run} from '@openai/agents';
import {
ChatSession,
isIztroToolEvent,
iztroZiweiAgent,
} from 'openai-iztro-agents';
const agent = iztroZiweiAgent();
const session = new ChatSession({externalUserId: 'user_42'});
const result = await run(agent, 'I was born on 1990-12-21 at 13:00, female. Please analyze my relationship and marriage timing from 2026 to 2028.', {session, stream: true});
for await (const event of result) {
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);
}
console.log('Conversation:', session.sessionId);
The next pages explain the same pieces separately: ChatSession, streaming, non-streaming, tools, and MCP.
Model functions
Use the function matching the model you want to call:
| Model | Python | TypeScript |
|---|---|---|
iztro-ziwei-v3 | iztro_ziwei_agent(...) | iztroZiweiAgent({...}) |
iztro-qimen-v3 | iztro_qimen_agent(...) | iztroQimenAgent({...}) |
iztro-ziwei-v3-fast | iztro_ziwei_fast_agent(...) | iztroZiweiFastAgent({...}) |
iztro-qimen-v3-fast | iztro_qimen_fast_agent(...) | iztroQimenFastAgent({...}) |
Real example: 01_hello_ziwei.py
This is the complete first-run example from the Python SDK repository. It supplies birth details, runs the Agent, reports the Iztro chart tool, and prints the full reading. The recorded output is shown inline below.
Source: examples/01_hello_ziwei.py.
Prompt used for this run
I was born on 1990-12-21 at 13:00, female. Please give me a detailed reading of my personality and life pattern.
Complete recorded output
Loading recorded output…