Skip to main content
ChatCLI supports real-time streaming of LLM responses, displaying text character-by-character as it is generated by the API. This significantly improves the user experience by eliminating the wait for complete responses.

StreamingClient Interface

Streaming is implemented as an optional interface that providers can adopt:
Detection is automatic via type assertion — providers that implement StreamingClient receive streaming automatically:
Providers that do not implement StreamingClient continue to work normally. ChatCLI falls back to SendPrompt (complete response) automatically.

StreamChunk

Each streaming chunk carries:

Streaming Contract

  • The channel returns zero or more text chunks
  • The final chunk has Done=true and may include Usage and StopReason
  • If an error occurs, a chunk with Error is sent and the channel closes
  • The channel closes after the final chunk or error
  • The caller can cancel via context

Supported Providers


Stream Watchdog

The Stream Watchdog monitors the stream to detect stalls (interruptions without data) and prevent ChatCLI from hanging indefinitely:
Both timers are reset on each received chunk. If the provider stops sending data for 90 seconds, the watchdog interrupts the stream and returns the accumulated text.

Watchdog Configuration

On slow networks or with providers that have high latency between chunks, increase the timeout to avoid premature interruptions. The default of 90 seconds is sufficient for most scenarios.

Fallback to Non-Streaming

When streaming is not available (provider does not support it or connection error), ChatCLI falls back automatically:
The DrainStream function allows converting a stream into a complete response when needed:

TUI Integration

In interactive mode (Bubble Tea), streaming integrates directly with the renderer:
  • Each chunk is emitted as an event via TUIEmitter
  • The Bubble Tea model updates the view incrementally
  • Markdown is rendered progressively via Glamour
  • The status bar shows the streaming state in real time
In one-shot mode (-p), streaming is disabled and DrainStream is used to collect the complete response before printing.

Next Steps

Context Recovery

What happens when max_tokens is reached during streaming.

Provider Fallback

Fallback chain between providers with and without streaming.

Native Tool Use

Streaming with native tool calls.

Progress UI

Visual indicators during agent streaming.