您可以使用 Anthropic 的 SDK 或 curl 指令,透過下列模型名稱,將要求傳送至 Gemini Enterprise Agent Platform 端點:
- 如要在 Google Cloud 使用 Anthropic 的 Claude Sonnet 5.5,請使用
claude-sonnet-5-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Fable 5.1,請使用
claude-fable-5-1 - 如要使用 Google Cloud 上的 Anthropic Claude Sonnet 5,請使用
claude-sonnet-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 5.5,請使用
claude-opus-5-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 5,請使用
claude-opus-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Fable 5,請使用
claude-fable-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 4.8,請使用
claude-opus-4-8 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 4.7,請使用
claude-opus-4-7 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 4.6,請使用
claude-opus-4-6 - 如要在 Google Cloud 使用 Anthropic 的 Claude Sonnet 4.6,請使用
claude-sonnet-4-6 - 如要在 Google Cloud 使用 Anthropic 的 Claude Opus 4.5,請使用
claude-opus-4-5 - 如要在 Google Cloud 使用 Anthropic 的 Claude Sonnet 4.5,請使用
claude-sonnet-4-5 - 如要在 Google Cloud 使用 Claude 3.7 Sonnet,請使用
claude-3-7-sonnet - 如要在 Google Cloud 使用 Claude 3.5 Sonnet v2,請使用
claude-3-5-sonnet-v2 - 如要在 Google Cloud 使用 Anthropic 的 Claude Haiku 5.5,請使用
claude-haiku-5-5 - 如要在 Google Cloud 使用 Anthropic 的 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 實施政策,禁止特定經銷商轉售其產品。如果您的 Cloud de Confiance by S3NS 帳單帳戶是由受禁經銷商管理,您將無法接受《服務條款》或啟用 Claude 模型。如果發生這種情況,請直接與經銷商聯絡。
如要透過 Gemini Enterprise Agent Platform 使用 Anthropic Claude 模型,請務必完成下列步驟。必須啟用 Agent Platform API (aiplatform.googleapis.com),才能使用 Gemini Enterprise Agent Platform。如果已有專案啟用 Agent Platform API,則可直接使用,不必建立新專案。
請確認您具備必要權限,可啟用及使用合作夥伴模型。詳情請參閱「授予必要權限」。
-
In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 Cloud de Confiance project.
Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.
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 模型資訊卡,然後按一下「Enable」(啟用):
- 前往 Google Cloud 的 Anthropic Claude Sonnet 5.5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Fable 5.1 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Sonnet 5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 5.5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Fable 5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 4.8 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 4.7 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 4.6 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Sonnet 4.6 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Opus 4.5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Sonnet 4.5 模型資訊卡
- 前往 Google Cloud 的 Anthropic Claude Haiku 5.5 模型資訊卡
- 前往 Google Cloud 的 Anthropic 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,模型會依據溫度參數選擇 A 或 B 做為下一個詞元,並排除 C。如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。
- TOP_K(選用):Top-K 會影響模型選取輸出詞元的方式。如果 Top-K 設為
1,代表下一個所選詞元是模型詞彙表的所有詞元中可能性最高者 (也稱為「貪婪解碼」)。如果 Top-K 設為3,則代表模型會依據溫度參數,從可能性最高的 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,在 Cloud de Confiance 控制台快速建立生成式 AI 模型原型並進行測試。舉例來說,您可以使用 Gemini Enterprise Agent Platform 的 Agent Studio,比較 Claude 模型與其他支援模型 (例如 Google Gemini) 的回覆。
詳情請參閱「快速入門導覽課程:使用 Gemini Enterprise Agent Platform 的 Agent Studio 向 Gemini 傳送文字提示詞」。