本文档简要介绍了 Gemini API 的 v1 和 v1beta 版本之间的区别。
- v1:API 的稳定版本。在主要版本的整个生命周期内,稳定版中的功能均可获得全面支持。如果存在任何重大更改,系统将创建新的 API 主要版本,并在合理的时间段后弃用现有版本。
可能会在不更改主要版本的情况下向 API 引入非重大变更。Interactions API 及其核心功能已在
v1中正式发布。 - v1beta:此版本包含正在积极开发中的早期功能和特性。虽然
v1beta中的功能可能会根据反馈进行改进,但您可以先试用这些新功能,然后再将它们升级为稳定版。
功能和特性支持
下表详细说明了 v1(正式版)和 v1beta(Beta 版)中各项功能的可用性。核心 API 功能和工具同时适用于 Interactions API 和 generateContent,除非另有说明:
| 功能 | v1 | v1beta |
|---|---|---|
| 核心 API 功能 | ||
| Interactions API | ||
| 函数调用 | ||
| 结构化输出 | ||
| 思考 / 推理 | ||
| 系统指令 | ||
| 音频输出(语音配置) | ||
| 服务层级(优先 / 灵活) | ||
| 工具 | ||
| 代码执行工具 | ||
| Google 搜索接地 | ||
| Google 地图接地 | ||
| 网址上下文工具 | ||
| 文件搜索工具 | ||
| 计算机使用工具 | ||
| MCP 服务器工具 | ||
| 实时 API | ||
| Live API (WebSockets) | ||
| Live Music API | ||
| 临时令牌 (Live API) | ||
| 平台 API | ||
| Models API | ||
| 文件服务路线 | ||
| 文件搜索存储路线 | ||
| Agents API | ||
| Webhooks API | ||
| 上下文缓存 |
- - 支持
在 SDK 中配置 API 版本
Gemini API SDK 默认使用 v1beta,但您可以通过设置 API 版本来明确指定版本,如以下代码示例所示:
Python
from google import genai
client = genai.Client(http_options={'api_version': 'v1'})
interaction = client.interactions.create(
model='gemini-3.8-flash',
input="Explain how AI works",
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
httpOptions: { apiVersion: "v1" },
});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works",
});
console.log(interaction.output_text);
}
await main();
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.types.HttpOptions;
Client client = Client.builder()
.httpOptions(HttpOptions.builder().apiVersion("v1").build())
.build();
CreateModelInteraction req = CreateModelInteraction.builder()
.model(Model.of("gemini-3.6-flash"))
.input(InteractionsInput.of("Explain how AI works"))
.build();
var interaction = client.interactions.create(CreateInteractionRequestBody.of(req)).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, &genai.ClientConfig{
HTTPOptions: genai.HTTPOptions{
APIVersion: "v1",
},
})
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.6-flash"),
Input: interactions.NewInteractionsInput("Explain how AI works"),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"input": "Explain how AI works",
}'