A ready-to-run example is available here!Enable real-time display of LLM responses as they’re generated, token by token. This guide demonstrates how to use streaming callbacks to process and display tokens as they arrive from the language model.
How It Works
Streaming allows you to display LLM responses progressively as the model generates them, rather than waiting for the complete response. This creates a more responsive user experience, especially for long-form content generation.1
2
Define Token Callback
Create a callback function that processes streaming chunks as they arrive:ModelResponseStream object containing:choices: List of response choices from the modeldelta: Incremental content changes for each choicecontent: The actual text tokens being streamed
3
Register Callback with Conversation
Pass your token callback to the conversation:token_callbacks parameter accepts a list of callbacks, allowing you to register multiple handlers
if needed (e.g., one for display, another for logging).Ready-to-run Example
This example is available on GitHub: examples/01_standalone_sdk/29_llm_streaming.py
examples/01_standalone_sdk/29_llm_streaming.py
The model name should follow the LiteLLM convention:
provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o).
The LLM_API_KEY should be the API key for your chosen provider.Next Steps
- LLM Error Handling - Handle streaming errors gracefully
- Custom Visualizer - Build custom UI for streaming
- Interactive Terminal - Display streams in terminal UI

