Basic Streaming
Useexecute() (or stream()) for streaming responses:
Stream Types
Text Stream
Stream generated text as it’s produced:Full Stream
Access all events including tool calls:UI Message Stream
Stream UI-compatible messages:Getting Final Results
Final Text
Usage Information
Sources (if available)
Streaming with Structured Output
Stream partial structured output:Swarm Streaming
For multi-agent systems, useswarm() to handle handoffs:
Abort Streaming
Cancel ongoing streams:Custom Stream Processing
Transform Streams
Apply custom transformations:Process Tool Calls
Streaming Utilities
Last Helper
Get the last item from a stream:Printer Utility
Print streams to stdout:Real-World Example
Streaming to Files
Write streams directly to files:Error Handling
Handle errors in streams:Best Practices
Consume Streams Fully
Consume Streams Fully
Always consume streams completely to avoid memory leaks:
Handle Errors Gracefully
Handle Errors Gracefully
Wrap stream processing in try-catch:
Use Abort Signals
Use Abort Signals
Provide abort signals for long-running streams:
Monitor Usage
Monitor Usage
Track token usage to manage costs:
Next Steps
API Reference
Full API documentation
Execution Functions
execute(), generate(), swarm() API