Gemini API 是从提示到生产的最快路径,支持 Gemini、Veo、Nano Banana 等。借助该 API,您可以将这些生成模型集成到应用中,以生成文本和图片、分析多模态输入以及构建对话智能体。
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-4-argon",
input="Explain how AI works in a few words"
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-4-argon",
input: "Explain how AI works in a few words",
});
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-4-argon"))
.input(InteractionsInput.of("Explain how AI works in a few words"))
.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-4-argon"),
Input: interactions.NewInteractionsInput("Explain how AI works in a few words"),
}),
})
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 "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-4-argon",
"input": "Explain how AI works in a few words"
}'
认识模型
查看全部Gemini 4 Argon 新
我们的旗舰推理模型,具有 100 万 token 的共享上下文窗口,并支持长达 100 万 token 的长解码。
Gemini 3.8 Flash 新
Google 旗下最智能的 Flash 模型,专为长跨度软件工程、自主智能体和复杂的企业工作流而设计。
Gemini 3.8 Flash TTS 新
录音室级文字转语音模型,具有富有表现力的演绎、自定义语音设计和语音复刻功能。
Gemini 3.5 Flash-Lite
这是一款大体量、成本敏感的模型,针对低延迟、高吞吐量的子智能体任务进行了优化。
Nano Banana
先进的图片生成和编辑模型。
Gemini Omni Flash
Google 的前沿视频生成和编辑模型。
Gemini 3.5 Transcribe 新
低延迟语音转文字模型,支持基于话语的语言检测、讲话人区分和字词时间戳。
Gemini Robotics
这是一款视觉语言模型 (VLM),可将 Gemini 的智能体功能引入机器人技术,并在物理世界中实现高级推理。
探索各项功能
图片生成
使用 Nano Banana 原生生成和编辑高度契合上下文的图片。
长上下文
向 Gemini 模型输入数百万个 token,并从非结构化图片、视频和文档中获取理解。
结构化输出
限制 Gemini 以 JSON 格式(一种适合自动处理的结构化数据格式)进行回答。
函数调用
通过将 Gemini 连接到外部 API 和工具,构建 Agentic Workflows。
使用 Gemini Omni Flash 生成视频
借助我们前沿的模型,根据文本或图片提示生成高质量视频内容。
使用 Live API 的语音智能体
使用 Live API 构建实时语音应用和智能体。
工具
通过 Google 搜索、网址上下文、Google 地图、代码执行和计算机使用等内置工具,将 Gemini 与世界连接起来。
文档理解
处理多达 1,000 页的 PDF 文件(具有完整的多模态理解能力)或其他基于文本的文件类型。
思考
探索思考能力如何提升复杂任务和智能体的推理能力。
创建代理
托管式智能体为 Gemini 提供了一个工作区,让其能够自行规划和完成任务。在单个请求中,Gemini 可以在托管沙盒环境中编写和运行代码、搜索网络以及创建文件。您可以从我们的预构建 Antigravity 智能体开始,也可以使用自己的指令和工具对其进行自定义。
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input=(
"Research the top 5 sustainable fashion brands, "
"compare their materials and pricing tiers, and "
"build an interactive dashboard in analysis.html."
),
environment="remote"
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
agent: "antigravity-preview-09-2026",
input:
"Research the top 5 sustainable fashion brands, " +
"compare their materials and pricing tiers, and " +
"build an interactive dashboard in analysis.html.",
environment: "remote",
});
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(
"Research the top 5 sustainable fashion brands, "
+ "compare their materials and pricing tiers, and "
+ "build an interactive dashboard in analysis.html."))
.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(
"Research the top 5 sustainable fashion brands, " +
"compare their materials and pricing tiers, and " +
"build an interactive dashboard in analysis.html.",
),
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 "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"agent": "antigravity-preview-09-2026",
"input": "Research the top 5 sustainable fashion brands, compare their materials and pricing tiers, and build an interactive dashboard in analysis.html.",
"environment": "remote"
}'
Interactions API
自 2026 年 6 月起,Interactions API 已成为我们的默认接口,也是未来使用 Gemini 模型和智能体进行构建的最佳方式。如果您要启动新项目,则应使用 Interactions API。虽然 generateContent API 仍受支持,但现在已被视为旧版 API。