How Streaming Works
When you send a message, the SDK:- Opens an SSE connection to the server
- Receives events as the AI generates responses
- Updates the conversation in real-time
- Closes the connection when complete
Streaming State
TheuseJadeSession hook provides streaming state:
Displaying Streaming Text
Tool Execution Indicator
- React / Next.js
- React Native
Cancellation
Cancel an ongoing stream:- Immediately stops receiving events
- Sends a cancel signal to the server
- Preserves partial conversation state
Reconnection
If a connection drops, you can reconnect to an existing session:Event Types
The SDK handles these SSE event types internally:Media Generation Events
For media generation, watch for media URLs in tool results:onMediaGenerated callback:
Error Handling
Handle streaming errors using theonError callback:
Best Practices
Debounce UI Updates
For very fast streams, consider debouncing UI updates:Show Progress for Long Operations
Media generation can take time. Show progress:- React / Next.js
- React Native