借助 Gemini、Veo、Nano Banana 等,Gemini API 可助您快速从提示词到生产部署。您可以将这些生成式模型集成到应用中,以生成文本和图片、分析多模态输入,以及构建对话智能体。
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
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-3.8-flash",
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-3.8-flash"))
.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-3.8-flash"),
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-3.8-flash",
"input": "Explain how AI works in a few words"
}'
了解模型
查看全部Gemini 4 Argon New
我们的旗舰推理模型,具有 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
我们前沿的视频生成和编辑模型。
speech_to_text Gemini 3.5 Transcribe 新
低延迟语音转文字模型,具有基于话语的语言检测、讲话人区分和字词时间戳功能。
Gemini Robotics
视觉-语言模型 (VLM),可将 Gemini 的智能体功能引入机器人技术,并支持在物理世界中进行高级推理。
探索功能
图片生成
使用 Nano Banana 以原生方式生成和编辑高度情境化的图片。
长上下文
向 Gemini 模型输入数百万个 token,并从非结构化图片、视频和文档中提取理解。
结构化输出
限制 Gemini 使用 JSON(一种适合自动处理的结构化数据格式)进行响应。
函数调用
通过将 Gemini 连接到外部 API 和工具来构建 Agentic Workflows。
使用 Veo 3.1 生成视频
使用我们前沿的模型,根据文本或图片提示创建高质量的视频内容。
使用 Live API 构建语音智能体
使用 Live API 构建实时语音应用和智能体。
工具
通过内置工具(例如 Google 搜索、网址上下文、Google 地图、代码执行和计算机使用)将 Gemini 连接到世界。
文档理解
处理多达 1000 页的 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 仍受支持,但现在被视为旧版。