Skip to content
View original post on X: Google Cloud TechOfficial· Pick78/100AI score78/100

Developer guide to Gemini 4 Argon Long Decode

AISummary

Google Cloud Tech explains how Long Decode lets Gemini 4 Argon return completions up to 1M tokens by splitting one generation across several model inferences.

Developers can enable it through the latest Gen AI SDKs or by manually handling a continuation_token, with max_output_tokens set above 65,536 for streaming or 32,768 for unary requests.

The post also notes that billing for completions above 32K tokens starts November 13, 2026.

AIWhy it matters

The guide shows how Long Decode splits one long generation across requests, with the SDK setup and continuation rules a developer needs to implement it.

Post on XView on X
Google Cloud TechVerified on X
@GoogleCloudTech

https://x.com/i/article/2110084650546987008

Developer guide to Gemini 4 Argon Long Decode

Gemini 4 Argon is able to reason for longer to solve complex math, science, coding, and agentic problems, and comes with an updated unified input and output limit of 1M tokens.

When the model is reasoning on complex problems it is more likely to generate completions for longer than a synchronous HTTP request reliably stays open. To solve this problem, we are introducing a set of features to the Gemini API to enable Long Decode with Gemini 4.

Long Decode enables developers to get long completions from Gemini 4 by splitting a generation across several model inferences.

Developers can enable Long Decode on the Gemini platform and Gemini API using the GenerateContent API and the latest version of the Google Gen AI SDKs, which enable developers to get one long generation instead of handling several requests manually. Support for Long Decode in the Interactions API on Gemini platform is coming soon.

Overview

Why Long Decode exists: Gemini 4 Argon works longer and harder for developers’ most complex tasks. In such cases, generating long completions can take longer than a single HTTP connection can reliably stay open. Long Decode enables developers to get completions up to 1M tokens long across multiple inferences. Note that 1,048,576 is the overall token limit of the model and includes both the input and output tokens.

How Long Decode works: For example, the model is completing a task that will require 256K output tokens, which includes thoughts, function calls, and the final response.

- The first request will result in 64K output tokens (when streaming). At the end of this request, the API will emit a continuation_token. The continuation_token is an encrypted string containing a hash of the original prompt and generation up until this point.

- If the continuation_token is included in the subsequent request, the model will continue the completion from where it left off in the previous request, generating the next 64K thinking and output tokens. At the end of the second response, another continuation_token will be emitted.

- The client is expected to include the continuation_token in all subsequent requests until it is no longer emitted and when the finishReason=STOP (GenerateContent API).

Supported surfaces:

- Long Decode is supported on the Gemini platform and Gemini API using the GenerateContent API and the latest version of the Google Gen AI SDKs.

- Agent Studio: Automatically handles long decodes when output token limit is set above 64K (up to 1M).

Default output limit: To ensure developers do not experience unwanted long completions the platform enforces a default output limit of 64K thinking and output tokens in a single request, with a few exceptions:

- Non streaming, direct HTTP requests: The default output (thinking + model response) limit is 32K tokens.

How to Enable Long Decode

Long Decode is not enabled by default. However, Gemini 4 is more prone to reasoning for longer to complete tasks. Disabling Long Decode may result in greater rates of incomplete generations (finishReason=MAX_TOKENS in GenerateContent API) than previous models. There are 2 paths to enabling Long Decode in the API.

Path 1 (Recommended): Using the GenAI SDK

The GenAI SDK automatically handles the continuation_token across requests. Developers effectively send a single request to receive a complete long decode.

- Step 1: Upgrade to the latest Gen AI SDKs: Python (google-genai) 2.30.1, JavaScript (@google/genai) 2.29.1, Go 1.74.0, Java 1.77.0, .NET 1.26.0, and Kotlin 1.6.0.

Limitations:

Outdated GenAI SDK versions: Developers using GenerateContent (Unary) with an older version of the Google Gen AI SDK will not be able to access the 1M option, and should upgrade to a newer version

- Open AI Compatibility Layer: Developers may not be able to retrieve long completions using the Open AI SDK to access Gemini 4.

- Step 2: In the generationConfig, specify max_output_tokens to a value above 65,536 (up to 1,048,576) for streaming requests or above 32,768 (up to 1,048,576) for unary requests. This is the token cap of the entire generation.

Path 2: Update client to manually generate long completions using the continuation_token.

- Step 1: In the generationConfig, specify max_output_tokens to a value above 65,536 (up to 1,048,576) for streaming requests or above 32,768 (up to 1,048,576) for unary requests. This is the token cap of the entire generation.

- Step 2: Update client code to handle continuation_tokens by including them in the subsequent request when they are present. The subsequent request should contain the original prompt and the continuation token. The previously generated output does not need to be included in the subsequent request.

Notes:

- max_output_tokens does not control how much a model will reason to complete a task. Use thinkingLevels to control how much the model reasons.

- Zero Data Retention (ZDR): Long Decode using streamGenerateContent or generateContent is ZDR compliant. Intermediate state is passed encrypted inside continuation_token without server storage.

- Compaction in Agent Harnesses: Since Long Decode generates partial completions over requests, the partial completions must be included as input tokens in subsequent requests to continue the completion. Users will see promptTokenCount (GenerateContent API) increase cumulatively over turns to reflect this. Developers should not use the promptTokenCount field to trigger compaction. Instead, use initial_prompt_token_count from the Gen AI SDK, which accurately reflects how much context a long completion is using in the model’s context window. Additionally, compaction should wait until a GenerateContent call completes - on't compact while a continuation token is present.

When to Use Long Decode

Most requests finish within the per-request limit (64K, 32K non-streaming REST calls). Use long decode only when one response needs more output than that. Long decode gives the model more room to reason. It does not make answers longer.

Choosing a Continuation Option

Choose one of two options. Most developers use option 1. All modes reach the same 1M-token limit.

Quickstart

Try it in Agent Studio

1. Open Agent Studio in your Google Cloud project and select gemini-4-argon.

1. In Model settings, set Output token limit between 32,768 and 1,048,576 (1M default) and choose a Thinking level (Low, Medium, or High).

1. Submit your prompt. Agent Studio handles continuation tokens automatically for responses over 32K tokens.

Option 1: Use the Gen AI SDK (Recommended)

Replace PROJECT_ID with your Google Cloud Project ID.

Option 2: Client-Side Continuation with GenerateContent

streamGenerateContent and generateContent continue past single-request caps using continuation_token (continuationToken in REST) and custom client implementations will require users to manually handle the continuation_token for long decodes. To implement, refer to the Gen AI SDK’s reference implementation.

Important: Do not append partial model output into contents or send a follow-up user prompt asking the model to continue. continuation_token preserves internal reasoning state, thought signatures, and tool calls across hop boundaries. Resend the original contents array plus continuation_token on each hop.

Rules for Client-Side Continuation

1. Resend the original request payload: Pass the original contents, system_instruction, and tools on every hop along with the latest continuation_token.

1. Read continuation_token and usage_metadata at the end of each hop: At launch, streamGenerateContent and generateContent return candidate.continuation_token and usage_metadata at the end of each hop (64K streaming / 32K unary). Starting November 13, 2026, streamGenerateContent will also emit checkpoints with continuation_token and usage_metadata at 32K tokens and every 5K tokens thereafter (37K, 42K, ... 64K).

1. Continue through thinking-only hops: Loop while finish_reason is CONTINUATION and continuation_token is present, even if a hop spent all 32K or 64K tokens thinking (parts: [{"text": ""}]). If finish_reason is MAX_TOKENS (MAX_OUTPUT) when continuation_token is present, Long Decode was not enabled or reached the requested max_output_tokens cap—omit max_output_tokens (or raise it) in the request.

1. Combine parts after STOP: Merge all accumulated parts across hops into a single model turn for multi-turn conversation history only after the final hop

Example:

Token Counting, Caching & Billing

Every token processed by the model is billed across continuation hops:

Notes:

- Warning: Within a single streamGenerateContent stream, chunk.usage_metadata reports cumulative counts for that hop so far, not per-chunk deltas. Overwrite your per-hop counter when a chunk with continuation_token or finish_reason arrives, and add each hop's final count to total_generated_tokens only when advancing to the next hop.

- Incremental Output: Output and thinking tokens are incremental per hop; summing each hop's final output and thought counts gives total generated tokens.

- Re-Prefilled Input & 95% Implicit Cache Discount: Each continuation hop re-prefills the prompt plus all prior decoded tokens. On the Gemini platform, Implicit Context Caching automatically discounts shared prefixes of 6,000 tokens or more by 95% ($0.10 / 1M tokens vs. $2.00 / 1M uncached during the introductory period; $0.20 / 1M vs. $4.00 / 1M standard).

- Cache Expiration: Implicit cache entries expire after 15–20 minutes of inactivity. Run client-side continuation hops back-to-back so prior hops hit the cache.

- Upcoming changes to Billing (Gemini platform): Gemini 4 can generate completions up to 1 million tokens in length. The GenerateContent API will begin charging for completions exceeding 32K tokens, and then every 5K tokens afterward. This will take effect on November 13 2026. Until then, Long Decode requests will be billed only at the end of a request.

Troubleshooting

Developer Checklist

- SDK Version: Upgrade to the latest Gen AI SDKs: Python (google-genai) 2.30.1, JavaScript (@google/genai) 2.29.1, Go 1.74.0, Java 1.77.0, .NET 1.26.0, and Kotlin 1.6.0.

- Continuation Mode: Use streamGenerateContent with 5K checkpoints for streaming workloads, or generateContent (handled automatically in the Gen AI SDK) for unary workloads.

- Budget & Thinking Level: Set max_output_tokens between 32,768 and 1,048,576 (1M - input_tokens) and set thinking_level (LOW, MEDIUM, HIGH). Remove thinking_budget.

- Resend Original Payload (GenerateContent): Pass the original contents array plus continuation_token on each hop; do not append partial model output into contents.

- Timeouts & Cache Reuse: Set HTTP read timeouts to 15–20 minutes for streaming hops, and run client-side hops back-to-back to hit the 95% Implicit Context Caching discount (>= 6K tokens).

Additional Resources

- Agent Studio

- Documentation

Source: Google Cloud Tech · x.comPublished · added here