Vol.17 · Claude with Google Cloud's Vertex AI

Vertex API、AnthropicVertex 与请求差异

Vertex 的 Claude 调用接近 Messages API,但 project、region、endpoint 和 anthropic_version 的位置都要搞清楚。

🟢 基础

SDK 调用

from anthropic import AnthropicVertex

client = AnthropicVertex(project_id="MY_PROJECT_ID", region="global")
message = client.messages.create(
    model="claude-sonnet-4-5@20250929",
    max_tokens=512,
    messages=[{"role": "user", "content": "Hello from Vertex"}],
)

多数 Messages API 概念可以复用;迁移重点是 client 初始化、model ID、project 与 region。

🔵 进阶

Vertex 原生差异

直接走 Vertex REST API 时,模型体现在 endpoint 路径中;anthropic_version 放在请求 body,值为 vertex-2023-10-16

Endpoint 策略

global 优先可用性;us / eu 兼顾地理边界;具体区域用于严格数据驻留或 provisioned throughput。

Anthropic 官方 SDK 提供 AnthropicVertex,让你用接近 Messages API 的方式调用 Vertex AI。主要差异在 client 初始化、project / region、模型 ID 与底层 Vertex endpoint。

如果直接走 Vertex REST API,model 不放在请求 body,而是在 Google Cloud endpoint 路径中;anthropic_version 放在 body,值为 vertex-2023-10-16

考点:Vertex 不使用 Bedrock 的 anthropic. 模型 ID 前缀。
考点:REST API 的 anthropic_version 在 body 中,值为 vertex-2023-10-16
考点:region / endpoint 会影响可用性、成本和数据驻留。
Lesson 03 速记 · Vertex API
本节小结:SDK 方式迁移成本最低。;Vertex 原生 API 的模型体现在 endpoint,anthropic_version 在 body。;region / endpoint 是架构配置,会影响可用性、成本和数据驻留。