Instead of waiting for a complete response, you can stream text tokens from Gemini as they are generated. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/google/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/google package uses Server-Sent Events (SSE) under the hood — it appends ?alt=sse to the interactions URL so that Gemini emits a stream of JSON delta events. The SDK parses each event and yields typed StreamPart objects that your application can consume one at a time. Tokens arrive as TextDeltaPart events, making it straightforward to echo output to users progressively.
Basic Streaming Example
Call->stream() instead of ->run(). You get back a stream handle. Iterate $stream->chunks() to receive each text delta as a plain string, then call $stream->run() once the loop is done to get the final TextModelResponse with complete usage data.
->chunks() is a convenience wrapper that filters the raw part stream and yields only the text content of each TextDeltaPart. For full control over every event type, iterate the raw parts directly (see below).
Stream Parts
Every event yielded by the underlyingGenerator is a StreamPart instance. The following part types are emitted by the Google provider:
TextDeltaPart
A fragment of the model’s text output. These arrive in order and can be concatenated to reconstruct the full response.
ReasoningDeltaPart
A fragment of the model’s internal reasoning or “thinking” output. Only emitted by thinking-capable models (e.g. gemini-3.5-flash with reasoning enabled). These deltas arrive interleaved with or before the main text deltas.
ToolCallStartPart / ToolCallDeltaPart
Emitted when the model decides to call a tool. ToolCallStartPart signals a new call and carries the tool’s index, ID, and name. ToolCallDeltaPart follows immediately with the JSON-encoded arguments.
ProviderMetadataPart
Carries raw Gemini metadata — id, model, finish_reason, and usage_metadata — extracted from the final SSE event. The provider key is always 'google'.
FinishPart
Always the last part yielded. Contains the normalised FinishReason enum value and a Usage object with final token counts accumulated across all SSE events.
Iterating Raw Parts
When you need to handle tool calls, reasoning deltas, or metadata in addition to text, iterate the stream as aGenerator and switch on the part type:
Final Result After Streaming
After the loop, call$stream->run() to retrieve a TextModelResponse that aggregates everything collected during streaming. It exposes the same properties as a non-streaming response:
When a
function_call delta is detected during streaming, the SDK immediately sets the FinishReason to ToolCalls — even before the FinishPart is emitted — so downstream consumers can detect tool-call responses as early as possible. The FinishPart at the end of the stream will also carry FinishReason::ToolCalls.