Streaming Response Behavior
Learn how Optave's streaming responses work and how to handle real-time AI-generated content in your application.
Enabling Streaming
To receive streaming responses, you need to configure the disableStream setting in your request:
const interactionParams = {
request: {
settings: {
disableStream: false, // Enable streaming (default is true)
// ... other settings
},
// ... other request configuration
}
};
const response = await client.interaction(interactionParams);
Important: Streaming is disabled by default (disableStream: true). Set disableStream: false to receive real-time updates as the AI model generates the response.
Streaming Interval
- Interval: 500ms (0.5 seconds)
- First Message: Sent after the first 500ms once content is available
- Subsequent Messages: Sent every 500ms while the AI model is generating the response
Message Content Type
- Cumulative/Complete: Each streamed message contains the full accumulated response from the beginning, not just the new delta/chunk
- Progressive Updates: The client receives increasingly complete versions of the response with each message
- Final Message: After streaming completes, a final message is sent with any remaining buffered content
Technical Implementation
The streaming process works as follows:
- AI model chunks are received and accumulated into a buffer
- Every 500ms, if the buffer contains content, the entire accumulated response is sent to the client via WebSocket
- The buffer continues to grow with each new chunk from the AI provider
- When streaming completes, any final content is sent immediately
Example Flow
Time 0ms: Streaming starts
Time 500ms: Message 1 sent: "Hello, how can"
Time 1000ms: Message 2 sent: "Hello, how can I help you today"
Time 1500ms: Message 3 sent: "Hello, how can I help you today? I'm here to"
...
Stream ends: Final message sent with complete response
Note: Each message replaces the previous one completely - clients should not concatenate messages, but rather display the latest message received.