Vertex AI
Vertex AI API
Anthropic 的 Claude 模型現在可以通過 Vertex AI 普遍使用。
用於訪問 Claude 的 Vertex API 與 Messages API 幾乎相同,並支持所有相同的選項,但有兩個關鍵區別:
- 在 Vertex 中,
model
不在請求正文中傳遞。相反,它在 Google Cloud 端點 URL 中指定。 - 在 Vertex 中,
anthropic_version
在請求正文中傳遞(而不是作為標頭),並且必須設置為值vertex-2023-10-16
。
Vertex 也受 Anthropic 官方 客戶端 SDK 的支持。本指南將引導您完成在 Python 或 TypeScript 中向 Vertex AI 上的 Claude 發出請求的過程。
請注意,本指南假設您已經有一個可以使用 Vertex AI 的 GCP 項目。有關所需設置的更多信息以及完整的演練,請參閱 使用來自 Anthropic 的 Claude 3 模型。
安裝用於訪問 Vertex AI 的 SDK
首先,安裝您選擇的語言的 Anthropic 客戶端 SDK。
訪問 Vertex AI
模型可用性
請注意,Anthropic 模型的可用性因地區而異。在 Vertex AI 模型花園 中搜索 “Claude”,或轉到 使用 Claude 3 以獲取最新信息。
API 模型名稱
模型 | Vertex AI API 模型名稱 |
---|---|
Claude 3 Haiku | claude-3-haiku@20240307 |
Claude 3 Sonnet | claude-3-sonnet@20240229 |
Claude 3 Opus (公開預覽) | claude-3-opus@20240229 |
發出請求
在運行請求之前,您可能需要運行 gcloud auth application-default login
以使用 GCP 進行身份驗證。
以下示例顯示如何在 Vertex AI 上從 Claude 3 Haiku 生成文本:
有關更多詳細信息,請參閱我們的 客戶端 SDK 和官方 Vertex AI 文檔。