i18n/zh-TW/vertex-ai-api-dev/SKILL.md
Google Cloud Vertex AI 上 Gemini API 使用指南 — 涵蓋 Gen AI SDK(Python, JS/TS, Go, Java, C#)、Live API、工具呼叫、多模態生成、快取與批次預測
npx skillsauth add tai-ch0802/skills-bundle vertex-ai-api-devInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
透過 Google Cloud Vertex AI 上的 Gemini API,存取 Google 專為企業級應用案例打造的最先進 AI 模型。
提供以下核心功能:
google-genai,JS/TS 為 @google/genai,Go 為 google.golang.org/genai,Java 為 com.google.genai:google-genai,C# 為 Google.GenAI)。google-cloud-aiplatform、@google-cloud/vertexai 或 google-generativeai。pip install google-genai 安裝 google-genainpm install @google/genai 安裝 @google/genaigo get google.golang.org/genai 安裝 google.golang.org/genaidotnet add package Google.GenAI 安裝 Google.GenAIgroupId: 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]
google-cloud-aiplatform、@google-cloud/vertexai和google-generativeai等舊版 SDK 已棄用。請參閱遷移指南,盡快遷移至上述新版 SDK。
在建立客戶端時,優先使用環境變數而非硬編碼參數。無參數初始化客戶端以自動讀取這些值。
設定這些變數以進行標準的 Google Cloud 驗證:
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='global'
export GOOGLE_GENAI_USE_VERTEXAI=true
location="global" 來存取全域端點,該端點會自動路由到具有可用容量的區域。us-central1、europe-west4),請改為在 GOOGLE_CLOUD_LOCATION 參數中指定該區域。如有需要,請參考支援的區域文件。當使用帶有 API 金鑰的快速模式時,請設定以下變數:
export GOOGLE_API_KEY='your-api-key'
export GOOGLE_GENAI_USE_VERTEXAI=true
不帶引數初始化客戶端以讀取環境變數:
from google import genai
client = genai.Client()
或者,您也可以在建立客戶端時硬編碼參數。
from google import genai
client = genai.Client(vertexai=True, project="your-project-id", location="global")
gemini-3.1-pro-preview 處理複雜推理、編碼、研究 (1M tokens)gemini-3-flash-preview 取得快速、平衡的效能、多模態 (1M tokens)gemini-3-pro-image-preview 進行 Nano Banana Pro 圖片生成與編輯gemini-live-2.5-flash-native-audio 使用 Live Realtime API (包含原生音訊)如有明確要求,請使用以下模型:
gemini-2.5-flash-image 進行 Nano Banana 圖片生成與編輯gemini-2.5-flashgemini-2.5-flash-litegemini-2.5-pro[!IMPORTANT] 像是
gemini-2.0-*、gemini-1.5-*、gemini-1.0-*、gemini-pro等模型為舊版且已棄用。請使用上述新模型。 對於生產環境,請參閱 Vertex AI 文件以取得穩定的模型版本 (例如gemini-3-flash)。
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Explain quantum computing"
)
print(response.text)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ vertexai: { project: "your-project-id", location: "global" } });
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Explain quantum computing"
});
console.log(response.text);
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-flash-preview", genai.Text("Explain quantum computing"), nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Text)
}
import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
public class GenerateTextFromTextInput {
public static void main(String[] args) {
Client client = Client.builder().vertexAi(true).project("your-project-id").location("global").build();
GenerateContentResponse response =
client.models.generateContent(
"gemini-3-flash-preview",
"Explain quantum computing",
null);
System.out.println(response.text());
}
}
using Google.GenAI;
var client = new Client(
project: "your-project-id",
location: "global",
vertexAI: true
);
var response = await client.Models.GenerateContent(
"gemini-3-flash-preview",
"Explain quantum computing"
);
Console.WriteLine(response.Text);
在實作或除錯 Vertex AI 的 API 整合時,請參閱官方的 Google Cloud Vertex AI 文件:
Vertex AI 上的 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 伺服器:如果可以使用
search_documents或get_document工具,請使用它們直接在上下文中尋找並擷取 Google Cloud 和 Vertex AI 的官方文件。這是獲取最新 API 詳細資訊和程式碼片段的首選方法。
請參考 Python Docs Samples 儲存庫以取得其他程式碼範例和特定使用情境。
根據特定的使用者請求,請參閱以下參考檔案以取得詳細的程式碼範例和使用模式 (Python 範例):
development
Unified testing skill — TDD workflow, unit/integration patterns, E2E/Playwright strategies. Replaces tdd-workflow + testing-patterns + webapp-testing.
testing
Security-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
development
Spec-Driven Development (SDD): A structured workflow (Requirement -> Analysis -> Implementation) enforcing explicit documentation before coding.
development
Methodologies for System Analysis (SA), focusing on technical architecture, data flow modeling, and API design.