Skip to main content
Enable streaming to receive LLM responses as they’re generated, providing a more responsive user experience.

Basic Streaming

Set stream: true to get a LocalStream instead of a Promise:

LocalStream Interface

When streaming, runLocal() returns a LocalStream object:

StreamResult

After the stream completes, the result promise resolves to:

Aborting a Stream

Use abort() to cancel a stream early:

Using AbortSignal

Pass an AbortSignal to integrate with your application’s cancellation logic:

Streaming with Tool Calls

Streaming works with tool calling. Tool calls are available in the final result:

Example: HTTP Streaming Response

Stream directly to an HTTP response in Next.js or Express:

Provider Support

Streaming is supported by all providers:

Spans and Streaming

Spans are submitted after the stream completes (or is aborted):
  • The span includes the complete response text accumulated during streaming
  • Token usage is captured from the stream’s final usage event
  • If aborted, the span records the partial response
  • Span submission is still non-blocking and asynchronous