---
title: Claude Models on Google Cloud (Google managed)
url: https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed
description: Google 將 Claude Models on Google Cloud (Google managed) 作為 Google Cloud's Agent Platform 的一部分來營運。您可以使用 Anthropic 的用戶端 SDK 呼叫 Claude。
---

[Claude Models on Google Cloud](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/overview) 比較了這兩種 Google Cloud 方案，並說明如何判斷您使用的是哪一種。

## 進行 API 呼叫之前

若要使用 Claude Models on Google Cloud (Google managed)，您需要：

1. 一個可以使用 Agent Platform 的 Google Cloud 專案。如需設定步驟，請參閱 Google Cloud 的 [Anthropic Claude models on Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude) 頁面。
2. 已安裝 [gcloud CLI](https://cloud.google.com/sdk/docs/install)，用於本機開發。
3. 對於進行呼叫的身分，需要一個包含 `aiplatform.endpoints.predict` 權限的 IAM 角色，例如 Agent Platform User（`roles/aiplatform.user`）。如需詳細資訊，請參閱 Google Cloud 的 [Agent Platform partner models](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/use-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](https://platform.claude.com/docs/zh-TW/cli-sdks-libraries/overview) 透過 `AnthropicVertex` (csharp: `AnthropicVertexClient`; go: `vertex.WithGoogleAuth`; java: `VertexBackend`; php: `Anthropic\Vertex\Client`; ruby: `Anthropic::VertexClient`) 支援 Claude Models on Google Cloud (Google managed)。請安裝提供它的套件：

<Tabs>
  <Tab title="Python">
    ```bash
    pip install -U "anthropic[vertex]"
    ```
  </Tab>

  <Tab title="TypeScript">
    ```bash
    npm install @anthropic-ai/vertex-sdk
    ```
  </Tab>

  <Tab title="C#">
    ```bash
    dotnet add package Anthropic.Vertex
    ```
  </Tab>

  <Tab title="Go">
    ```bash
    go get github.com/anthropics/anthropic-sdk-go
    ```
  </Tab>

  <Tab title="Java">
    <CodeGroup exclude="shell, python, typescript, csharp, go, php, ruby">
      ```groovy Gradle
      implementation("com.anthropic:anthropic-java:3.1.0")
      implementation("com.anthropic:anthropic-java-vertex:3.1.0")
      ```

      ```xml Maven
      <dependency>
          <groupId>com.anthropic</groupId>
          <artifactId>anthropic-java</artifactId>
          <version>3.1.0</version>
      </dependency>
      <dependency>
          <groupId>com.anthropic</groupId>
          <artifactId>anthropic-java-vertex</artifactId>
          <version>3.1.0</version>
      </dependency>
      ```
    </CodeGroup>
  </Tab>

  <Tab title="PHP">
    ```bash
    composer require anthropic-ai/sdk google/auth
    ```
  </Tab>

  <Tab title="Ruby">
    ```bash
    # Gemfile
    gem "anthropic"
    gem "googleauth"
    ```
  </Tab>
</Tabs>

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

## 發送請求

對 Claude Models on Google Cloud (Google managed) 的請求會傳送至以 `:rawPredict` 結尾的 Agent Platform 端點 URL。「Streaming」（串流）請求則改用 `:streamRawPredict`。

請求與 [Messages API](https://platform.claude.com/docs/zh-TW/api/messages/create) 請求幾乎相同，主要有兩點不同：

* **模型：** 端點 URL 會指定模型。在 cURL 請求中，請勿在主體中包含 `model`。
* **版本：** 在 cURL 請求中，請在主體中傳遞 `anthropic_version`，而非作為標頭。將其設為 `vertex-2023-10-16`，或設定為 [API 版本 `2026-10-21`](https://platform.claude.com/docs/zh-TW/api/migration-2026-10-21)。

以下範例使用全域端點。如需其他端點類型，請參閱[全域、多區域和區域端點](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#global-multi-region-and-regional-endpoints)。

<CodeGroup exclude="shell:CLI">
  ```bash 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
    }'
  ```

  <CodeGroupItem language="CLI">
    `ant` CLI 不支援 Claude Models on Google Cloud (Google managed)。
  </CodeGroupItem>

  ```python 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 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));
  ```

  ```csharp 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 Go
  import (
  	"context"
  	"fmt"

  	"github.com/anthropics/anthropic-sdk-go"
  	"github.com/anthropics/anthropic-sdk-go/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 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
  <?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 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
  ```
</CodeGroup>

### API 模型 ID

| Model                                                                                                    | Agent Platform API model ID  |
| :------------------------------------------------------------------------------------------------------- | :--------------------------- |
| Claude Fable 5.1                                                                                         | `claude-fable-5-1`           |
| Claude Mythos 5.1 ([limited availability](https://support.claude.com/en/articles/14604842))              | `claude-mythos-5-1`          |
| Claude Fable 5                                                                                           | `claude-fable-5`             |
| Claude Mythos 5 ([limited availability](https://support.claude.com/en/articles/14604842))                | `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](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations))   | `claude-opus-4-1@20250805`   |
| Claude Opus 4 ([deprecated](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations))     | `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](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations)) | `claude-sonnet-4-5@20250929` |
| Claude Sonnet 4 ([deprecated](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations))   | `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](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations))  | `claude-3-5-haiku@20241022`  |

Claude Models on Google Cloud (Google managed) 在不同區域提供不同的 Claude 模型。若要查看某個區域提供哪些模型，請在 [Model Garden](https://cloud.google.com/model-garden) 中搜尋「Claude」，或參閱 Google Cloud 的 [Anthropic Claude models on Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude) 頁面。

Google 會為 Claude Models on Google Cloud (Google managed) 所提供的模型設定生命週期日期。這些日期可能與 Claude API 的時程不同。如需模型目前的停用日期，請參閱 Google Cloud 的 [Anthropic Claude models on Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude) 頁面。如需了解「已棄用」和「已停用」的含義，請參閱[模型棄用](https://platform.claude.com/docs/zh-TW/about-claude/model-deprecations)。

<Note>
  Claude Mythos Preview 是研究預覽版。Claude Models on Google Cloud (Google managed) 向受邀客戶提供此模型。如需更多資訊，請參閱 [Project Glasswing](https://anthropic.com/glasswing)。
</Note>

<Tip>
  正在升級到較新的 Claude 模型嗎？Claude Code 中的 [Claude API 技能](https://platform.claude.com/docs/zh-TW/agents-and-tools/agent-skills/claude-api-skill#migrating-to-a-newer-claude-model)會在您的整個程式碼庫中套用模型 ID 替換與破壞性參數變更：

  讓 Claude Code 為您遷移程式碼

  ```text
  /claude-api migrate 將此專案遷移至最新的 Claude Opus 模型
  ```

  此技能會偵測您的程式碼所針對的雲端平台，並針對該平台調整模型 ID 格式與功能變更。
</Tip>

## 全域、多區域和區域端點

Claude Models on Google Cloud (Google managed) 提供三種端點類型。您可以透過建立用戶端時傳遞的區域值來選擇其中一種。在 cURL 請求中，端點類型會決定主機以及 URL 中的 `locations` 區段。

| 端點類型       | 區域值                  | 主機                                                                         |
| ---------- | -------------------- | -------------------------------------------------------------------------- |
| **全域**（建議） | `"global"`           | `aiplatform.googleapis.com`                                                |
| **多區域**    | `"us"` 或 `"eu"`      | `aiplatform.us.rep.googleapis.com`<br />`aiplatform.eu.rep.googleapis.com` |
| **區域**     | 某個區域，例如 `"us-east5"` | `{region}-aiplatform.googleapis.com`                                       |

各端點類型的差異在於請求的傳送目的地：

* **全域：** 請求會傳送至任何有可用容量的區域。當您希望獲得最高可用性且資料落地要求較有彈性時，請使用此類型。
* **多區域：** 請求會傳送至美國（`"us"`）或歐盟（`"eu"`）內的任何區域。當您需要在較廣泛的地理範圍內實現資料落地，並需要比單一區域更高的可用性時，請使用此類型。
* **區域：** 請求只會傳送至您指定的區域，例如 `"us-east5"` 或 `"europe-west1"`。當您需要單一區域的資料落地或必須符合嚴格的合規要求時，請使用此類型。

多區域和區域端點的費用比全域端點高 10%。三種端點類型都接受隨用隨付流量，而佈建輸送量則需要區域端點。

區域端點僅提供 Claude Sonnet 4.6 及更早的模型。對於較新的模型，請使用全域或多區域端點。

<Note>
  多區域和區域端點的加價僅適用於 Claude Sonnet 4.5（已棄用）及更新的模型。如需保留先前定價的模型，請參閱[雲端平台定價](https://platform.claude.com/docs/zh-TW/about-claude/pricing#cloud-platform-pricing)。對於區域端點，加價反映了專用區域容量的基礎架構成本。
</Note>

以下範例使用 `us` 多區域端點。醒目標示的行用於設定區域。如需在全域端點上的完整請求，請參閱[發送請求](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#accessing-vertex-ai)。

<CodeGroup exclude="shell:CLI">
  ```bash 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
    }'
  ```

  <CodeGroupItem language="CLI">
    `ant` CLI 不支援 Claude Models on Google Cloud (Google managed)。
  </CodeGroupItem>

  ```python 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 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
  });
  ```

  ```csharp 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 Go
  import (
  	"context"

  	"github.com/anthropics/anthropic-sdk-go"
  	"github.com/anthropics/anthropic-sdk-go/vertex"
  )
  // ...
  	// 多區域識別碼："us" 或 "eu"
  	client := anthropic.NewClient(
  		vertex.WithGoogleAuth(context.Background(), "us", "MY_PROJECT_ID"),
  	)
  ```

  ```java 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 PHP
  use Anthropic\Vertex;

  $client = Vertex\Client::fromEnvironment(
      region: 'us', // Multi-region identifier: "us" or "eu"
      projectId: 'MY_PROJECT_ID',
  );
  ```

  ```ruby Ruby
  require "anthropic"

  client = Anthropic::VertexClient.new(
    region: "us", # Multi-region identifier: "us" or "eu"
    project_id: "MY_PROJECT_ID"
  )
  ```
</CodeGroup>

## 功能支援

Claude Models on Google Cloud (Google managed) 支援的功能包括：

* [Messages API](https://platform.claude.com/docs/zh-TW/api/messages/create)

* [提示快取](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-caching)

* [思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking)

* [工具使用](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/overview)，包括以下工具：

  * [Bash 工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/bash-tool)
  * [瀏覽器使用工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/browser-use-tool)
  * [電腦使用工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/computer-use-tool)
  * [記憶工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/memory-tool)
  * [文字編輯器工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/text-editor-tool)
  * [網頁搜尋工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/web-search-tool)

* [引用](https://platform.claude.com/docs/zh-TW/build-with-claude/citations)

* [結構化輸出](https://platform.claude.com/docs/zh-TW/build-with-claude/structured-outputs)

[功能概覽](https://platform.claude.com/docs/zh-TW/build-with-claude/overview)列出了所有功能，以及 Claude Models on Google Cloud (Google managed) 是否支援這些功能。

### 不支援的功能

Claude Models on Google Cloud (Google managed) 不支援以下功能：

* **輸入來源：** 圖片和文件的 URL 來源，以及 Files API
* **伺服器端工具：** 程式碼執行、網頁擷取和 advisor
* **代理基礎架構：** Agent Skills、MCP connector 和程式化工具呼叫
* **API 端點：** Message Batches API、Models API、Admin API、Compliance API，以及 Usage and Cost API
* **Claude Managed Agents**
* **伺服器端備援：** [`fallbacks` 參數](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#server-side-fallback)

請改用[用戶端備援模式](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#client-side-fallback)來取代伺服器端備援。

### 上下文視窗

Claude Models on Google Cloud (Google managed) 為以下模型提供 [1M token 的「context window」（上下文視窗）](https://platform.claude.com/docs/zh-TW/build-with-claude/context-windows)：

* 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 token，包括 Claude Sonnet 4.5（已棄用）和 Claude Sonnet 4（已棄用）。

Agent Platform 將請求酬載限制為 30 MB。當您傳送大型文件或大量圖片時，可能會在達到 token 限制之前先達到此限制。

## 計費、速率限制和日誌記錄

### 速率限制

Google Cloud 負責管理 Claude Models on Google Cloud (Google managed) 的「rate limit」（速率限制）和配額。如需詳細資訊，包括如何申請提高配額，請參閱 Google Cloud 的 [Quotas for Anthropic Claude models](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude/quotas) 頁面。

### 計費

Google Cloud 會針對 Claude Models on Google Cloud (Google managed) 向您開立帳單。如需價格資訊，請參閱 Google Cloud 的 [Generative AI pricing](https://cloud.google.com/vertex-ai/generative-ai/pricing#claude-models) 頁面。價格也取決於端點類型。請參閱[全域、多區域和區域端點](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#global-multi-region-and-regional-endpoints)。

### 資料保留

Google Cloud 負責管理 Claude Models on Google Cloud (Google managed) 的資料處理。如需詳細資訊，請參閱 [Agent Platform and zero data retention](https://cloud.google.com/vertex-ai/generative-ai/docs/data-governance)。

### 監控和日誌記錄

若要記錄 Claude Models on Google Cloud (Google managed) 的提示和完成內容，請使用 Agent Platform 的[請求-回應日誌記錄服務](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/request-response-logging)。

Anthropic 建議您至少保留最近 30 天的日誌。這些日誌可協助您了解您的活動並調查可能的濫用行為。

<Note>
  啟用此服務不會讓 Google 或 Anthropic 存取您的任何內容。
</Note>

## 從 Claude Models on Google Cloud (Anthropic managed) 遷移

如需了解遷移時會有哪些變更，請參閱[兩種 Google Cloud 方案的差異](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/overview#how-the-two-google-cloud-offerings-differ)。若要遷移至 Claude Models on Google Cloud (Google managed)，請依照以下步驟操作：

<Steps>
  <Step title="設定存取權">
    確認您的專案以及進行呼叫的身分符合[進行 API 呼叫之前](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#before-making-api-calls)中的要求。
  </Step>

  <Step title="安裝 SDK 套件">
    安裝提供 Claude Models on Google Cloud (Google managed) 用戶端的套件。請參閱[安裝 SDK](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#install-an-sdk-for-accessing-vertex-ai)。
  </Step>

  <Step title="替換匯入和用戶端">
    變更匯入和建立用戶端的程式碼。使用 `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) 用戶端：

    <CodeGroup>
      ```bash 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"}
          ]
        }'
      ```

      ```bash CLI
      ant messages create \
        --model claude-opus-5-5 \
        --max-tokens 1024 \
        --message '{role: user, content: "Hello, Claude"}'
      ```

      ```python Python
      from anthropic import AnthropicGoogleCloud

      client = AnthropicGoogleCloud()
      ```

      ```typescript TypeScript
      import { AnthropicGoogleCloud } from "@anthropic-ai/google-cloud-sdk";

      const client = new AnthropicGoogleCloud();
      ```

      ```csharp C#
      using Anthropic.GoogleCloud;

      var client = new AnthropicGoogleCloudClient();
      ```

      ```go Go
      import (
      	"context"

      	"github.com/anthropics/anthropic-sdk-go"
      	"github.com/anthropics/anthropic-sdk-go/googlecloud"
      )
      // ...
      	client, err := googlecloud.NewClient(context.Background(), googlecloud.ClientConfig{})
      	if err != nil {
      		panic(err)
      	}
      ```

      ```java 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 PHP
      use Anthropic\GoogleCloud\Client;

      $client = new Client();
      ```

      ```ruby Ruby
      require "anthropic"

      client = Anthropic::GoogleCloudClient.new
      ```
    </CodeGroup>

    以下程式碼會建立 Claude Models on Google Cloud (Google managed) 的用戶端，並使用全域端點。如需其他端點類型，請參閱[全域、多區域和區域端點](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#global-multi-region-and-regional-endpoints)。

    <CodeGroup exclude="shell:CLI">
      ```bash 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
        }'
      ```

      <CodeGroupItem language="CLI">
        `ant` CLI 不支援 Claude Models on Google Cloud (Google managed)。請改用 cURL 或 SDK。
      </CodeGroupItem>

      ```python Python
      from anthropic import AnthropicVertex

      project_id = "MY_PROJECT_ID"
      region = "global"

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

      ```typescript TypeScript
      import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";

      const projectId = "MY_PROJECT_ID";
      const region = "global";

      const client = new AnthropicVertex({
        projectId,
        region
      });
      ```

      ```csharp C#
      using Anthropic.Vertex;

      var projectId = "MY_PROJECT_ID";
      var region = "global";

      var client = new AnthropicVertexClient(new AnthropicVertexCredentials(region, projectId));
      ```

      ```go Go
      import (
      	"context"

      	"github.com/anthropics/anthropic-sdk-go"
      	"github.com/anthropics/anthropic-sdk-go/vertex"
      )
      // ...
      	// 使用預設的 Google Cloud 憑證
      	client := anthropic.NewClient(
      		vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
      	)
      ```

      ```java 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 PHP
      use Anthropic\Vertex;

      $client = Vertex\Client::fromEnvironment(
          region: 'global',
          projectId: 'MY_PROJECT_ID',
      );
      ```

      ```ruby Ruby
      require "anthropic"

      client = Anthropic::VertexClient.new(
        region: "global",
        project_id: "MY_PROJECT_ID"
      )
      ```
    </CodeGroup>

    此程式碼在建立用戶端時會傳遞您的專案 ID 和區域。請將 `MY_PROJECT_ID` 替換為您的專案 ID。您使用該用戶端進行的 Messages API 呼叫維持不變，例外情況是下一步中的模型 ID 和功能。
  </Step>

  <Step title="檢查模型 ID 和功能">
    * **模型 ID：** 如果您使用的是早於 Claude 4.6 的模型，請將其 ID 中快照日期前的連字號替換為 `@`。例如，`claude-haiku-4-5-20251001` 會變成 `claude-haiku-4-5@20251001`。如需模型及其 ID，請參閱 [API 模型 ID](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#api-model-ids)。
    * **功能：** 確認您的程式碼所使用的功能未列於[不支援的功能](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#features-not-supported)中。
  </Step>

  <Step title="執行測試請求">
    執行[發送請求](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#accessing-vertex-ai)中的請求，以確認您的設定可正常運作。然後執行您自己的程式碼。在移轉正式環境流量之前，請先閱讀 [Claude Models on Google Cloud (Google managed) 的速率限制](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed#rate-limits)。
  </Step>
</Steps>

## 後續步驟

<CardGroup cols={2}>
  <Card title="功能概覽" icon="stack" href="https://platform.claude.com/docs/zh-TW/build-with-claude/overview">
    探索 Claude 的功能。
  </Card>

  <Card title="Anthropic Claude models on Agent Platform" icon="book" href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude">
    查看各區域提供哪些 Claude 模型及其停用日期。
  </Card>

  <Card title="Agent Platform 文件" icon="book" href="https://cloud.google.com/vertex-ai/docs">
    閱讀 Google Cloud 的 Agent Platform 文件。
  </Card>

  <Card title="Claude 模型的全域端點" icon="link" href="https://cloud.google.com/blog/products/ai-machine-learning/global-endpoint-for-claude-models-generally-available-on-vertex-ai">
    閱讀 Google Cloud 關於 Claude 模型全域端點的部落格文章。
  </Card>
</CardGroup>
