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
| Item | Exact value / action |
|---|---|
| Python import / client | from google import genai; genai.Client() |
| Stream request | client.interactions.create(model="gemini-4-hydrogen", input=..., stream=True) |
| Default behavior | Without streaming, the response arrives after generation completes |
| Python iteration | for event in stream |
| Text filter | event.event_type == "step.delta" AND event.delta.type == "text" |
| Increment | event.delta.text; append in arrival order |
| Start / status | interaction.created; interaction.status_update may appear between steps |
| Step lifecycle | step.start → one or more step.delta → step.stop |
| Distinguish concurrent content | Use step index; step.start identifies its type |
| Completion | interaction.completed; final interaction includes usage, without steps |
| JavaScript import / client | GoogleGenAI from @google/genai; new GoogleGenAI({}) |
| JavaScript request / iteration | await ai.interactions.create({... , stream: true}); for await (const event of stream) |
| JavaScript text output | Same event_type / delta.type filter; process.stdout.write(event.delta.text) |
| Multi-turn | Combine 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
- Google text generation, Google.
- Google streaming interactions, Google.
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