Streaming
Streaming allows you to receive AI-generated content incrementally as it’s produced, creating responsive user experiences without waiting for the complete response.Basic Text Streaming
Stream text as it’s generated:Streaming Flows
Create flows that stream responses:Streaming Structured Data
Stream type-safe JSON objects as they’re being generated:Streaming Flow with Structured Output
Server-Sent Events (SSE)
When serving flows over HTTP, Genkit automatically streams responses using Server-Sent Events:Passthrough Streaming
Pass streaming chunks directly from the model to the client:Durable Streaming (Experimental)
Allow clients to reconnect to in-progress or completed streams:X-Genkit-Stream-Id header and can reconnect to replay buffered chunks.
See the durable-streaming sample for a complete example.
Best Practices
Use Streaming for Long Responses
Stream responses when generating long-form content to improve perceived performance:- Stories, articles, or essays
- Detailed explanations
- Code generation
- Multi-paragraph summaries
Handle Errors Gracefully
Always check for errors in streaming loops:Go
Consider Network Conditions
Streaming works best with stable connections. For unreliable networks, consider:- Using durable streaming with reconnection support
- Buffering chunks before sending to the client
- Falling back to non-streaming for small responses
Next Steps
- Learn about Tool Calling for interactive workflows
- Explore Chat Interfaces for conversational apps
- Check out Flows for deployment patterns