进阶 ai.google.dev 2026-10-15 02:43:21 · 29 阅读

第5章 最新 Gemini 模型

Gemini 4 Argon 现已推出,快来体验吧。

首页

Gemini API

文档

Gemini 4 Argon 的新特性

Gemini 4 Argon(gemini-4-argon)是我们最新、最强大的模型。它能在难题上进行更长时间的推理,在复杂编码、智能体、数学和科学任务上取得更好的结果。Gemini 4 Argon 可通过 Gemini API 和 Google AI Studio 使用。

Gemini 4 Argon 支持统一的 1M token 上下文窗口、最长 1M token 的长解码(long decode),以及可调节的思考级别(low、medium、high)。

experiment

在 AI Studio 中试用

用 Gemini 4 Argon 和 AI Studio 从零构建应用。

smart_toy

应用画廊

体验和改编用 Gemini 4 Argon 构建的应用。

rocket_launch

快速上手

通过示例提示词开始使用 Gemini 4 Argon。

本指南介绍 Gemini 4 Argon 的新特性、API 变更、代码示例和迁移指引。

新模型

模型 | 模型 ID | 默认思考级别 | 价格 | 描述

Gemini 4 Argon | gemini-4-argon | medium | 2026 年 11 月 30 日前提供 introductory 优惠价:输入 $2/1M token,输出 $10/1M token(此后为输入 $4/1M、输出 $20/1M)。详见定价页面。 | 我们最强大的模型,为在真实软件工程和知识工作中深度、精准地解决最难问题而打造。

完整细节请参阅 Gemini 4 Argon 模型页面。优惠价格详情见本页后文的定价部分或定价页面。

快速开始

使用以下示例向 gemini-4-argon 发送请求,采用推荐的默认 thinking_level(medium)和 64K 输出 token 上限:

Python ```python from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-4-argon", input="Write a three.js script that renders a realistic 3D black hole with gravitational lensing." )

print(interaction.output_text) ```

JavaScript ```javascript import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: "gemini-4-argon", input: "Write a three.js script that renders a realistic 3D black hole with gravitational lensing.", });

console.log(interaction.output_text); ```

REST ```bash curl "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "model": "gemini-4-argon", "input": "Write a three.js script that renders a realistic 3D black hole with gravitational lensing." }' ```

Gemini 4 Argon 的新特性

统一的 1M 输入输出 token 上限:输入、思考和输出共享一个 1,048,576 token 的窗口。

长解码:单次响应现在可以超过 64K token,最高可达 1M token 减去你的输入。参见长解码。

智能体视频理解正式发布(GA):智能体视频理解现已全面可用。

Managed Agents 支持:Gemini Managed Agents 中的 Antigravity 智能体现在支持 Gemini 4 Argon。

完整规格请见 Gemini 4 Argon 模型页面,价格详情见定价页面。

更大的输出与长解码

Gemini 4 Argon 能在困难的数学、科学和编码问题上进行更长时间的思考。

用 thinking_level 控制推理深度:思考级别决定模型在回答前推理的深度。max_output_tokens 是硬性上限:思考加输出一旦达到上限,响应就会停止,所以要把它设置得足够高,避免答案被截断。

通过后台执行(background execution)生成最多 1M token:将 background 执行与大于 65,536 的 max_output_tokens 结合使用,可以让单次响应超过 64K token,最高达 1M token。模型以最多 64K token 为一跳(hop)生成长响应,每一跳都从上一跳的停止处继续。使用后台执行时,我们的服务器会替你运行这些续写跳。由于每一跳都会在 interaction.steps 中添加一个 model_output 步骤,请在 interaction 完成后把所有 model_output 步骤的文本拼接起来。

Python ```python 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) ```

JavaScript ```javascript 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); ```

REST ```bash 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')

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("")' break fi sleep 5 done ```

后台执行是运行长解码最简单的方式,它会在服务器端运行续写循环,直到模型完成或达到 max_output_tokens。如果你需要对重试、退避和错误处理进行更细粒度的控制(或者不希望存储你的 interactions),可以在 GenerateContent API 中使用客户端续写。客户端续写也将很快支持 Interactions API。关于流式传输、重连、token 计数以及何时使用长解码,请参阅长解码指南。

设置输出 token 上限

max_output_tokens 设定一次响应中思考和输出 token 的总量。要设得足够高,避免思考过程截断答案;也要设得足够低,在难题用完全部额度时控制花费。

以下值可作为起点:

标准任务:保持默认值 65,536,或不设置。

现有应用上限低于 32K 的:将 max_output_tokens 提升到至少 32,768。相比之前的模型,Gemini 4 Argon 会把更多额度用于思考。如果想减少 token 用量,应该降低思考级别。

复杂推理和编码:设置 background: true,并将 max_output_tokens 设为 131,072 或 262,144,最高可到 1,048,576 减去你的输入 token。

理解思考级别

思考级别是你在 Gemini 4 Argon 中控制质量、延迟和 token 用量的主要手段:

思考级别 | Token 用量 | 适用场景

low | token 用量最少,延迟最低 | 较简单的任务和对成本敏感的场景。也适用于只需轻量思考的分析和写作任务。在难题上质量可能下降。

medium(默认) | 平衡 | 推荐用于大多数任务,包括复杂代码和智能体场景。

high | token 用量最多,首 token 最慢 | 复杂推理、高难度数学和科学,以及最难的代码或智能体任务。与长解码搭配使用可生成超长输出。

在三个级别上分别运行你的评估,然后选择能满足质量要求的最低级别。了解更多请参阅思考指南。

Python ```python from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-4-argon", input="Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely.", generation_config={ "thinking_level": "medium" # Balanced reasoning effort for complex tasks } )

print(interaction.output_text) ```

JavaScript ```javascript import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: "gemini-4-argon", input: "Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely.", generation_config: { thinking_level: "medium", // Balanced reasoning effort for complex tasks }, });

console.log(interaction.output_text); ```

REST ```bash curl "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "model": "gemini-4-argon", "input": "Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely.", "generation_config": { "thinking_level": "medium" } }' ```

Managed Agents 中的 Gemini 4 Argon

Gemini Managed Agents 中的 Antigravity 智能体支持 Gemini 4 Argon。使用时在 agent_config 中设置模型:

Python ```python from google import genai

client = genai.Client()

interaction = client.interactions.create( agent="antigravity-preview-09-2026", input=( "Audit https://web.dev for performance, Core Web Vitals, and SEO. " "Query Google's PageSpeed Insights API for both Mobile and Desktop strategies. " "Check search indexing with Google Search for site:web.dev. " "Format the output as a side-by-side scorecard table with prioritized fixes." ), environment="remote", agent_config={ "type": "antigravity", "model": "gemini-4-argon", }, )

print(interaction.output_text) ```

JavaScript ```javascript import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ agent: "antigravity-preview-09-2026", input: "Audit https://web.dev for performance, Core Web Vitals, and SEO. " + "Query Google's PageSpeed Insights API for both Mobile and Desktop strategies. " + "Check search indexing with Google Search for site:web.dev. " + "Format the output as a side-by-side scorecard table with prioritized fixes.", environment: "remote", agent_config: { type: "antigravity", model: "gemini-4-argon", }, }, { timeout: 300000 });

console.log(interaction.output_text); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "Content-Type: application/json" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -d '{ "agent": "antigravity-preview-09-2026", "input": "Audit https://web.dev for performance, Core Web Vitals, and SEO. Query Google'\''s PageSpeed Insights API for both Mobile and Desktop strategies. Check search indexing with Google Search for site:web.dev. Format the output as a side-by-side scorecard table with prioritized fixes.", "environment": "remote", "agent_config": { "type": "antigravity", "model": "gemini-4-argon" } }' ```

更多选项请参阅 Antigravity 智能体指南中的模型选择部分。

迁移清单 `/gemini-api-dev migrate my app to Gemini 4 Argon`

迁移到 gemini-4-argon

更新模型 ID:将目标模型字符串改为 gemini-4-argon。

检查 max_output_tokens:如果现在有显式设置,考虑调高。建议至少 32,768,因为 Gemini 4 Argon 会把更多额度用于思考。

配置思考级别:在 low、medium(默认)、high 之间选择,并在三个级别上都测试你的工作负载。

放弃显式上下文缓存:Gemini 4 Argon 不支持显式缓存(cachedContents / caches.create)。请从请求中移除创建或引用 cached_content 的调用。对于至少 4,096 token 的提示词,隐式缓存默认开启,缓存命中时输入 token 可享 95% 折扣。

移除采样参数:从请求中移除 temperature、top_p 和 top_k。即使提供,也会被忽略。

长输出使用后台执行:需要超过 64K token 的任务,请设置 background 为 true,并将 max_output_tokens 设为大于 65,536。

调大客户端超时:难题可能需要几分钟。请使用后台执行,或将 HTTP 客户端超时设置为至少 15 分钟。

会话状态保存在服务端:多轮对话和函数调用请使用 previous_interaction_id。

定价

2026 年 11 月 30 日前,Gemini 4 Argon 提供 introductory 优惠价:

输入 token:$2.00 / 1M token(2026 年 12 月 1 日起为 $4.00)

缓存输入 token:隐式缓存对缓存输入提供 95% 折扣,即 $0.10 / 1M token(2026 年 12 月 1 日起为 $0.20)。

输出 token(含思考 token):$10.00 / 1M token(2026 年 12 月 1 日起为 $20.00)

Gemini 4 Argon 不支持免费层级和 Google AI Pro 计划。完整价格层级请见定价页面。

其他模型

Gemini 3.8 Flash

Gemini 3.6 Flash 和 3.5 Flash-Lite

查看所有模型

后续步骤

阅读长解码指南,了解流式传输、重连和 token 计数。

在思考指南中了解思考级别和思维摘要的工作方式。

在后台执行指南中了解长时间运行的任务。

在 Google AI Studio 中测试和优化提示词。

评论 (0)