Important: Streaming is automatically disabled when
autoTurn
(Conversational Turns) is enabled. The SDK will use non-streaming mode to properly handle response splitting and natural conversation flow. Choose either streaming OR conversational turns based on your use case.Basic Streaming
Using AsyncIterable Pattern
Stream responses using the modern AsyncIterable pattern:Real-time UI Updates
Here’s how to implement streaming in a web application:Advanced Streaming Features
Streaming with Reasoning
Whenreasoning
is enabled, thinking content appears directly in the stream:
Streaming with Custom Processing
You can implement custom processing for different types of content:Streaming Limitations
Compatibility with Other Features
Streaming is NOT compatible with:autoTurn
(Conversational Turns) - The SDK automatically disables streaming when autoTurn is enabledcompliance
checks - Content moderation is not available for streaming responses
reasoning
- Thinking content appears in the streamcheck_image_generation
- Image prompts can be detected in streaming responses- All standard chat parameters (temperature, max_tokens, etc.)
Error Handling
Implement robust error handling for streaming:Performance Optimization
Throttling Updates
For better performance, throttle UI updates:Buffering Strategy
Implement smart buffering for smoother display:Best Practices
When to Use Streaming vs Conversational Turns
Use Streaming for:- Long-form content generation (stories, articles, explanations)
- Real-time code generation
- When you want immediate character-by-character display
- Applications where you control the entire response flow
- Natural chat interfaces that mimic human conversation
- When you want automatic response splitting
- Applications that benefit from realistic typing delays
- Chat apps where the AI should feel more human-like
UI/UX Considerations
- Visual feedback: Show a typing indicator or cursor
- Graceful degradation: Fallback to non-streaming on errors
- Performance: Throttle updates for smooth rendering
- Accessibility: Announce streaming status to screen readers