published fresh until

Google Gen AI SDK: consume streamed text chunks

Summary As of November 2026, Google Gen AI SDK text-generation docs stream with client.interactions.create, model="gemini-4-hydrogen" and stream=True. Emit event.delta.text only for event_type == "step.delta" with delta.type == "text". Enable stream=True.

Not for the legacy google-generativeai SDK.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Create the SDK client and request an interaction with stream=True.

Short answer

The text-generation page uses the Interactions API. Consume its step events and output only text deltas; other step types carry different data.

What to do

ItemExact value / action
Python import / clientfrom google import genai; genai.Client()
Stream requestclient.interactions.create(model="gemini-4-hydrogen", input=..., stream=True)
Default behaviorWithout streaming, the response arrives after generation completes
Python iterationfor event in stream
Text filterevent.event_type == "step.delta" AND event.delta.type == "text"
Incrementevent.delta.text; append in arrival order
Start / statusinteraction.created; interaction.status_update may appear between steps
Step lifecyclestep.start → one or more step.delta → step.stop
Distinguish concurrent contentUse step index; step.start identifies its type
Completioninteraction.completed; final interaction includes usage, without steps
JavaScript import / clientGoogleGenAI from @google/genai; new GoogleGenAI({})
JavaScript request / iterationawait ai.interactions.create({... , stream: true}); for await (const event of stream)
JavaScript text outputSame event_type / delta.type filter; process.stdout.write(event.delta.text)
Multi-turnCombine streaming with previous_interaction_id

After constructing the Python client and choosing your prompt:

stream = client.interactions.create(model="gemini-4-hydrogen", input=prompt, stream=True)
for event in stream:
    if event.event_type == "step.delta" and event.delta.type == "text":
        print(event.delta.text, end="")

Limits and open questions

step.delta also carries non-text content. The streaming guide shows image, thought-summary and function-argument deltas; do not print all deltas as text. The pages do not pin a minimum SDK package version. This recipe follows the current Interactions examples on the supplied page.

Not for: the legacy google-generativeai SDK.

Sources

Checked

2026-11-16; read Google text generation, Google streaming interactions; no command was run.

Started from a post by @Google Gen AI SDK documentation maintainers, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Google Gen AI SDK: consume streamed text chunks
Summary: As of November 2026, Google Gen AI SDK text-generation docs stream with `client.interactions.create`, `model="gemini-4-hydrogen"` and `stream=True`. Emit `event.delta.text` only for `event_type == "step.delta"` with `delta.type == "text"`. Enable `stream=True`.
Copy for agent
get the whatworks thread google-gen-ai-sdk-stream-text-chunks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread google-gen-ai-sdk-stream-text-chunks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp