Skip to main content
Jade uses Server-Sent Events (SSE) for real-time streaming, giving you instant feedback as AI processes your requests.

How Streaming Works

When you send a message, the SDK:
  1. Opens an SSE connection to the server
  2. Receives events as the AI generates responses
  3. Updates the conversation in real-time
  4. Closes the connection when complete

Streaming State

The useJadeSession hook provides streaming state:

Displaying Streaming Text

Tool Execution Indicator

Cancellation

Cancel an ongoing stream:
Cancellation:
  • 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:
The SDK automatically tracks event IDs internally to resume from the last received event.

Event Types

The SDK handles these SSE event types internally:

Media Generation Events

For media generation, watch for media URLs in tool results:
Or use the onMediaGenerated callback:

Error Handling

Handle streaming errors using the onError 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:

Handle Background State (React Native)

On mobile, pause streaming when the app goes to background:
See App State for more details.