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 支持。本指南將引導您完成在 Vertex AI 上使用 Python 或 TypeScript 向 Claude 發出請求的過程。
請注意,本指南假設您已經有一個可以使用 Vertex AI 的 GCP 項目。有關所需設置的更多信息以及完整的演示,請參閱 使用來自 Anthropic 的 Claude 3 模型。
安裝用於訪問 Vertex AI 的 SDK
首先,安裝 Anthropic 為您選擇的語言提供的 客戶端 SDK。
訪問 Vertex AI
模型可用性
請注意,Anthropic 模型的可用性因地區而異。在 Vertex AI Model Garden 中搜索 “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 |
Claude 3.5 Sonnet | claude-3-5-sonnet@20240620 |
發送請求
在運行請求之前,您可能需要運行 gcloud auth application-default login
來驗證 GCP。
以下示例展示了如何在 Vertex AI 上使用 Claude 3 Haiku 生成文本:
有關更多詳細信息,請參閱我們的 客戶端 SDK 和官方 Vertex AI 文檔。