Gemini 3.8 Flash (gemini-3.8-flash) 是 Google 旗下最智能的 Flash
模型,专为长期软件工程、自主智能体和复杂的企业工作流而设计。
本指南介绍了 Gemini 3.8 Flash 的新功能、API 变更、代码示例和迁移指南。
新建模型
| 模型 | 模型 ID | 默认思考等级 | 价格 | 说明 |
|---|---|---|---|---|
| Gemini 3.8 Flash | gemini-3.8-flash |
medium |
3.8 Flash 将以初次体验价提供至今年年底,即 $0.75/百万输入 token,$3.75/百万输出 token;如需了解详情,请参阅价格。 | Google 旗下最智能的 Flash 模型,专为长期软件工程、自主智能体和复杂的企业工作流而设计。 |
Gemini 3.8 Flash 支持 100 万个 token 的上下文窗口、最多 6.4 万个输出 token、可调的思考等级(low、medium、high)以及相同的全套内置工具。
如需了解完整规格,请参阅Gemini 3.8 Flash 模型页面。如需了解初次体验价详情,请参阅本页稍后的价格部分或价格页面。
快速入门
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Write a three.js script that renders a realistic 3D black hole."
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: "Write a three.js script that renders a realistic 3D black hole.",
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(
InteractionsInput.of(
"Write a three.js script that renders a realistic 3D black hole."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Write a three.js script that renders a realistic 3D black hole."),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
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-3.8-flash",
"input": "Write a three.js script that renders a realistic 3D black hole."
}'
Gemini 3.8 Flash 的新功能
- 长期软件工程: 在实际编码基准、复杂的多文件重构和确定性工具执行方面表现出色。如需了解详情,请参阅评估方法。
- 自主智能体: 让您能够构建弹性多步骤规划和工具编排工作流,大幅减少失败的循环和错误。
- 复杂的企业工作流: 在要求苛刻的领域任务和大规模数据流水线中,提供卓越的准确性、深入的推理能力和高度的事实严谨性。
- Managed Agents 的默认模型: Managed Agents 的默认智能体 Antigravity 智能体现在使用 Gemini 3.8 Flash。Antigravity SDK 也默认使用 Gemini 3.8 Flash。
- 初次体验价: Gemini 3.8 Flash 将以初次体验价提供至 2026 年 12 月 31 日,即 $0.75/百万输入 token,$3.75/百万输出 token。标准价格为 $1.50/百万输入 token,$7.50/百万输出 token,将于 2027 年 1 月 1 日生效。
Gemini 3.8 Flash 经过精心设计,可以在运行时间较长且复杂的任务中使用更多 token。为了在困难的多步骤目标上提供更高质量的结果,该模型会采取较小的推理步骤,迭代调用工具,并在此过程中验证其工作。并非每个工作流都需要这种级别的验证。对于日常任务,您可以降低推理工作量,以减少 token 消耗。或者,Gemini 3.6 Flash 仍受支持。
了解推理等级
Gemini 3.8 Flash 可让您通过调整模型的思考等级,灵活控制延迟时间和智能:
- 低思考力度:缩短延迟时间敏感型任务的回答时间,例如突发事件响应流水线、实时聊天、撰写草稿和快速数据分析。
- 中等(默认): 适用于大多数任务的最佳质量。建议用于复杂的代码和智能体用例,提供更高的首次准确率。
- 思考力度:最大限度地提高模型的推理和工具编排能力。最适合深入推理、数学和困难的多步骤任务。
以下示例将复杂代码分析请求的 thinking_level 设置为 medium:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
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
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: "Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely.",
generation_config: {
thinking_level: "medium"
}
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ThinkingLevel;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(
InteractionsInput.of(
"Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely."))
.generationConfig(
GenerationConfig.builder()
.thinkingLevel(ThinkingLevel.MEDIUM) // Balanced reasoning effort for complex tasks
.build())
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely."),
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelMedium.ToPointer(), // Balanced reasoning effort for complex tasks
},
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
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-3.8-flash",
"input": "Analyze this payment processing pipeline for race conditions during retry attempts and rewrite the transaction locks safely.",
"generation_config": {
"thinking_level": "medium"
}
}'
更新后的 Antigravity 智能体
由于性能和推理能力有所提升,Gemini Managed Agents 中的 Antigravity 智能体现在默认使用 Gemini 3.8 Flash 构建。
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",
)
print(interaction.output_text)
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",
}, { timeout: 300000 });
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateAgentInteraction params =
CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(
InteractionsInput.of(
"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(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("antigravity-preview-09-2026"),
Input: interactions.NewInteractionsInput(
"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: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment("remote")),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
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 配置底层 Gemini 模型 can be configured。
迁移核对清单
`/gemini-api-dev migrate my app to Gemini 3.8 Flash`
迁移到 gemini-3.8-flash
- 更新模型 ID: 将目标模型字符串更改为
gemini-3.8-flash。 - 配置思考等级: 将
thinking_budget替换为字符串枚举thinking_level。请注意,Gemini 3.8 Flash 不支持minimal;请选择low、medium(默认)或high。 - 应用 Gemini 3 API 参数更改: 移除已废弃的采样参数(
temperature、top_p、top_k)、candidate_count(Gemini 3 及更高版本中不支持)和预填模型轮次。请参阅 Gemini 3.6 API 变更和参数更新。 - 强制执行轮次验证规则: 在服务器端
previous_interaction_id上标准化多轮对话,并移除预填模型轮次。 - 审核函数调用:
- 将多模态素材资源放置在响应载荷内。
- 使用
\n\n设置内嵌说明的格式。 - 如果您看到与工具前文本相关的
Malformed_Function_Call错误,请参阅 工具前文本要求的变通方法。 - 仅在使用 generateContent API 时:确保所有
FunctionResponse对象都包含call_id和name。
- Gemini 3 基准要求: 如需了解 SDK 更新和思维签名保留,请参阅思维签名。
价格
在 2026 年 12 月 31 日之前,Gemini 3.8 Flash 和 Gemini 3.6 Flash 可在 Google AI Studio 和 Gemini Enterprise Agent Platform 中享受初次体验价。标准价格将于 2027 年 1 月 1 日生效。如需了解完整价格层级,请参阅价格页面。
其他模型
后续步骤
- 查看模型概览中的 API 规范。
- 探索 Interactions API 概览 中的多智能体编排。
- 在 Google AI Studio 中测试和优化提示。