For Agent tasks that require long generation without keeping the client connected, use the Interactions API with background=True to start server-managed long decoding, then check its status with the Interaction ID. This mode requires store=True.
Suitable tasks: Generating very long reports, code, or proofs; asynchronous Agent jobs submitted through a task queue and queried later.
Unsuitable tasks: Tasks that need a short result immediately, or workflows that require the server not to store the Interaction.
Supported model version: gemini-4-hydrogen.
Supported client, Agent, or API: Google Cloud Gemini Enterprise Agent Platform Interactions API; Python Google Gen AI SDK.
Recommended reasoning level and parameters: For long decoding, set max_output_tokens above 65,536, up to a maximum of 1,048,576 minus the input token count; the example uses HIGH. Input and output share a 1,048,576-token limit.
The example below starts a background Interaction and polls until it finishes. Replace PROJECT_ID with your Google Cloud project ID. Before making the call, authenticate with Agent Platform using ADC or an API key.
import time
from google import genai
client = genai.Client(
enterprise=True,
project="PROJECT_ID",
location="global",
)
interaction = client.interactions.create(
model="gemini-4-hydrogen",
input="Write a complete system migration implementation plan, including risks, rollback steps, and acceptance criteria.",
background=True,
store=True,
generation_config={
"max_output_tokens": 256000,
"thinking_level": "high",
},
)
while interaction.status in ("queued", "in_progress"):
time.sleep(10)
interaction = client.interactions.get(id=interaction.id)
print(f"Status: {interaction.status}")
print(interaction.output_text)Install or upgrade the SDK:
pip install --upgrade "google-genai>=2.34.0"Set up Agent Platform access in your Google Cloud project and authenticate with ADC or an API key.
Install google-genai version 2.34.0 or later. The Interactions API in this version supports automatic SDK continuation; background mode is continued by the server.
When creating the Interaction, set background=True and store=True, and set max_output_tokens to a budget greater than 65,536.
Save the returned Interaction ID. While the background job runs, poll for the queued or in_progress status using client.interactions.get(id=...).
When the task finishes, check its status and read output_text. To stop a task, cancel the background Interaction; after a checkpoint is reached, the service saves a continuation_token so execution can resume from that point.
Google's Cloud documentation example for background mode explicitly uses background=True, store=True, and max_output_tokens=256000, and calls interactions.get() every 10 seconds while the status is queued or in_progress.
In background mode, continuation is handled by the Agent Platform server, so the client does not need to keep a single request stream open. This mode requires the Interaction to be stored; the default server-side retention period is 7 days.
In background mode, a canceled task can resume from a checkpoint. Checkpoints are saved starting after 65,536 decoded tokens, then every additional 5,000 tokens.
Long decoding on Agent Platform is supported only on v1beta1. The Google Gen AI SDK uses v1beta1 by default; long decoding is unsupported if you explicitly switch to v1.
Source: Gemini 4 Hydrogen developer guide, page last updated 2026-11-12 UTC.
background=True requires store=True, so it is unsuitable for workflows that prohibit server-side storage. The Interactions API's stateless mode requires store=False, with the caller managing continuation.
max_output_tokens counts thinking, tool calls, and the final answer. The combined input and output limit is 1,048,576 tokens, and the limit for a single foreground output segment is 65,536 tokens; server-managed background continuation can complete long output across segments.
Long decoding is supported only on Agent Platform v1beta1. Do not override the SDK's API version to v1 when deploying.
Interactions are retained for 7 days by default; handle job records according to the task's data-retention requirements. The source example also shows how to delete segments in reverse order.
The documentation labels Hydrogen as a short-cycle GA model and says retirement will be announced at least 45 days in advance; monitor model lifecycle announcements for production workflows.
Start a background Interaction using the example, then confirm that the initial creation returns an Interaction ID, the in-progress status can be queried, and the output can be read when the task finishes. To verify cancellation and resumption, call the cancellation endpoint while the task is running, then use the returned continuation_token and that Interaction to create a continuation request. This article summarizes the documented configuration steps; the request was not run in an actual Google Cloud project.
Gemini 4 Hydrogen