API 版本说明

本文档简要介绍了 Gemini API 的 v1v1beta 版本之间的差异。

  • 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.7-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.7-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(""));

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.7-flash",
    "input": "Explain how AI works",
  }'