Claude Models on Google Cloud 对比了这两种 Google Cloud 产品,并说明了如何判断您使用的是哪一种。
进行 API 调用之前
要使用 Claude Models on Google Cloud (Google managed),您需要:
- 一个可以使用 Agent Platform 的 Google Cloud 项目。有关设置步骤,请参阅 Google Cloud 的 Anthropic Claude models on Agent Platform 页面。
- 已安装 gcloud CLI,用于本地开发。
- 对于发起调用的身份,需要一个包含
aiplatform.endpoints.predict权限的 IAM 角色,例如 Agent Platform User(roles/aiplatform.user)。有关详细信息,请参阅 Google Cloud 的 Agent Platform partner models 页面。 - 该身份的 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 (csharp: AnthropicVertexClient; go: vertex.WithGoogleAuth(); java: VertexBackend; php: Anthropic\Vertex\Client; ruby: Anthropic::VertexClient) 支持 Claude Models on Google Cloud (Google managed)。请安装提供它的软件包:
Python
pip install -U "anthropic[vertex]"
TypeScript
npm install @anthropic-ai/vertex-sdk
C#
dotnet add package Anthropic.Vertex
Go
go get github.com/anthropics/anthropic-sdk-go/v2
Java
Gradle
implementation("com.anthropic:anthropic-java:3.3.0")
implementation("com.anthropic:anthropic-java-vertex:3.3.0")
Maven
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java-vertex</artifactId>
<version>3.3.0</version>
</dependency>
PHP
composer require anthropic-ai/sdk google/auth
Ruby
# Gemfile
gem "anthropic"
gem "googleauth"
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。
以下示例使用全局端点。有关其他端点类型,请参阅全局、多区域和区域端点。
cURL
curl https://aiplatform.googleapis.com/v1/projects/MY_PROJECT_ID/locations/global/publishers/anthropic/models/claude-opus-5-5:rawPredict \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"anthropic_version": "vertex-2023-10-16",
"messages": [{"role": "user", "content": "Hey Claude!"}],
"max_tokens": 100
}'
CLI
ant CLI 不支持 Claude Models on Google Cloud (Google managed)。
Python
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)
TypeScript
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
const projectId = "MY_PROJECT_ID";
const region = "global";
// 走标准的 `google-auth-library` 认证流程。
const client = new AnthropicVertex({
projectId,
region
});
const result = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 100,
messages: [
{
role: "user",
content: "Hey Claude!"
}
]
});
console.log(JSON.stringify(result, null, 2));
C#
using Anthropic.Models.Messages;
using Anthropic.Vertex;
var projectId = "MY_PROJECT_ID";
var region = "global";
var client = new AnthropicVertexClient(new AnthropicVertexCredentials(region, projectId));
var parameters = new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 100,
Messages = [new UserMessageParam { Content = "Hey Claude!" }]
};
var message = await client.Messages.Create(parameters);
Console.WriteLine(message);
Go
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go/v2"
"github.com/anthropics/anthropic-sdk-go/v2/vertex"
)
// ...
// 使用默认的 Google Cloud 凭据
client := anthropic.NewClient(
vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
)
message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 100,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
},
})
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", message)
Java
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.messages.Message;
import com.anthropic.models.messages.MessageCreateParams;
import com.anthropic.models.messages.Model;
import com.anthropic.vertex.backends.VertexBackend;
import com.google.auth.oauth2.GoogleCredentials;
void main() throws Exception {
AnthropicClient client = AnthropicOkHttpClient.builder()
.backend(
VertexBackend.builder()
.googleCredentials(GoogleCredentials.getApplicationDefault())
.region("global")
.project("MY_PROJECT_ID")
.build()
)
.build();
Message message = client
.messages()
.create(
MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(100)
.addUserMessage("Hey Claude!")
.build()
);
IO.println(message);
}
PHP
<?php
use Anthropic\Messages\TextBlock;
use Anthropic\Vertex;
$client = Vertex\Client::fromEnvironment(
region: 'global',
projectId: 'MY_PROJECT_ID',
);
$message = $client->messages->create(
maxTokens: 100,
messages: [
['role' => 'user', 'content' => 'Hey Claude!']
],
model: 'claude-opus-5-5',
);
foreach ($message->content as $block) {
if ($block instanceof TextBlock) {
echo $block->text . PHP_EOL;
}
}
Ruby
require "anthropic"
client = Anthropic::VertexClient.new(
region: "global",
project_id: "MY_PROJECT_ID"
)
message = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 100,
messages: [{role: "user", content: "Hey Claude!"}]
)
puts message.content.find { it.type == :text }.text
API 模型 ID
| Model | Agent Platform API model ID |
|---|---|
| Claude Fable 5.1 | claude-fable-5-1 |
| Claude Mythos 5.1 (limited availability) | claude-mythos-5-1 |
| Claude Fable 5 | claude-fable-5 |
| Claude Mythos 5 (limited availability) | claude-mythos-5 |
| Claude Opus 5.5 | claude-opus-5-5 |
| Claude Opus 5 | claude-opus-5 |
| Claude Opus 4.8 | claude-opus-4-8 |
| Claude Opus 4.7 | claude-opus-4-7 |
| Claude Opus 4.6 | claude-opus-4-6 |
| Claude Opus 4.5 | claude-opus-4-5@20251101 |
| Claude Opus 4.1 (deprecated) | claude-opus-4-1@20250805 |
| Claude Opus 4 (deprecated) | claude-opus-4@20250514 |
| Claude Sonnet 5.5 | claude-sonnet-5-5 |
| Claude Sonnet 5 | claude-sonnet-5 |
| Claude Sonnet 4.6 | claude-sonnet-4-6 |
| Claude Sonnet 4.5 (deprecated) | claude-sonnet-4-5@20250929 |
| Claude Sonnet 4 (deprecated) | claude-sonnet-4@20250514 |
| Claude Haiku 5.5 | claude-haiku-5-5 |
| Claude Haiku 4.5 | claude-haiku-4-5@20251001 |
| Claude Haiku 3.5 (deprecated) | claude-3-5-haiku@20241022 |
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 Mythos Preview 是一项研究预览。Claude Models on Google Cloud (Google managed) 向受邀客户提供该模型。有关更多信息,请参阅 Project Glasswing。
让 Claude Code 将您的代码迁移到更新的模型
/claude-api migrate 将此项目迁移到最新的 Claude Opus 模型
全局、多区域和区域端点
Claude Models on Google Cloud (Google managed) 提供三种端点类型。您可以通过创建客户端时传入的区域值来选择其中一种。在 cURL 请求中,端点类型决定了主机以及 URL 中的 locations 段。
| 端点类型 | 区域值 | 主机 |
|---|---|---|
| 全局(推荐) | "global" |
aiplatform.googleapis.com |
| 多区域 | "us" 或 "eu" |
aiplatform.us.rep.googleapis.comaiplatform.eu.rep.googleapis.com |
| 区域 | 某个区域,例如 "us-east5" |
{region}-aiplatform.googleapis.com |
这些端点类型的区别在于请求的发送目的地:
- 全局: 请求会发送到任何有可用容量的区域。当您希望获得最高可用性且对数据驻留要求灵活时,请使用此类型。
- 多区域: 请求会发送到美国(
"us")或欧盟("eu")内的任何区域。当您需要在较大地理范围内实现数据驻留,并且需要比单一区域更高的可用性时,请使用此类型。 - 区域: 请求仅发送到您指定的区域,例如
"us-east5"或"europe-west1"。当您需要单一区域的数据驻留或必须满足严格的合规要求时,请使用此类型。
多区域和区域端点的费用比全球端点高 10%。三种端点类型都支持按需付费流量,而预配吞吐量需要使用区域端点。
区域端点仅提供 Claude Sonnet 4.6 及更早的模型。对于更新的模型,请使用全局或多区域端点。
注意
多区域和区域端点的溢价仅适用于 Claude Sonnet 4.5(已弃用)及更高版本的模型。有关保留原有定价的模型,请参阅云平台定价。对于区域端点,溢价反映了专用区域容量的基础设施成本。
以下示例使用 us 多区域端点。高亮的行用于设置区域。有关在全局端点上的完整请求,请参阅发起请求。
cURL
# 多区域标识符("us" 或 "eu")同时出现在主机名和路径中
curl https://aiplatform.us.rep.googleapis.com/v1/projects/MY_PROJECT_ID/locations/us/publishers/anthropic/models/claude-opus-5-5:rawPredict \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"anthropic_version": "vertex-2023-10-16",
"messages": [{"role": "user", "content": "Hey Claude!"}],
"max_tokens": 100
}'
CLI
ant CLI 不支持 Claude Models on Google Cloud (Google managed)。
Python
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)
TypeScript
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
const projectId = "MY_PROJECT_ID";
const region = "us"; // Multi-region identifier: "us" or "eu"
const client = new AnthropicVertex({
projectId,
region
});
C#
using Anthropic.Vertex;
var projectId = "MY_PROJECT_ID";
var region = "us"; // Multi-region identifier: "us" or "eu"
var client = new AnthropicVertexClient(new AnthropicVertexCredentials(region, projectId));
Go
import (
"context"
"github.com/anthropics/anthropic-sdk-go/v2"
"github.com/anthropics/anthropic-sdk-go/v2/vertex"
)
// ...
// 多区域标识符:"us" 或 "eu"
client := anthropic.NewClient(
vertex.WithGoogleAuth(context.Background(), "us", "MY_PROJECT_ID"),
)
Java
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.vertex.backends.VertexBackend;
import com.google.auth.oauth2.GoogleCredentials;
void main() throws Exception {
// 多区域标识符:"us" 或 "eu"
AnthropicClient client = AnthropicOkHttpClient.builder()
.backend(
VertexBackend.builder()
.googleCredentials(GoogleCredentials.getApplicationDefault())
.region("us")
.project("MY_PROJECT_ID")
.build()
)
.build();
}
PHP
use Anthropic\Vertex;
$client = Vertex\Client::fromEnvironment(
region: 'us', // Multi-region identifier: "us" or "eu"
projectId: 'MY_PROJECT_ID',
);
Ruby
require "anthropic"
client = Anthropic::VertexClient.new(
region: "us", # Multi-region identifier: "us" or "eu"
project_id: "MY_PROJECT_ID"
)
功能支持
Claude Models on Google Cloud (Google managed) 支持的功能包括:
-
“Tool use”(工具使用),包括以下工具:
功能概览列出了所有功能,以及 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 天的日志。这些日志有助于您了解自己的活动并调查可能的滥用行为。
注意
启用此服务不会让 Google 或 Anthropic 获得对您内容的任何访问权限。
从 Claude Models on Google Cloud (Anthropic managed) 迁移
有关迁移时会发生哪些变化,请参阅两种 Google Cloud 产品的区别。要迁移到 Claude Models on Google Cloud (Google managed),请按照以下步骤操作:
-
设置访问权限
检查您的项目以及发起调用的身份是否满足进行 API 调用之前中的要求。
-
安装 SDK 软件包
安装为 Claude Models on Google Cloud (Google managed) 提供客户端的软件包。请参阅安装 SDK。
-
替换导入和客户端
修改导入和创建客户端的代码。使用
AnthropicVertex(csharp:AnthropicVertexClient; go:vertex.WithGoogleAuth(); java:VertexBackend; php:Anthropic\Vertex\Client; ruby:Anthropic::VertexClient) 代替AnthropicGoogleCloud(csharp:AnthropicGoogleCloudClient; go:googlecloud.NewClient(); java:GoogleCloudBackend; php:Anthropic\GoogleCloud\Client; ruby:Anthropic::GoogleCloudClient)。cURL 请求需要新的 URL、新的请求头和新的请求体。以下代码创建您目前使用的 Claude Models on Google Cloud (Anthropic managed) 客户端:cURL
curl "https://claude.googleapis.com/v1/projects/$ANTHROPIC_GOOGLE_CLOUD_PROJECT/locations/global/workspaces/$ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID/invoke/v1/messages" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ -H "content-type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "claude-opus-5-5", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello, Claude"} ] }'CLI
ant messages create \ --model claude-opus-5-5 \ --max-tokens 1024 \ --message '{role: user, content: "Hello, Claude"}'Python
from anthropic import AnthropicGoogleCloud client = AnthropicGoogleCloud()TypeScript
import { AnthropicGoogleCloud } from "@anthropic-ai/google-cloud-sdk"; const client = new AnthropicGoogleCloud();C#
using Anthropic.GoogleCloud; var client = new AnthropicGoogleCloudClient();Go
import ( "context" "github.com/anthropics/anthropic-sdk-go/v2" "github.com/anthropics/anthropic-sdk-go/v2/googlecloud" ) // ... client, err := googlecloud.NewClient(context.Background(), googlecloud.ClientConfig{}) if err != nil { panic(err) }Java
import com.anthropic.client.AnthropicClient; import com.anthropic.client.okhttp.AnthropicOkHttpClient; import com.anthropic.googlecloud.backends.GoogleCloudBackend; void main() { AnthropicClient client = AnthropicOkHttpClient.builder() .backend(GoogleCloudBackend.fromEnv()) .build(); }PHP
use Anthropic\GoogleCloud\Client; $client = new Client();Ruby
require "anthropic" client = Anthropic::GoogleCloudClient.new以下代码创建 Claude Models on Google Cloud (Google managed) 的客户端。它使用全局端点。有关其他端点类型,请参阅全局、多区域和区域端点。
cURL
curl https://aiplatform.googleapis.com/v1/projects/MY_PROJECT_ID/locations/global/publishers/anthropic/models/claude-opus-5-5:rawPredict \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "anthropic_version": "vertex-2023-10-16", "messages": [{"role": "user", "content": "Hey Claude!"}], "max_tokens": 100 }'CLI
antCLI 不支持 Claude Models on Google Cloud (Google managed)。请改用 cURL 或 SDK。Python
from anthropic import AnthropicVertex project_id = "MY_PROJECT_ID" region = "global" client = AnthropicVertex(project_id=project_id, region=region)TypeScript
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk"; const projectId = "MY_PROJECT_ID"; const region = "global"; const client = new AnthropicVertex({ projectId, region });C#
using Anthropic.Vertex; var projectId = "MY_PROJECT_ID"; var region = "global"; var client = new AnthropicVertexClient(new AnthropicVertexCredentials(region, projectId));Go
import ( "context" "github.com/anthropics/anthropic-sdk-go/v2" "github.com/anthropics/anthropic-sdk-go/v2/vertex" ) // ... // 使用默认的 Google Cloud 凭据 client := anthropic.NewClient( vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"), )Java
import com.anthropic.client.AnthropicClient; import com.anthropic.client.okhttp.AnthropicOkHttpClient; import com.anthropic.vertex.backends.VertexBackend; import com.google.auth.oauth2.GoogleCredentials; void main() throws Exception { AnthropicClient client = AnthropicOkHttpClient.builder() .backend( VertexBackend.builder() .googleCredentials(GoogleCredentials.getApplicationDefault()) .region("global") .project("MY_PROJECT_ID") .build() ) .build(); }PHP
use Anthropic\Vertex; $client = Vertex\Client::fromEnvironment( region: 'global', projectId: 'MY_PROJECT_ID', );Ruby
require "anthropic" client = Anthropic::VertexClient.new( region: "global", project_id: "MY_PROJECT_ID" )此代码在创建客户端时传入您的项目 ID 和区域。请将
MY_PROJECT_ID替换为您的项目 ID。您使用该客户端进行的 Messages API 调用保持不变,例外情况是下一步中的模型 ID 和功能。 -
检查模型 ID 和功能
-
运行测试请求
运行发起请求中的请求,以检查您的设置是否正常工作。然后运行您自己的代码。在迁移生产流量之前,请阅读 Claude Models on Google Cloud (Google managed) 的速率限制。
后续步骤
-
功能概览:探索 Claude 的功能。
-
Anthropic Claude models on Agent Platform:查看每个区域提供哪些 Claude 模型及其停用日期。
-
Agent Platform 文档:阅读 Google Cloud 的 Agent Platform 文档。
-
Claude 模型的全局端点:阅读 Google Cloud 关于 Claude 模型全局端点的博客文章。