Loading...
  • 建構
  • 管理
  • 模型與定價
  • 客戶端 SDK
  • API 參考
Search...
⌘K
Log in
Vertex AI
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
管理/第三方平台

Vertex AI 上的 Claude

Anthropic 的 Claude 模型現已通過 Vertex AI 正式推出。

用於存取 Claude 的 Vertex API 幾乎與 Messages API 相同,並支援所有相同的選項,但有兩個主要差異:

  • 在 Vertex 中,model 不在請求正文中傳遞。相反,它在 Google Cloud 端點 URL 中指定。
  • 在 Vertex 中,anthropic_version 在請求正文中傳遞(而不是作為標頭),並且必須設定為值 vertex-2023-10-16。

Vertex 也受到 Anthropic 官方 client SDKs 的支援。本指南將引導您使用 Anthropic 的其中一個 client SDK 向 Vertex AI 上的 Claude 發出請求。

請注意,本指南假設您已經有一個能夠使用 Vertex AI 的 GCP 專案。有關所需設定的更多資訊以及完整的逐步說明,請參閱 使用 Anthropic 的 Claude 3 模型。

安裝用於存取 Vertex AI 的 SDK

首先,為您選擇的語言安裝 Anthropic 的 client SDK。

存取 Vertex AI

模型可用性

請注意,Anthropic 模型的可用性因地區而異。在 Vertex AI Model Garden 中搜尋「Claude」或前往 使用 Claude 3 以取得最新資訊。

API 模型 ID

模型Vertex AI API 模型 ID
Claude Opus 4.7claude-opus-4-7
Claude Opus 4.6claude-opus-4-6
Claude Sonnet 4.6claude-sonnet-4-6
Claude Sonnet 4.5claude-sonnet-4-5@20250929
Claude Sonnet 4 ⚠️claude-sonnet-4@20250514
Claude Sonnet 3.7 ⚠️claude-3-7-sonnet@20250219
Claude Opus 4.5claude-opus-4-5@20251101
Claude Opus 4.1claude-opus-4-1@20250805
Claude Opus 4 ⚠️claude-opus-4@20250514
Claude Haiku 4.5claude-haiku-4-5@20251001
Claude Haiku 3.5 ⚠️claude-3-5-haiku@20241022
Claude Haiku 3 ⚠️claude-3-haiku@20240307

發出請求

在執行請求之前,您可能需要執行 gcloud auth application-default login 以使用 GCP 進行身份驗證。

以下範例顯示如何從 Vertex AI 上的 Claude 生成文字:

from anthropic import AnthropicVertex

project_id = "MY_PROJECT_ID"
region = "global"

client = AnthropicVertex(project_id=project_id, region=region)

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=100,
    messages=[
        {
            "role": "user",
            "content": "Hey Claude!",
        }
    ],
)
print(message)

有關更多詳細資訊,請參閱 client SDKs 和官方 Vertex AI 文件。

Claude 也可通過 Amazon Bedrock 和 Microsoft Foundry 取得。

活動日誌

Vertex 提供 請求-回應日誌服務,允許客戶記錄與您的使用相關的提示和完成。

Anthropic 建議您至少在 30 天滾動基礎上記錄您的活動,以便了解您的活動並調查任何潛在的濫用。

啟用此服務不會給 Google 或 Anthropic 任何存取您內容的權限。

功能支援

有關 Vertex AI 上目前支援的所有功能,請參閱 API 功能概述。

上下文視窗

Claude Opus 4.7、Claude Opus 4.6 和 Claude Sonnet 4.6 在 Vertex AI 上有 1M 令牌上下文視窗。其他 Claude 模型,包括 Sonnet 4.5 和 Sonnet 4(已棄用),有 200k 令牌上下文視窗。

Vertex AI 將請求有效負載限制為 30 MB。發送大型文件或許多影像時,您可能會在達到令牌限制之前達到此限制。

全球、多區域和區域端點

Google Vertex AI 提供三種端點類型:

  • 全球端點: 動態路由以實現最大可用性
  • 多區域端點: 在地理區域內(例如美國或歐盟)進行動態路由,以實現具有高可用性的資料駐留
  • 區域端點: 通過特定地理區域保證資料路由

區域和多區域端點包括相對於全球端點的 10% 定價溢價。

這僅適用於 Claude Sonnet 4.5 和未來的模型。較舊的模型(Claude Sonnet 4(已棄用)、Opus 4(已棄用)及更早版本)保持其現有的定價結構。

何時使用每個選項

全球端點(推薦):

  • 提供最大可用性和正常運行時間
  • 動態將請求路由到具有可用容量的區域
  • 無定價溢價
  • 最適合資料駐留靈活的應用程式
  • 僅支援按使用量付費流量(預配吞吐量需要區域端點)

多區域端點:

  • 在地理區域內的區域間動態路由請求(目前為 us 和 eu)
  • 當您需要在廣泛地理範圍內進行資料駐留但希望比單一區域有更高的可用性時很有用
  • 相對於全球端點的 10% 定價溢價
  • 僅支援按使用量付費流量(預配吞吐量需要區域端點)

區域端點:

  • 通過特定地理區域路由流量
  • 單一區域資料駐留、嚴格合規性要求或預配吞吐量所需
  • 支援按使用量付費和預配吞吐量
  • 10% 定價溢價反映了專用區域容量的基礎設施成本

實施

使用全球端點(推薦):

初始化用戶端時,將 region 參數設定為 "global":

from anthropic import AnthropicVertex

project_id = "MY_PROJECT_ID"
region = "global"

client = AnthropicVertex(project_id=project_id, region=region)

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=100,
    messages=[
        {
            "role": "user",
            "content": "Hey Claude!",
        }
    ],
)
print(message)

使用多區域端點:

將 region 參數設定為多區域識別碼:"us" 表示美國,"eu" 表示歐盟。SDK 將請求路由到相應的多區域端點(https://aiplatform.us.rep.googleapis.com 或 https://aiplatform.eu.rep.googleapis.com),該端點在該地理範圍內的區域間動態平衡流量。

from anthropic import AnthropicVertex

project_id = "MY_PROJECT_ID"
region = "us"  # 多區域識別碼:"us" 或 "eu"

client = AnthropicVertex(project_id=project_id, region=region)

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=100,
    messages=[
        {
            "role": "user",
            "content": "Hey Claude!",
        }
    ],
)
print(message)

使用區域端點:

指定特定區域,例如 "us-east1" 或 "europe-west1":

from anthropic import AnthropicVertex

project_id = "MY_PROJECT_ID"
region = "us-east1"  # 指定特定區域

client = AnthropicVertex(project_id=project_id, region=region)

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=100,
    messages=[
        {
            "role": "user",
            "content": "Hey Claude!",
        }
    ],
)
print(message)

Claude Mythos Preview 是一個研究預覽版本,可供 Google Vertex AI 上的受邀客戶使用。有關更多資訊,請參閱 Project Glasswing。

其他資源

  • Google Vertex AI 定價: cloud.google.com/vertex-ai/generative-ai/pricing
  • Claude 模型文件: Vertex AI 上的 Claude
  • Google 部落格文章: Claude 模型的全球端點
  • Anthropic 定價詳細資訊: 定價文件

Was this page helpful?

  • 安裝用於存取 Vertex AI 的 SDK
  • 存取 Vertex AI