Claude Platform Docs
MessagesGoogle Cloud

Claude Models on Google Cloud (Google managed)

Google 将 Claude Models on Google Cloud (Google managed) 作为 Google Cloud's Agent Platform 的一部分进行运营。您可以使用 Anthropic 的客户端 SDK 调用 Claude。

Claude Models on Google Cloud 对比了这两种 Google Cloud 产品,并说明了如何判断您使用的是哪一种。

进行 API 调用之前

要使用 Claude Models on Google Cloud (Google managed),您需要:

  1. 一个可以使用 Agent Platform 的 Google Cloud 项目。有关设置步骤,请参阅 Google Cloud 的 Anthropic Claude models on Agent Platform 页面。
  2. 已安装 gcloud CLI,用于本地开发。
  3. 对于发起调用的身份,需要一个包含 aiplatform.endpoints.predict 权限的 IAM 角色,例如 Agent Platform User(roles/aiplatform.user)。有关详细信息,请参阅 Google Cloud 的 Agent Platform partner models 页面。
  4. 该身份的 Google Cloud 凭据。对于 SDK 示例,您可能需要运行 gcloud auth application-default login 以向 Google Cloud 进行身份验证。Claude Models on Google Cloud (Google managed) 的 cURL 示例通过 gcloud auth print-access-token 获取令牌。该命令使用 gcloud CLI 自身的登录,而不是 Application Default Credentials。对于这些示例,请先运行 gcloud auth login 或 gcloud init。

安装 SDK

Anthropic 的客户端 SDK 通过 AnthropicVertex 支持 Claude Models on Google Cloud (Google managed)。请安装提供它的软件包:

pip install -U "anthropic[vertex]"

ant CLI 不支持 Claude Models on Google Cloud (Google managed)。

发起请求

发往 Claude Models on Google Cloud (Google managed) 的请求会发送到以 :rawPredict 结尾的 Agent Platform 端点 URL。"Streaming"(流式传输)请求则改用 :streamRawPredict。

请求与 Messages API 请求几乎完全相同,主要有两点区别:

  • 模型: 端点 URL 中指定了模型。在 cURL 请求中,请勿在请求体中包含 model。
  • 版本: 在 cURL 请求中,请在请求体中传递 anthropic_version,而不是作为请求头传递。将其设置为 vertex-2023-10-16,或设置为 API 版本 2026-10-21。

以下示例使用全局端点。有关其他端点类型,请参阅全局、多区域和区域端点。

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-5-5",
    max_tokens=100,
    messages=[
        {
            "role": "user",
            "content": "Hey Claude!",
        }
    ],
)
print(message)

API 模型 ID

ModelAgent Platform API model ID
Claude Fable 5.1
Claude Mythos 5.1 (limited availability)
Claude Fable 5
Claude Mythos 5 (limited availability)
Claude Opus 5.5
Claude Opus 5
Claude Opus 4.8
Claude Opus 4.7
Claude Opus 4.6
Claude Opus 4.5
Claude Opus 4.1 (deprecated)
Claude Opus 4 (deprecated)
Claude Sonnet 5.5
Claude Sonnet 5
Claude Sonnet 4.6
Claude Sonnet 4.5 (deprecated)
Claude Sonnet 4 (deprecated)
Claude Haiku 5.5
Claude Haiku 4.5
Claude Haiku 3.5 (deprecated)

Claude Models on Google Cloud (Google managed) 在不同区域提供不同的 Claude 模型。要查看某个区域提供哪些模型,请在 Model Garden 中搜索"Claude",或参阅 Google Cloud 的 Anthropic Claude models on Agent Platform 页面。

Google 为 Claude Models on Google Cloud (Google managed) 所提供的模型设定生命周期日期。这些日期可能与 Claude API 的时间表不同。有关模型当前的停用日期,请参阅 Google Cloud 的 Anthropic Claude models on Agent Platform 页面。有关"已弃用"和"已停用"的含义,请参阅模型弃用。

全局、多区域和区域端点

Claude Models on Google Cloud (Google managed) 提供三种端点类型。您可以通过创建客户端时传入的区域值来选择其中一种。在 cURL 请求中,端点类型决定了主机以及 URL 中的 locations 段。

端点类型区域值主机
全局(推荐)"global"aiplatform.googleapis.com
多区域"us" 或 "eu"aiplatform.us.rep.googleapis.com
aiplatform.eu.rep.googleapis.com
区域某个区域,例如 "us-east5"{region}-aiplatform.googleapis.com

这些端点类型的区别在于请求的发送目的地:

  • 全局: 请求会发送到任何有可用容量的区域。当您希望获得最高可用性且对数据驻留要求灵活时,请使用此类型。
  • 多区域: 请求会发送到美国("us")或欧盟("eu")内的任何区域。当您需要在较大地理范围内实现数据驻留,并且需要比单一区域更高的可用性时,请使用此类型。
  • 区域: 请求仅发送到您指定的区域,例如 "us-east5" 或 "europe-west1"。当您需要单一区域的数据驻留或必须满足严格的合规要求时,请使用此类型。

多区域和区域端点的费用比全局端点高 10%。三种端点类型都支持按需付费流量,而预配吞吐量需要使用区域端点。

区域端点仅提供 Claude Sonnet 4.6 及更早的模型。对于更新的模型,请使用全局或多区域端点。

以下示例使用 us 多区域端点。高亮的行用于设置区域。有关在全局端点上的完整请求,请参阅发起请求。

from anthropic import AnthropicVertex

project_id = "MY_PROJECT_ID"
region = "us"  # Multi-region identifier: "us" or "eu"

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

功能支持

Claude Models on Google Cloud (Google managed) 支持的功能包括:

功能概览列出了所有功能,以及 Claude Models on Google Cloud (Google managed) 是否支持这些功能。

不支持的功能

Claude Models on Google Cloud (Google managed) 不支持以下功能:

  • 输入源: 图像和文档的 URL 源,以及 Files API
  • 服务器端工具: 代码执行、网页获取和顾问
  • 智能体基础设施: Agent Skills、MCP 连接器和程序化工具调用
  • API 端点: Message Batches API、Models API、Admin API、Compliance API 以及 Usage and Cost API
  • Claude Managed Agents
  • 服务器端回退: fallbacks 参数

请使用客户端回退模式代替服务器端回退。

上下文窗口

Claude Models on Google Cloud (Google managed) 为以下模型提供 1M 令牌的"context window"(上下文窗口):

  • Claude Fable 5.1
  • Claude Fable 5
  • Claude Opus 5.5
  • Claude Opus 5
  • Claude Opus 4.8
  • Claude Opus 4.7
  • Claude Opus 4.6
  • Claude Sonnet 5.5
  • Claude Sonnet 5
  • Claude Sonnet 4.6
  • Claude Haiku 5.5

其他 Claude 模型的上下文窗口为 200k 令牌,其中包括 Claude Sonnet 4.5(已弃用)和 Claude Sonnet 4(已弃用)。

Agent Platform 将请求负载限制为 30 MB。当您发送大型文档或大量图像时,可能会在达到令牌限制之前先达到此限制。

计费、速率限制和日志记录

速率限制

Google Cloud 管理 Claude Models on Google Cloud (Google managed) 的"rate limit"(速率限制)和配额。有关详细信息,包括如何申请提高配额,请参阅 Google Cloud 的 Quotas for Anthropic Claude models 页面。

计费

Google Cloud 会就 Claude Models on Google Cloud (Google managed) 向您开具账单。有关价格,请参阅 Google Cloud 的 Generative AI pricing 页面。价格还取决于端点类型。请参阅全局、多区域和区域端点。

数据保留

Google Cloud 负责管理 Claude Models on Google Cloud (Google managed) 的数据处理。有关详细信息,请参阅 Agent Platform and zero data retention。

监控和日志记录

要记录 Claude Models on Google Cloud (Google managed) 的提示和补全内容,请使用 Agent Platform 的请求-响应日志记录服务。

Anthropic 建议您至少保留最近 30 天的日志。这些日志有助于您了解自己的活动并调查可能的滥用行为。

从 Claude Models on Google Cloud (Anthropic managed) 迁移

有关迁移时会发生哪些变化,请参阅两种 Google Cloud 产品的区别。要迁移到 Claude Models on Google Cloud (Google managed),请按照以下步骤操作:

  1. 设置访问权限

    检查您的项目以及发起调用的身份是否满足进行 API 调用之前中的要求。

  2. 安装 SDK 软件包

    安装为 Claude Models on Google Cloud (Google managed) 提供客户端的软件包。请参阅安装 SDK。

  3. 替换导入和客户端

    修改导入和创建客户端的代码。使用 AnthropicVertex 代替 AnthropicGoogleCloud。cURL 请求需要新的 URL、新的请求头和新的请求体。以下代码创建您当前使用的 Claude Models on Google Cloud (Anthropic managed) 客户端:

    from anthropic import AnthropicGoogleCloud
    
    client = AnthropicGoogleCloud()

    以下代码创建 Claude Models on Google Cloud (Google managed) 的客户端。它使用全局端点。有关其他端点类型,请参阅全局、多区域和区域端点。

    from anthropic import AnthropicVertex
    
    project_id = "MY_PROJECT_ID"
    region = "global"
    
    client = AnthropicVertex(project_id=project_id, region=region)

    此代码在创建客户端时传入您的项目 ID 和区域。请将 MY_PROJECT_ID 替换为您的项目 ID。您使用该客户端进行的 Messages API 调用保持不变,例外情况是下一步中的模型 ID 和功能。

  4. 检查模型 ID 和功能

    • 模型 ID: 如果您使用的是早于 Claude 4.6 的模型,请将其 ID 中快照日期前的连字符替换为 @。例如,claude-haiku-4-5-20251001 变为 claude-haiku-4-5@20251001。有关模型及其 ID,请参阅 API 模型 ID。
    • 功能: 检查您的代码所使用的功能是否未列在不支持的功能中。
  5. 运行测试请求

    运行发起请求中的请求,以检查您的设置是否正常工作。然后运行您自己的代码。在迁移生产流量之前,请阅读 Claude Models on Google Cloud (Google managed) 的速率限制。

后续步骤

Was this page helpful?