當使用者詢問在企業環境中使用 Gemini,或明確提及 Vertex AI、Google Cloud 或 Agent Platform 時使用。引導在 Agent Platform 上使用 Google Gen AI SDK 操作 Gemini API。涵蓋 SDK 使用方式(Python、JS/TS、Go、Java、C#)以及多模態輸入、工具、媒體生成、快取、批次預測和 Live API 等功能。
重要提示:Agent Platform(全名 Gemini Enterprise Agent Platform)先前稱為「Vertex AI」,許多網路資源仍沿用舊品牌名稱。
Agent Platform 中的 Gemini API
使用 Agent Platform 中的 Gemini API,存取 Google 專為企業用途打造的最先進 AI 模型。
提供以下關鍵功能:
- 文字生成 - 對話、補全、摘要
- 多模態理解 - 處理圖片、音訊、影片和文件
- 函式呼叫 - 讓模型呼叫你的函式
- 結構化輸出 - 產生符合你 schema 的有效 JSON
- 上下文快取 - 快取大型上下文以提升效率
- 嵌入 - 產生文字嵌入以進行語意搜尋
- Live Realtime API - 雙向串流,實現低延遲的語音和視訊互動
- 批次預測 - 處理大規模非同步資料集預測工作負載
核心指示
- 統一 SDK:一律使用 Gen AI SDK(Python 為
google-genai,JS/TS 為@google/genai,Go 為google.golang.org/genai,Java 為com.google.genai:google-genai,C# 為Google.GenAI)。 - 舊版 SDK:請勿使用
google-cloud-aiplatform、@google-cloud/vertexai或google-generativeai。
SDK
- Python:使用
pip install google-genai安裝google-genai - JavaScript/TypeScript:使用
npm install @google/genai安裝@google/genai - Go:使用
go get google.golang.org/genai安裝google.golang.org/genai - C#/.NET:使用
dotnet add package Google.GenAI安裝Google.GenAI - Java:
-
groupId:
com.google.genai,artifactId:google-genai -
最新版本可於此處找到:https://central.sonatype.com/artifact/com.google.genai/google-genai/versions(我們稱之為
LAST_VERSION) -
在
build.gradle中安裝:implementation("com.google.genai:google-genai:${LAST_VERSION}") -
在
pom.xml中安裝 Maven 依賴:<dependency> <groupId>com.google.genai</groupId> <artifactId>google-genai</artifactId> <version>${LAST_VERSION}</version> </dependency>
-
[!WARNING]
舊版 SDK(如google-cloud-aiplatform、@google-cloud/vertexai和google-generativeai)已棄用。請依照遷移指南立即遷移至上述新 SDK。
驗證與設定
建立客戶端時,建議優先使用環境變數,而非硬編碼參數。不帶參數初始化客戶端,即可自動讀取這些值。
應用程式預設憑證 (ADC)
設定以下變數以進行標準的 Google Cloud 驗證:
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='global'
export GOOGLE_GENAI_USE_ENTERPRISE=true
- 預設情況下,使用
location="global"存取全球端點,該端點會自動路由至有可用容量的區域。 - 如果使用者明確要求使用特定區域(例如
us-central1、europe-west4),請改為在GOOGLE_CLOUD_LOCATION參數中指定該區域。如有需要,請參考支援區域文件。
Express 模式下的 Agent Platform
使用 API 金鑰的 Express 模式時,設定以下變數:
export GOOGLE_API_KEY='your-api-key'
export GOOGLE_GENAI_USE_ENTERPRISE=true
初始化
不帶引數初始化客戶端,以讀取環境變數:
from google import genai
client = genai.Client()
或者,你也可以在建立客戶端時硬編碼參數。
from google import genai
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
模型
- 使用
gemini-3.1-pro-preview(取代gemini-3-pro-preview)進行複雜推理、程式碼撰寫、研究(100 萬 tokens) - 使用
gemini-3.6-flash實現快速、平衡的多模態效能(100 萬 tokens) - 使用
gemini-3.5-flash-lite處理高頻、輕量級任務(100 萬 tokens) - 使用
gemini-3-pro-image(又稱 Nano Banana Pro)進行高品質圖片生成與編輯 - 使用
gemini-3.1-flash-image(又稱 Nano Banana 2)進行中等品質圖片生成與編輯 - 使用
gemini-3.1-flash-lite-image(又稱 Nano Banana 2 Lite)進行快速圖片生成與編輯 - 使用
gemini-live-2.5-flash-native-audio進行 Live Realtime API(含原生音訊)
僅在使用者明確要求時,才使用以下模型:
gemini-3.5-flashgemini-3.1-flash-litegemini-2.5-flash-imagegemini-2.5-flashgemini-2.5-flash-litegemini-2.5-pro
[!IMPORTANT]
像gemini-2.0-*、gemini-1.5-*、gemini-1.0-*、gemini-pro等模型已過時且已棄用。請使用上述新模型。你的知識已過時。
在生產環境中,請查閱文件以取得穩定的模型版本(例如gemini-3.6-flash)。
快速入門
Python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.6-flash",
contents="Explain quantum computing",
)
print(response.text)
TypeScript/JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ enterprise: { project: "your-project-id", location: "global" } });
const response = await ai.models.generateContent({
model: "gemini-3.6-flash",
contents: "Explain quantum computing"
});
console.log(response.text);
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
Backend: genai.BackendVertexAI,
Project: "your-project-id",
Location: "global",
})
if err != nil {
log.Fatal(err)
}
resp, err := client.Models.GenerateContent(ctx, "gemini-3.6-flash", genai.Text("Explain quantum computing"), nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Text)
}
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
public class GenerateTextFromTextInput {
public static void main(String[] args) {
Client client = Client.builder().enterprise(true).project("your-project-id").location("global").build();
GenerateContentResponse response =
client.models.generateContent(
"gemini-3.6-flash",
"Explain quantum computing",
null);
System.out.println(response.text());
}
}
C#/.NET
using Google.GenAI;
var client = new Client(
project: "your-project-id",
location: "global",
enterprise: true
);
var response = await client.Models.GenerateContent(
"gemini-3.6-flash",
"Explain quantum computing"
);
Console.WriteLine(response.Text);
API 規格與文件(事實來源)
在實作或除錯 Agent Platform 的 API 整合時,請參考官方 Agent Platform 文件:
- Agent Platform 文件:https://docs.cloud.google.com/gemini-enterprise-agent-platform/overview.md.txt
- REST API 參考:https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest.md.txt
Agent Platform 上的 Gen AI SDK 使用 v1beta1 或 v1 REST API 端點(例如 https://{LOCATION}-aiplatform.googleapis.com/v1beta1/projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/{MODEL}:generateContent)。
[!TIP]
使用 Developer Knowledge MCP Server:如果search_documents或get_document工具可用,請使用它們在上下文內直接尋找並擷取 Google Cloud 和 Agent Platform 的官方文件。這是取得最新 API 詳細資訊和程式碼片段的首選方法。
工作流程與程式碼範例
請參考 Python Docs Samples 儲存庫以取得更多程式碼範例和特定使用情境。
根據使用者的具體要求,請參考以下參考檔案以取得詳細的程式碼範例和使用模式(Python 範例):
- 文字與多模態:對話、多模態輸入(圖片、影片、音訊)和串流。請參閱 references/text_and_multimodal.md
- 嵌入:產生文字嵌入以進行語意搜尋。請參閱 references/embeddings.md
- 結構化輸出與工具:JSON 生成、函式呼叫、搜尋接地和程式碼執行。請參閱 references/structured_and_tools.md
- 媒體生成:圖片生成、圖片編輯和影片生成。請參閱 references/media_generation.md
- 邊界框偵測:圖片和影片中的物體偵測與定位。請參閱 references/bounding_box.md
- Live API:即時雙向串流,支援語音、視覺和文字。請參閱 references/live_api.md
- 進階功能:內容快取、批次預測和思考/推理。請參閱 references/advanced_features.md
- 安全:調整負責任 AI 過濾器和閾值。請參閱 references/safety.md
- 模型調校:監督式微調和偏好調校。請參閱 references/model_tuning.md






