Argon 的 Long Decode 按 64K-token hop 后台续接;需要 background: true 和大于 65,536 的输出额度。输入、思考和输出共享上下文,各 hop 都计费。
适合的任务:需要超过 64K tokens 的复杂数学、科学、研究、形式化证明,以及最难的编码和 Agent 任务;也适合评测工具不会在输出上限处截断的任务。
不适合的任务:聊天、问答、摘要、分类和抽取等通常低于 32K tokens 的任务;固定长度写作;多轮短工具调用 Agent;接近输入上限的提示;对延迟敏感的请求。Long Decode 可能运行数分钟。
适用的模型版本:Gemini 4 Argon,模型 ID gemini-4-argon。
适用的客户端、Agent 或 API:Interactions API 的后台执行;GenerateContent API 的客户端 continuation。Interactions API 的客户端自行续接在页面中标记为 coming soon;本页还提供 Python、JavaScript 和 REST 示例。
推荐的推理档位和参数:Long Decode 必须使用 background: true,并将 max_output_tokens 设为大于 65,536;复杂推理从 262,144 开始,最高为 1,048,576 减去输入 tokens。页面建议最难推理使用 thinking_level: "high",多数编码和 Agent 任务使用默认的 medium;降低 thinking_level 可减少 token 使用。
Gemini 4 Argon 的 Long Decode 在 Interactions API 中按以下流程运行:
创建 background: true 的 interaction,并设置大于 65,536、最高 1,048,576 的 max_output_tokens。
服务器先生成最多 64K tokens 的第一个 hop。
如果还没有完成,服务器从上一个 hop 停止处继续生成下一个 64K hop,直到模型完成或用完 max_output_tokens。
每个 hop 都在同一个 interaction ID 下新增一个 model_output step 到 interaction.steps。
轮询 interaction 或使用流式传输;读取全部 model_output steps 并拼接文本,得到完整响应。
import time
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-4-argon",
input="Write a complete, rigorous proof of the prime number theorem.",
background=True,
generation_config={
"max_output_tokens": 262144,
"thinking_level": "high",
},
)
while interaction.status in ("in_progress", "queued"):
time.sleep(5)
interaction = client.interactions.get(id=interaction.id)
# Each hop adds a model_output step, so join the text of all of them.
text = "".join(
content.text
for step in interaction.steps
if step.type == "model_output"
for content in step.content
if content.type == "text"
)
print(text)
print("Status:", interaction.status)
print("Usage:", interaction.usage)import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
let interaction = await client.interactions.create({
model: "gemini-4-argon",
input: "Write a complete, rigorous proof of the prime number theorem.",
background: true,
generation_config: {
max_output_tokens: 262144,
thinking_level: "high",
},
});
while (interaction.status === "in_progress" || interaction.status === "queued") {
await new Promise((resolve) => setTimeout(resolve, 5000));
interaction = await client.interactions.get(interaction.id);
}
// Each hop adds a model_output step, so join the text of all of them.
const text = interaction.steps
.filter((step) => step.type === "model_output")
.flatMap((step) => step.content ?? [])
.filter((content) => content.type === "text")
.map((content) => content.text)
.join("");
console.log(text);
console.log("Status:", interaction.status);
console.log("Usage:", interaction.usage);# 1. Create the background interaction. It returns an ID right away.
ID=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-4-argon",
"input": "Write a complete, rigorous proof of the prime number theorem.",
"background": true,
"generation_config": {"max_output_tokens": 262144, "thinking_level": "high"}
}' | jq -r '.id')
# 2. Poll until the status is no longer in_progress or queued.
# The REST response has no output_text field, so join the text of every model_output step.
while true; do
RESP=$(curl -s "https://generativelanguage.googleapis.com/v1beta/interactions/$ID" \
-H "x-goog-api-key: $GEMINI_API_KEY")
STATUS=$(echo "$RESP" | jq -r '.status')
if [[ "$STATUS" != "in_progress" && "$STATUS" != "queued" ]]; then
echo "$RESP" | jq -r '[.steps[]? | select(.type == "model_output") | .content[]? | select(.type == "text") | .text] | join("")'
echo "$RESP" | jq '{status, usage}'
break
fi
sleep 5
done| 运行方式 | 输出上限 |
|---|---|
background: false(流式或非流式) | 65,536 tokens;大于 65,536 会返回 400 错误,Long Decode 尚未可用 |
background: true,未设置 max_output_tokens | 65,536 tokens |
background: true,max_output_tokens 大于 65,536 | 使用设置的 max_output_tokens,最高为 1,048,576 减去输入 tokens |
Long Decode 必须显式将 max_output_tokens 设为大于 65,536;还要检查 Agent framework 或评测工具中的同名设置。较低的值(例如 8,192)可能在模型完成思考前就停止响应。
| 配置 | 后台执行(Interactions API) | 客户端 continuation(GenerateContent API) |
|---|---|---|
| 每个 hop 的发起者 | Google 服务器 | Google GenAI SDK 或自己的代码 |
| 每次请求的 tokens | 一个 interaction 中的 max_output_tokens | 每个流式请求 64K;每个非流式请求 32K |
| 运行时间 | 最长 24 小时 | 20 分钟 |
| 存储 | 需要 store: true | 服务器不存储任何内容 |
| 适用特点 | 最容易运行 Long Decode | 对重试有更细粒度控制,可自行构建 backoff、错误处理和恢复能力 |
Interactions API 的后台执行是最简单的 Long Decode 方式。客户端 continuation 允许代码自行发起每个 hop,当前可用于 GenerateContent API;Interactions API 的该高级自定义方式在页面中标记为 coming soon。
将任务限定为 Gemini 4 Argon 的复杂推理、代码或 Agent 工作,固定模型 ID gemini-4-argon、输入和验收标准。
先判断是否真的需要超过 64K tokens;普通聊天、问答、摘要、分类和抽取不应默认启用 Long Decode。
对 Interactions API 创建后台 interaction:设置 background: true、store: true,并设置 max_output_tokens。复杂数学、科学和证明任务可从 262,144 开始,但上限是 1,048,576 减去输入 tokens。
选择 Thinking 档位;页面建议最难推理使用 high,多数编码和 Agent 任务使用默认 medium。如需节省 tokens,降低 thinking_level。
轮询 in_progress 或 queued 状态,直到进入终态;将同一 interaction ID 下所有 model_output steps 的文本拼接起来,并读取 usage。
若使用流式传输,设置 stream: true 和 thinking_summaries: "auto",保存 interaction.created 的 interaction ID,以及所有事件的 event_id。
流断开后使用最后一个 event_id 调用 interactions.get 并继续流;重连后先读到流结束,再检查状态。HTTP read timeout 设置为每条流 15 到 20 分钟。
处理终态:completed 读取结果;requires_action 执行工具并回传结果;incomplete 提高 max_output_tokens 后重试;failed 重试,连续失败时将 interaction ID 提交给支持团队;cancelled 读取 usage 确认已计费 tokens。
记录每个 hop 的输入、思考、输出、缓存 token 和总 token。不要用 total_input_tokens 判断上下文大小;应以提示大小加 total_output_tokens 和 total_thought_tokens 估算实际上下文。
页面明确将 Long Decode 限定为 Gemini 4 Argon,并说明其可超过 64K tokens,最高到统一的 1,048,576-token 上下文窗口;输入、思考和输出共享该窗口。
Interactions API 的后台执行由服务器自动生成并合并每个 64K hop;每个 hop 在同一 interaction ID 下新增 model_output step。
创建后台 interaction 时,max_output_tokens 必须大于 65,536;后台方式最高可设置到 1,048,576 减去输入 tokens。未设置时仍为 65,536。
background: false 的流式和非流式 interaction 上限为 65,536;更大值会返回 400,且页面说明无后台执行的 Long Decode 尚不可用。
后台 interaction 最长运行 24 小时;GenerateContent API 的客户端 continuation 每次流式请求为 64K、每次非流式请求为 32K,运行时间为 20 分钟,服务器不保存内容。
流式恢复需要保存 interaction ID 和每个 event_id,并使用 interactions.get、stream: true 与 last_event_id 继续;服务器会重放遗漏事件,即使 interaction 已完成。
终态包括 completed、requires_action、incomplete、failed 和 cancelled,页面分别给出了对应处理动作。
max_output_tokens 是整个 interaction 中思考和输出的合计上限;页面建议长编码和 Agent 任务从默认 65,536 开始,复杂推理、数学、科学和证明使用 background: true,从 262,144 开始。
interaction.usage 应读取 total_input_tokens、total_cached_tokens、total_output_tokens、total_thought_tokens 和 total_tokens。流式 step.stop 与 interaction.status_update 中的 usage 是 interaction 的累计值,应读取最新值而不是相加。
后续 hop 会把提示和此前生成内容再次作为输入发送;示例中 1,000-token 提示、200,000 tokens 思考与输出分四个 hop 时,各 hop 输入为 1,000、66,536、132,072、197,608,合计 397,216 tokens。页面称重复输入通过隐式缓存自动享受 95% 折扣,实际上下文约为 201,000 tokens。
每个 hop 的每个 token 都计费,包括只有思考的 hop。介绍期缓存输入价格为每 1M tokens 0.10 美元,而普通输入价格为每 1M tokens 2.00 美元;取消或失败的 interaction 仍需支付结束前已经完成的工作。
停止运行中的 interaction:Python 使用 client.interactions.cancel(id=interaction.id),JavaScript 使用 client.interactions.cancel(interaction.id),REST 使用 POST /v1beta/interactions/{id}/cancel。
官方相关链接:GenerateContent API 的 Long Decode、后台执行指南、Thinking 和 Gemini 4 Argon 最新模型页面。
Long Decode 不是把一次普通同步请求的输出上限直接改成 1,048,576;它要求后台执行,并通过多个 64K hop 续接。
1,048,576 是输入、思考和输出共享的统一上下文窗口;可用输出上限还要减去输入 tokens。
max_output_tokens 是思考与可见输出的合计上限。设置高值只是给模型更多空间,模型仍自行决定写多少;固定 token 或字数目标不受支持。
每个 hop 会重复发送截至当时的上下文,因此 total_input_tokens 会高于实际上下文大小,不能用来直接决定何时压缩或裁剪对话历史。
后台执行需要 store: true;页面没有在本页给出更多存储 schema,不应自行补写。
复杂任务可能运行数分钟;流式连接应使用 15 到 20 分钟的 HTTP read timeout,并保持 5K-token 分块之间的正常暂停连接。首个 64K tokens 约需前 10 分钟,之后输出块约为 5,000 tokens。
background: false 无 Long Decode,超过 65,536 会失败;页面说明相关支持将来提供。
模型不遵循 token 长度或字数目标;当任务需要严格长度时,不应使用 Long Decode 作为长度控制器。
使用 gemini-4-argon 创建一个 background: true、store: true 的 Interactions API interaction,设置 max_output_tokens: 262144 和 thinking_level: "high",记录 interaction ID。
轮询 /v1beta/interactions/{id} 或使用 SDK,直到状态不再是 in_progress 或 queued;拼接每个 model_output step 的文本,并保存 usage。
用同一输入分别测试 65,536、262,144 和接近 1,048,576 减去输入 tokens 的上限,记录完成、截断、失败和实际思考/输出 token。
进行流式测试:保存 interaction.created 的 interaction ID 和所有 event_id,主动断开连接,再以 last_event_id 重连并读到流结束,确认遗漏事件被重放且最终文本可拼接。
对 completed、requires_action、incomplete、failed、cancelled 分别构造或记录终态处理,不把空文本的 incomplete 当作成功结果。
记录每个 hop 的输入 token、缓存 token、思考 token、输出 token、总 token 和费用;将重复 hop 输入的 95% 隐式缓存折扣与未缓存 token 分开核算。
Gemini 4 Argon