Skip to main content

Streaming API

The streaming API provides real-time access to model responses as they are generated. This enables building responsive UIs and handling partial results before the full response is complete.

Streaming vs Complete

Two ways to interact with models:

Event Types

All events emitted during assistant message generation:

Basic Streaming

Streaming with Tool Calls

Partial Tool Arguments

During streaming, tool arguments are progressively parsed as they arrive:
Important notes:
  • During toolcall_delta, arguments contains best-effort parse of partial JSON
  • Fields may be missing, incomplete, or truncated mid-word
  • Arrays and nested objects may be partially populated
  • At minimum, arguments will be an empty object {}, never undefined
  • Google provider does not support function call streaming - you get a single toolcall_delta with full arguments

Streaming Thinking/Reasoning

Models with reasoning capabilities emit thinking events:

Stop Reasons

Every completed stream includes a stop reason:

Error Handling

Aborting Requests

Cancel in-progress requests with an abort signal:

Continuing After Abort

Aborted messages can be added to context and continued:

Stream Options

Common options for streaming requests:

Simplified Streaming API

For reasoning-capable models, use streamSimple with unified options:
Reasoning levels:
  • minimal - Very quick, basic reasoning
  • low - Quick reasoning
  • medium - Balanced reasoning (default)
  • high - Deep reasoning
  • xhigh - Maximum reasoning (OpenAI only, maps to high on other providers)
See Thinking/Reasoning for details.

Usage and Cost Tracking

Next Steps

Tools

Learn about tool calling and validation

Thinking

Enable reasoning capabilities