Skip to main content

Overview

Streaming allows you to receive responses token-by-token as they’re generated, providing a better user experience for long responses and enabling real-time feedback.

Basic Streaming

Server-Sent Events (SSE) Format

When streaming, switchAILocal sends data in SSE format:

Streaming with CLI Providers

CLI providers like Gemini, Claude, and Vibe support streaming:

Collecting Streamed Content

Accumulate the full response while streaming:

Streaming with Callbacks

Python with Custom Handler

JavaScript with Event Emitter

Streaming Long Outputs

For very long responses, streaming is essential:

Streaming with Multiple Providers

Test streaming across different providers:

Error Handling in Streams

Streaming with CLI Attachments

Combine streaming with file attachments:

Measuring Stream Performance

Raw SSE Parsing (Advanced)

For custom HTTP clients:

When to Use Streaming

Use streaming when:
  • Generating long-form content (essays, stories, code)
  • Building real-time chat interfaces
  • Providing user feedback during processing
  • Working with CLI providers that support streaming
Avoid streaming when:
  • You need the complete response for processing
  • Response is very short (<50 tokens)
  • Implementing retry logic (harder with streams)

Streaming Support by Provider

Next Steps

Basic Usage

Learn the fundamentals

Multi-Provider

Advanced routing patterns

Intelligent Routing

Auto-routing with Cortex

Python SDK

Complete SDK reference