Gemini API 是最快的方法,可讓您使用 Gemini、Veo、Nano Banana 等模型,將提示轉化為實際成果。您可以將這些生成式模型整合至應用程式,生成文字和圖片、分析多模態輸入內容,以及建構對話式代理。
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 新推出
Google 的旗艦推論模型,脈絡窗口達 100 萬個詞元,解碼長度最多可達 100 萬個詞元。
Gemini 3.8 Flash 新模型
這是我們最聰明的 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 模型,從非結構化圖片、影片和文件中擷取資訊。
結構化輸出
限制 Gemini 只能以 JSON 格式回覆,這種結構化資料格式適合自動處理。
呼叫函式
將 Gemini 連結至外部 API 和工具,建構代理工作流程。
使用 Veo 3.1 生成影片
使用最先進的模型,根據文字或圖像提示詞生成高品質影片內容。
使用 Live API 的語音代理
使用 Live API 建構即時語音應用程式和代理。
工具
透過 Google 搜尋、網址內容、Google 地圖、程式碼執行和電腦使用等內建工具,將 Gemini 連結至世界。
文件解讀
處理多達 1,000 頁的 PDF 檔案,並充分理解多模態內容或其他文字檔案類型。
思考中
瞭解思考功能如何提升複雜工作和代理的推論能力。
建立代理
受管理代理可為 Gemini 提供工作空間,讓 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,但現在已視為舊版。