Skip to main content
The generateStream() method enables real-time token streaming, perfect for building responsive chat interfaces where text appears progressively.

Basic Usage

Method Signature

Parameters

Returns

An LLMStreamingResult containing:

SwiftUI Integration

Basic Streaming View

With Typing Animation Effect

Cancellation

Cancel streaming mid-generation:

Error Handling

Check Streaming Support

Not all models support streaming. Check before calling:

Performance Tips

Instead of updating the UI for every token, batch updates:
For markdown rendering, consider processing the complete text periodically rather than on every token.
For very long generations, consider trimming displayed history to prevent memory issues.

Complete Chat Example

generate()

Non-streaming generation →

System Prompts

Control model behavior →