Overview
stream_text is an async iterator for low-latency streaming text generation. It provides real-time access to tokens as they’re generated, with optional callbacks for chunk processing, error handling, and completion.
Basic usage
1
Kick off the request
2
Consume the async iterator
await stream_res.text() once to get the full text.Parameters
Return value
stream_text returns a StreamTextResult with:
text_stream: Async iterator yielding text chunkstext(): Async method to get the complete textusage: Token usage statisticsfinish_reason: Why the stream endedtool_calls: Tool calls if any were made
Examples
Basic streaming
With callbacks
With system instruction
With custom parameters
Tool-calling with streaming
See the dedicated Tool page for a complete walkthrough.