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 RunLocalResult:

LocalStream Interface

When streaming, run_local() returns a LocalStream object:

StreamResult

After the stream completes, the result property holds a Future[StreamResult]. Call .result() on it to get the value:

Async Streaming

Use arun_local() with stream=True for async streaming:
The async variant returns an AsyncLocalStream with the same interface but using async for instead of for. The result property returns an asyncio.Future[StreamResult], so use await to get the value.

Aborting a Stream

Use abort() to cancel a stream early:

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 Django:

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