您可以使用 Anthropic 的 SDK 或 curl 指令,透過下列模型名稱將要求傳送至 Gemini Enterprise Agent Platform 端點:
- 如要在 Google Cloud 上使用 Claude Sonnet 5,請使用
claude-sonnet-5 - 如要在 Google Cloud 上使用 Claude Opus 5,請使用
claude-opus-5 - 如要在 Google Cloud 上使用 Claude Fable 5,請使用
claude-fable-5 - 如要在 Google Cloud 上使用 Claude Opus 4.8,請使用
claude-opus-4-8 - 如要在 Google Cloud 上使用 Claude Opus 4.7,請使用
claude-opus-4-7 - 如要在 Google Cloud 上使用 Claude Opus 4.6,請使用
claude-opus-4-6 - 如要在 Google Cloud 上使用 Claude Sonnet 4.6,請使用
claude-sonnet-4-6 - 如要在 Google Cloud 上使用 Claude Opus 4.5,請使用
claude-opus-4-5 - 如要在 Google Cloud 上使用 Claude Opus 4.1,請使用
claude-opus-4-1 - 如要在 Google Cloud 上使用 Claude Opus 4,請使用
claude-opus-4 - 如要在 Google Cloud 上使用 Claude Sonnet 4.5,請使用
claude-sonnet-4-5 - 如要在 Google Cloud 上使用 Claude Sonnet 4,請使用
claude-sonnet-4 - 如要在 Google Cloud 上使用 Claude 3.7 Sonnet,請使用
claude-3-7-sonnet - 如要在 Google Cloud 上使用 Claude 3.5 Sonnet v2,請使用
claude-3-5-sonnet-v2 - 如要在 Google Cloud 上使用 Claude Haiku 4.5,請使用
claude-haiku-4-5 - 如要在 Google Cloud 上使用 Claude 3.5 Haiku,請使用
claude-3-5-haiku - 如要在 Google Cloud 上使用 Claude 3.5 Sonnet,請使用
claude-3-5-sonnet - 如要在 Google Cloud 上使用 Claude 3 Opus,請使用
claude-3-opus - 如要在 Google Cloud 上使用 Claude 3 Haiku,請使用
claude-3-haiku
事前準備
Anthropic 實施政策,禁止特定經銷商轉售產品。如果您的 Google Cloud 帳單帳戶是由違規經銷商管理,您將無法接受《服務條款》或啟用 Claude 模型。如果發生這種情況,請直接與經銷商聯絡。
如要透過 Gemini Enterprise Agent Platform 使用 Anthropic Claude 模型,請完成下列步驟。如要使用 Gemini Enterprise Agent Platform,必須啟用 Agent Platform API (aiplatform.googleapis.com)。如果您現有的專案已啟用 Agent Platform API,可以使用該專案,不必建立新專案。
請確認您具備啟用及使用合作夥伴模型所需的權限。 詳情請參閱「授予必要權限」。
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Gemini Enterprise Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Gemini Enterprise Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
前往下列任一 Model Garden 模型資訊卡,然後按一下「啟用」:
- 前往 Google Cloud 上的 Claude Sonnet 5 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 5 模型資訊卡
- 前往 Google Cloud 上的 Claude Fable 5 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4.8 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4.7 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4.6 模型資訊卡
- 前往 Google Cloud 上的 Claude Sonnet 4.6 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4.5 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4.1 模型資訊卡
- 前往 Google Cloud 上的 Claude Opus 4 模型資訊卡
- 前往 Google Cloud 上的 Claude Sonnet 4.5 模型資訊卡
- 前往 Google Cloud 上的 Claude Sonnet 4 模型資訊卡
- 前往 Google Cloud 上的 Claude Haiku 4.5 模型資訊卡
- 前往 Google Cloud 上的 Claude 3.5 Haiku 模型資訊卡
Anthropic 建議您啟用提示和完成活動的 30 天記錄功能,以便記錄任何模型濫用情形。如要啟用記錄功能,請參閱「記錄要求和回應」。
使用 Anthropic SDK
您可以使用 Anthropic Claude SDK,向 Anthropic Claude 模型發出 API 要求。詳情請參閱下列文章:
- Claude messages API 參考資料
- Anthropic Python API 程式庫
- Anthropic Gemini Enterprise Agent Platform TypeScript API 程式庫
使用 Anthropic Vertex SDK 對 Claude 模型發出串流呼叫
下列程式碼範例使用 Anthropic Vertex SDK,對 Claude 模型執行串流呼叫。
Python
如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。
下列範例使用區域端點。如要使用多區域或全域端點,請參閱「指定多區域端點」或「指定全域端點」。使用 Anthropic Vertex SDK 對 Claude 模型發出一元呼叫
下列程式碼範例使用 Anthropic Vertex SDK,對 Claude 模型執行一元呼叫。
Python
如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。
下列範例使用區域端點。如要使用多區域或全域端點,請參閱「指定多區域端點」或「指定全域端點」。使用 curl 指令
您可以使用 curl 指令向 Gemini Enterprise Agent Platform 端點提出要求。 curl 指令會指定要使用的支援 Claude 模型。
以下主題說明如何建立 curl 指令,並提供 curl 指令範例。
REST
如要使用 Agent Platform API 測試文字提示詞,請將 POST 要求傳送至發布商模型端點。
下列範例使用區域端點。如要使用多區域或全域端點,請參閱「指定多區域端點」或「指定全域端點」。使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:支援 Anthropic Claude 模型的區域。如要使用全域端點,請參閱「指定全域端點」。
- MODEL:要使用的模型名稱。
- ROLE:與訊息相關聯的角色。您可以指定
user或assistant。 第一則訊息必須使用user角色。Claude 模型會交替進行user和assistant輪次。如果最終訊息使用assistant角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。 - STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為
true可串流回覆,設為false則可一次傳回回覆。 - CONTENT:
user或assistant訊息的內容,例如文字。 - MAX_TOKENS:回覆內可以生成的權杖數量上限。一個權杖約為 3.5 個字元。100 個符記約為 60 到 80 個字。
如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。
- TOP_P (選用):
Top-P 會影響模型選取輸出詞元的方式。模型會按照可能性最高到最低的順序選取符記,直到所選符記的可能性總和等於 Top-P 值。舉例來說,假設詞元 A、B 和 C 的可能性分別為 0.3、0.2 和 0.1,而「Top-P」值為
0.5,模型會依據 temperature 選擇 A 或 B 做為下一個詞元,並排除 C。如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。
- TOP_K(選用):
Top-K 會影響模型選取輸出詞元的方式。如果 Top-K 設為
1,代表下一個所選詞元是模型詞彙表的所有詞元中可能性最高者 (也稱為「貪婪解碼」)。如果 Top-K 設為3,則代表模型會依據 temperature,從可能性最高的 3 個詞元中選取下一個詞元。在每個符記選取步驟中,模型會對機率最高的「Top-K」符記取樣,接著進一步根據「Top-P」篩選詞元,最後依 temperature 選出最終詞元。
如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。
- TYPE:如要在 Google Cloud 上的 Claude 3.7 Sonnet 和後續 Claude 模型中啟用擴展思考模式,請指定
enabled。 - BUDGET_TOKENS:如要啟用擴充思考功能,您必須指定模型可使用的詞元數量,供內部推論使用,並將其納入輸出內容。預算越高,越能全面分析複雜問題,並提升回覆品質。您必須指定大於或等於
1024但小於MAX_TOKENS的值。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict
JSON 要求內文:
{
"anthropic_version": "vertex-2023-10-16",
"messages": [
{
"role": "ROLE",
"content": "CONTENT"
}],
"max_tokens": MAX_TOKENS,
"stream": STREAM,
"thinking": {
"type": "TYPE",
"budget_tokens": BUDGET_TOKENS
}
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict" | Select-Object -Expand Content
您應該會收到類似如下的 JSON 回應。
cURL 指令範例
MODEL_ID="MODEL"
LOCATION="us-central1"
PROJECT_ID="PROJECT_ID"
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/anthropic/models/${MODEL_ID}:streamRawPredict -d \
'{
"anthropic_version": "vertex-2023-10-16",
"messages": [{
"role": "user",
"content": "Hello!"
}],
"max_tokens": 50,
"stream": true}'
使用工具 (呼叫函式)
Anthropic Claude 模型支援工具和函式呼叫,可提升模型功能。詳情請參閱 Anthropic 說明文件中的「工具使用總覽」。Gemini Enterprise Agent Platform 適用的 Claude 模型支援用戶端工具,但不支援伺服器工具。
下列範例示範如何使用 SDK 或 curl 指令使用工具。這些範例會搜尋舊金山附近營業中的餐廳。
Python
如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。
下列範例使用區域端點。如要使用多區域或全域端點,請參閱「指定多區域端點」或「指定全域端點」。REST
下列範例使用區域端點。如要使用多區域或全域端點,請參閱「指定多區域端點」或「指定全域端點」。使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:支援 Anthropic Claude 模型的區域。如要使用全域端點,請參閱「指定全域端點」。
- MODEL:要使用的模型名稱。
- ROLE:與訊息相關聯的角色。您可以指定
user或assistant。 第一則訊息必須使用user角色。Claude 模型會交替進行user和assistant輪次。如果最終訊息使用assistant角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。 - STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為
true可串流回覆,設為false則可一次傳回回覆。 - CONTENT:
user或assistant訊息的內容,例如文字。 - MAX_TOKENS:
回覆內可以生成的權杖數量上限。一個權杖約為 3.5 個字元。100 個符記約為 60 到 80 個字。
如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict
JSON 要求內文:
{
"anthropic_version": "vertex-2023-10-16",
"max_tokens": MAX_TOKENS,
"stream": STREAM,
"tools": [
{
"name": "text_search_places_api",
"description": "Returns information about a set of places based on a string",
"input_schema": {
"type": "object",
"properties": {
"textQuery": {
"type": "string",
"description": "The text string on which to search"
},
"priceLevels": {
"type": "array",
"description": "Price levels to query places, value can be one of [PRICE_LEVEL_INEXPENSIVE, PRICE_LEVEL_MODERATE, PRICE_LEVEL_EXPENSIVE, PRICE_LEVEL_VERY_EXPENSIVE]",
},
"openNow": {
"type": "boolean",
"description": "Describes whether a place is open for business at
the time of the query."
},
},
"required": ["textQuery"]
}
}
],
"messages": [
{
"role": "user",
"content": "What are some affordable and good Italian restaurants that are open now in San Francisco??"
}
]
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict" | Select-Object -Expand Content
您應該會收到類似如下的 JSON 回應。
使用 Gemini Enterprise Agent Platform 的 Agent Studio
對於部分 Anthropic Claude 模型,您可以使用 Gemini Enterprise Agent Platform 的 Agent Studio,在 Google Cloud 控制台中快速設計及測試生成式 AI 模型原型。舉例來說,您可以使用 Gemini Enterprise Agent Platform 的 Agent Studio,比較 Claude 模型的回覆與其他支援模型 (例如 Google Gemini)。
詳情請參閱快速入門導覽課程:使用 Gemini Enterprise Agent Platform 的 Agent Studio 向 Gemini 傳送文字提示詞。