---
title: 思考
url: https://platform.claude.com/docs/zh-TW/build-with-claude/thinking
description: 了解 Claude 的思考如何運作：開啟思考、讀取思考輸出、透過 effort 調整思考深度，以及搭配工具、快取與串流使用思考。
---

<Note>
  若要了解「zero data retention」（零資料保留），即 ZDR 如何適用於此功能，請參閱 [API 與資料保留](https://platform.claude.com/docs/zh-TW/manage-claude/api-and-data-retention)。
</Note>

只進行單次處理就作答的模型，必須第一次就把所有事情做對：沒有草稿、沒有檢查，也無法中途改變方向。對於證明、棘手的錯誤或冗長的代理任務而言，第一個想到的方法往往不是最好的。

「Thinking」（思考）消除了這項限制。思考啟用時，Claude 會在回答前先用自己的話逐步處理問題：重述問題、嘗試不同方法、檢查中間結果，並放棄站不住腳的路徑。這些預先思考會以 `thinking` 內容區塊的形式出現在回應之前，Claude 會依據這些思考產生最終答案。因此，思考能提升數學、程式設計、分析以及長時間執行的代理工作等複雜任務的表現。這類任務的答案品質取決於中間過程，若沒有思考，這些過程就會被壓縮進回應本身，或直接被略過。

思考是有成本的：Claude 用於推理的 token 會以輸出 token 計費，即使思考文字沒有傳回給您也一樣，而且這些 token 會與回應文字一起計入 `max_tokens`。本頁說明思考在整個 API 中的行為：如何開啟思考、讀取其輸出，以及管理思考與工具、串流、快取和上下文視窗之間的互動。

## 思考如何運作

<Frame>
  ![圖表：Claude 決定是否進行預先思考，可能在工具呼叫之間思考，並在文字之前回傳思考區塊](https://platform.claude.com/docs/zh-TW/images/how-thinking-works.svg)
</Frame>

Claude 是否會針對特定請求進行思考，以及思考的深度，取決於您的思考設定和請求的複雜度。

以下是預先思考在回應中的樣子：一個或多個 `thinking` 內容區塊會在 `text` 區塊之前出現。思考區塊仍然是生成的內容，就像其後的 `text` 區塊一樣，但它與正式回應是分開的。每個思考區塊也帶有一個 `signature` 欄位，這是完整推理的加密副本，您需要在多輪對話和工具使用對話中原封不動地傳回（請參閱[思考加密](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-encryption)）：

```json
{
  "content": [
    {
      "type": "thinking",
      "thinking": "Let me break this down. The question has two parts, so I'll start with the simpler one and use its result to constrain the second...",
      "signature": "WaUjzkypQ2mUEVM36O2Txu...."
    },
    {
      "type": "text",
      "text": "Based on my analysis..."
    }
  ]
}
```

您不一定會看到這段文字，而您看到的也絕不是原始的思維鏈：思考區塊中的文字是 [Claude 推理的摘要](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#summarized-thinking)。思考設定上的 `display` 欄位控制是否回傳該摘要：`"summarized"` 會回傳摘要，而 `"omitted"`（許多模型上的預設值）會回傳 `thinking` 欄位為空的思考區塊。無論哪種方式，區塊的計費方式相同，在多輪對話中傳回的方式也相同。請參閱[控制思考顯示](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#controlling-thinking-display)以了解各模型的預設值和詳細資訊。

如果 Claude 使用工具，思考也可能出現在工具呼叫之間。請參閱[搭配工具使用的思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)。如需完整的回應格式，請參閱 [Messages API 參考](https://platform.claude.com/docs/zh-TW/api/messages/create)。

## 設定思考

在大多數模型上，思考預設為開啟，或只需一個參數即可開啟。下表顯示每個模型對請求可傳送的每個 `thinking` 值的處理方式。400 錯誤表示 API 拒絕該請求，[思考疑難排解](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting)列出了每個錯誤及其修正方式。

| 模型                    | 無 `thinking` 欄位 | `"adaptive"` | `"enabled"` 搭配 `budget_tokens` | `"between_tools"`           | `"disabled"`              |
| --------------------- | --------------- | ------------ | ------------------------------ | --------------------------- | ------------------------- |
| Claude Opus 5.5       | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 400 錯誤                    |
| Claude Sonnet 5.5     | 自適應思考           | 自適應思考        | 400 錯誤                         | 在 `high` 或更低 effort 下關閉預先思考 | 400 錯誤                    |
| Claude Haiku 5.5      | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 在 `high` 或更低 effort 下關閉思考 |
| Claude Fable 5.1      | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 400 錯誤                    |
| Claude Mythos 5.1     | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 400 錯誤                    |
| Claude Fable 5        | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 400 錯誤                    |
| Claude Mythos 5       | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 400 錯誤                    |
| Claude Opus 5         | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 在 `high` 或更低 effort 下關閉思考 |
| Claude Sonnet 5       | 自適應思考           | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 思考關閉                      |
| Claude Opus 4.8       | 思考關閉            | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 思考關閉                      |
| Claude Opus 4.7       | 思考關閉            | 自適應思考        | 400 錯誤                         | 400 錯誤                      | 思考關閉                      |
| Claude Mythos Preview | 自適應思考           | 自適應思考        | 擴展思考                           | 400 錯誤                      | 400 錯誤                    |
| Claude Opus 4.6       | 思考關閉            | 自適應思考        | 擴展思考（已棄用）                      | 400 錯誤                      | 思考關閉                      |
| Claude Sonnet 4.6     | 思考關閉            | 自適應思考        | 擴展思考（已棄用）                      | 400 錯誤                      | 思考關閉                      |
| Claude Opus 4.5       | 思考關閉            | 400 錯誤       | 擴展思考                           | 400 錯誤                      | 思考關閉                      |
| Claude Sonnet 4.5     | 思考關閉            | 400 錯誤       | 擴展思考                           | 400 錯誤                      | 思考關閉                      |
| Claude Haiku 4.5      | 思考關閉            | 400 錯誤       | 擴展思考                           | 400 錯誤                      | 思考關閉                      |

在表格中，「在 `high` 或更低 effort 下」表示該請求在 `low`、`medium` 和 `high` effort 下可正常運作，而在 `xhigh` 或 `max` 下會回傳 400 錯誤。

在 Claude Opus 5.5、Claude Opus 5、Claude Sonnet 5.5、Claude Sonnet 5、Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5、Claude Mythos Preview 和 Claude Haiku 5.5 上，思考已經開啟，無需任何設定。這些模型上的 `display` 預設為 `"omitted"`，因此在您選擇啟用之前，思考文字會被隱藏。請使用 `thinking: {"type": "adaptive", "display": "summarized"}` 來啟用，如以下範例所示。

在 Claude Opus 4.8、Claude Opus 4.7、Claude Opus 4.6 和 Claude Sonnet 4.6 上，思考預設為關閉，直到您設定 `thinking: {type: "adaptive"}`，這會讓 Claude 根據請求決定何時思考以及思考的深度。同樣的請求，只要替換[模型字串](https://platform.claude.com/docs/zh-TW/models/overview)，就能在這些模型上開啟思考。以下範例設定了 `display: "summarized"` 以顯示思考文字，並使用寬裕的 `max_tokens`：

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 16000,
      "thinking": {
        "type": "adaptive",
        "display": "summarized"
      },
      "messages": [
        {
          "role": "user",
          "content": "What is the greatest common divisor of 1071 and 462?"
        }
      ]
    }'
  ```

  ```bash CLI
  ant messages create \
    --model claude-opus-5-5 \
    --max-tokens 16000 \
    --thinking '{type: adaptive, display: summarized}' \
    --message '{role: user, content: "What is the greatest common divisor of 1071 and 462?"}' \
    --transform content \
    --format yaml
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=16000,
      thinking={"type": "adaptive", "display": "summarized"},
      messages=[
          {
              "role": "user",
              "content": "What is the greatest common divisor of 1071 and 462?",
          }
      ],
  )

  for block in response.content:
      match block.type:
          case "thinking":
              print(f"\nThinking: {block.thinking}")
          case "text":
              print(f"\nResponse: {block.text}")
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 16000,
    thinking: {
      type: "adaptive",
      display: "summarized"
    },
    messages: [
      {
        role: "user",
        content: "What is the greatest common divisor of 1071 and 462?"
      }
    ]
  });

  for (const block of response.content) {
    switch (block.type) {
      case "thinking":
        console.log(`\nThinking: ${block.thinking}`);
        break;
      case "text":
        console.log(`\nResponse: ${block.text}`);
        break;
    }
  }
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 16000,
      Thinking = new ThinkingConfigAdaptive { Display = Display.Summarized },
      Messages = [
          new() {
              Role = Role.User,
              Content = "What is the greatest common divisor of 1071 and 462?"
          }
      ]
  };

  var message = await client.Messages.Create(parameters);

  foreach (var block in message.Content)
  {
      if (block.TryPickThinking(out ThinkingBlock? thinking))
      {
          Console.WriteLine($"\nThinking: {thinking.Thinking}");
      }
      else if (block.TryPickText(out TextBlock? text))
      {
          Console.WriteLine($"\nResponse: {text.Text}");
      }
  }
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 16000,
  	Thinking: anthropic.ThinkingConfigParamUnion{
  		OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{
  			Display: anthropic.ThinkingConfigAdaptiveDisplaySummarized,
  		},
  	},
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("What is the greatest common divisor of 1071 and 462?")),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }

  for _, block := range response.Content {
  	switch v := block.AsAny().(type) {
  	case anthropic.ThinkingBlock:
  		fmt.Printf("\nThinking: %s", v.Thinking)
  	case anthropic.TextBlock:
  		fmt.Printf("\nResponse: %s", v.Text)
  	}
  }
  ```

  ```java Java
  import com.anthropic.models.messages.ThinkingConfigAdaptive;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(16000L)
          .thinking(ThinkingConfigAdaptive.builder()
              .display(ThinkingConfigAdaptive.Display.SUMMARIZED)
              .build())
          .addUserMessage("What is the greatest common divisor of 1071 and 462?")
          .build();

      Message response = client.messages().create(params);

      response.content().forEach(block -> {
          block.thinking().ifPresent(thinkingBlock ->
              IO.println("\nThinking: " + thinkingBlock.thinking())
          );
          block.text().ifPresent(textBlock ->
              IO.println("\nResponse: " + textBlock.text())
          );
      });
  }
  ```

  ```php PHP
  use Anthropic\Messages\TextBlock;
  use Anthropic\Messages\ThinkingBlock;

  $client = new Client();

  $message = $client->messages->create(
      maxTokens: 16000,
      messages: [
          [
              'role' => 'user',
              'content' => 'What is the greatest common divisor of 1071 and 462?'
          ]
      ],
      model: 'claude-opus-5-5',
      thinking: ['type' => 'adaptive', 'display' => 'summarized'],
  );

  foreach ($message->content as $block) {
      switch (true) {
          case $block instanceof ThinkingBlock:
              echo "\nThinking: " . $block->thinking;
              break;
          case $block instanceof TextBlock:
              echo "\nResponse: " . $block->text;
              break;
      }
  }
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: "claude-opus-5-5",
    max_tokens: 16000,
    thinking: {
      type: "adaptive",
      # 像這樣的一般 hash 使用 display:。具型別的 ThinkingConfigAdaptive 類別
      # 則寫成 display_（結尾加底線），以避免遮蔽 Ruby 的 Kernel#display。
      # 請求中送出的仍是 display。
      display: "summarized"
    },
    messages: [
      {
        role: "user",
        content: "What is the greatest common divisor of 1071 and 462?"
      }
    ]
  )

  message.content.each do |block|
    case block
    when Anthropic::Models::ThinkingBlock
      puts "\nThinking: #{block.thinking}"
    when Anthropic::Models::TextBlock
      puts "\nResponse: #{block.text}"
    end
  end
  ```
</CodeGroup>

執行範例會先印出摘要後的思考，然後是答案：

```text Output wrap
Thinking: Use Euclidean algorithm.
1071 = 2*462 + 147
462 = 3*147 + 21
147 = 7*21 + 0
GCD = 21

Response: ## Finding GCD of 1071 and 462

I'll use the **Euclidean algorithm**, repeatedly dividing and taking remainders...
```

思考 token 會計入 `max_tokens`，因此請將其設定得足夠高，為思考和回應文字都保留空間。請參閱引導頁面上的[成本控制](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#cost-control)以及[思考與上下文視窗](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-and-the-context-window)。

### 關閉思考

在思考預設為開啟的 Claude Sonnet 5 上，您可以將其關閉：

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-sonnet-5",
      "max_tokens": 4096,
      "thinking": {"type": "disabled"},
      "messages": [
        {
          "role": "user",
          "content": "Summarize this article in one sentence."
        }
      ]
    }'
  ```

  ```bash CLI
  ant messages create \
    --model claude-sonnet-5 \
    --max-tokens 4096 \
    --thinking '{type: disabled}' \
    --message '{role: user, content: "Summarize this article in one sentence."}'
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-sonnet-5",
      max_tokens=4096,
      thinking={"type": "disabled"},
      messages=[{"role": "user", "content": "Summarize this article in one sentence."}],
  )
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-sonnet-5",
    max_tokens: 4096,
    thinking: { type: "disabled" },
    messages: [{ role: "user", content: "Summarize this article in one sentence." }]
  });
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeSonnet5,
      MaxTokens = 4096,
      Thinking = new ThinkingConfigDisabled(),
      Messages = [
          new() {
              Role = Role.User,
              Content = "Summarize this article in one sentence."
          }
      ]
  };

  var message = await client.Messages.Create(parameters);
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeSonnet5,
  	MaxTokens: 4096,
  	Thinking: anthropic.ThinkingConfigParamUnion{
  		OfDisabled: &anthropic.ThinkingConfigDisabledParam{},
  	},
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Summarize this article in one sentence.")),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  ```

  ```java Java
  import com.anthropic.models.messages.ThinkingConfigDisabled;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_SONNET_5)
          .maxTokens(4096L)
          .thinking(ThinkingConfigDisabled.builder().build())
          .addUserMessage("Summarize this article in one sentence.")
          .build();

      Message response = client.messages().create(params);
  }
  ```

  ```php PHP
  $client = new Client();

  $message = $client->messages->create(
      maxTokens: 4096,
      messages: [
          [
              'role' => 'user',
              'content' => 'Summarize this article in one sentence.'
          ]
      ],
      model: 'claude-sonnet-5',
      thinking: ['type' => 'disabled'],
  );
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: "claude-sonnet-5",
    max_tokens: 4096,
    thinking: { type: "disabled" },
    messages: [
      {
        role: "user",
        content: "Summarize this article in one sentence."
      }
    ]
  )
  ```
</CodeGroup>

Claude Opus 5 的思考也預設為開啟，並在 [effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時接受 `thinking: {type: "disabled"}`。在 `xhigh` 或 `max` effort 下，思考無法關閉：將 `thinking: {type: "disabled"}` 與這些 effort 等級組合的請求會回傳 400 錯誤。此限制會在每個請求上強制執行。在思考停用的情況下，Claude Opus 5 偶爾可能會以純文字形式發出工具呼叫，或在其可見輸出中包含內部 XML 標籤。請參閱[在停用思考的情況下執行](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-opus-5#running-with-thinking-disabled)以了解提示方面的緩解措施。

Claude Sonnet 5.5 的思考也預設為開啟，且它會以 400 錯誤拒絕 `thinking: {type: "disabled"}`。若要關閉預先思考，請改為傳送 `thinking: {type: "between_tools"}`。這是 Claude Sonnet 5.5 上最低的思考設定，並在 [effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時被接受。模型仍會回傳其[工具呼叫之間的進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)。在沒有工具的情況下，回應只包含文字，就像在 Claude Sonnet 5 上使用 `disabled` 一樣。請參閱[在沒有預先思考的情況下執行](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#running-without-up-front-thinking)以取得提示指引。

Claude Haiku 5.5 的思考也預設為開啟，並在 [effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或以下時接受 `thinking: {type: "disabled"}`。在 `xhigh` 或 `max` effort 下，該組合會回傳 400 錯誤。若要減少思考，請先降低 effort 等級。在思考關閉的情況下，當您同時要求 JSON 輸出時，模型可能會略過它需要的工具呼叫。在思考關閉期間，與目前生效等級不同的[每則訊息 `output_config.effort`](https://platform.claude.com/docs/zh-TW/build-with-claude/effort#change-effort-mid-conversation-beta) 也會回傳 400 錯誤。請參閱[使用 effort 控制思考](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#use-effort-to-control-thinking)以及[搭配 JSON 輸出與您自己的工具使用自適應思考](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#json-output-with-your-own-tools)。

Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5、Claude Opus 5.5 和 Claude Mythos Preview 會拒絕 `thinking: {type: "disabled"}`。在這些模型上無法關閉思考。

若要在傳送請求之前檢查模型是否接受 `"disabled"`，請從 Models API 讀取其 `capabilities.thinking.types.disabled.supported` 值。[使用 Models API](https://platform.claude.com/docs/zh-TW/models/overview#using-the-models-api) 說明了該欄位。

如果您的模型僅支援擴展思考（請參閱[各模型設定表](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting#supported-models)），請改用 `type: "enabled"` 和 `budget_tokens` 值進行設定。[擴展思考](https://platform.claude.com/docs/zh-TW/build-with-claude/extended-thinking)頁面涵蓋了該設定。如果任何思考設定回傳 400 錯誤，[思考疑難排解](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting)會將每則錯誤訊息對應到其修正方式。

## 讀取思考輸出

### 控制思考顯示

思考設定上的 `display` 欄位控制思考內容在 API 回應中的回傳方式。`display` 在兩種模式下都適用：將其與 `type: "adaptive"` 或 `type: "enabled"` 一起設定。它接受以下值：

* `"summarized"`：思考區塊包含[摘要思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#summarized-thinking)文字，即 Claude 推理的可讀摘要。這是 Claude Opus 4.6、Claude Sonnet 4.6 及更早模型上的預設值。
* `"omitted"`：思考區塊會以空的 `thinking` 欄位回傳。`signature` 欄位仍帶有加密的完整思考，以維持多輪對話的連續性（請參閱[思考加密](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-encryption)）。這是 Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5、Claude Opus 5.5、Claude Opus 5、Claude Sonnet 5.5、Claude Sonnet 5、Claude Opus 4.8、Claude Opus 4.7、[Claude Mythos Preview](https://anthropic.com/glasswing) 和 Claude Haiku 5.5 上的預設值。
* `"updates"`（beta）：推理區塊會以空的 `thinking` 欄位回傳，與 `"omitted"` 相同，而某些模型在工具呼叫之間撰寫的簡短[進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)會以可讀文字回傳。需要 beta 標頭 `thinking-display-updates-2026-08-18`。

當您的應用程式不向使用者呈現思考內容時，請設定 `display: "omitted"`。主要好處是串流時能更快取得第一個文字 token：伺服器會完全略過串流思考 token，只傳送簽章，因此最終的文字回應能更早開始串流。

使用 `display: "omitted"` 時，回應會包含 `thinking` 欄位為空的 `thinking` 區塊：

```json Output
{
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "EosnCkYICxIMMb3LzNrMu..."
    },
    {
      "type": "text",
      "text": "The answer is 12,231."
    }
  ]
}
```

使用省略的思考時，請注意以下事項：

* 您仍需為完整的思考 token 付費。省略可降低延遲，而非成本。
* 如果您在多輪對話中傳回思考區塊，請原封不動地傳回。伺服器會解密 `signature` 以重建原始思考，用於建構提示（請參閱[保留思考區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserving-thinking-blocks)）。您在往返傳遞的省略區塊的 `thinking` 欄位中放入的任何文字都會被忽略。
* `display` 在 `thinking.type: "disabled"` 時無效（沒有可顯示的內容），在 `thinking.type: "between_tools"`（僅限 Claude Sonnet 5.5）時也無效，因為後者不接受其他欄位。使用 `between_tools` 時，進度更新仍會帶有摘要文字回傳，就像在 `display: "updates"` 下一樣（請參閱[進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)）。
* 使用 `thinking.type: "adaptive"` 且模型針對簡單請求略過思考時，無論 `display` 為何，都不會產生思考區塊。
* 使用 `display: "omitted"` 進行串流時，不會串流任何思考文字。每個思考區塊會串流一個 `thinking` 字串為空的 `thinking_delta`，然後是其 `signature_delta`。使用 `display: "updates"` 時，只有[進度更新區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)會串流帶有文字的 `thinking_delta` 事件。請參閱[串流思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)以了解事件順序。

<Note>
  無論您設定哪個 `display` 值，`signature` 欄位都是相同的。支援在對話的各輪之間切換 `display` 值。
</Note>

### 摘要思考

當 `display` 為 `"summarized"` 時，您收到的思考文字是 Claude 完整思考過程的摘要，而非原始的思維鏈。「Summarized thinking」（摘要思考）在提供思考的完整智慧優勢的同時，也能防止濫用。沒有任何 `display` 設定會回傳原始的思維鏈。

使用摘要思考時，請注意以下事項：

* 您需要為原始請求所產生的完整思考 token 付費，而非摘要 token。計費的輸出 token 數量與您在回應中看到的 token 數量並不相符。
* 在 Claude Opus 4.6、Claude Sonnet 4.6 及更早的模型上，思考輸出的前幾行會較為詳細，提供對提示工程特別有幫助的詳細推理。[Claude Mythos Preview](https://anthropic.com/glasswing) 從第一個 token 就開始摘要，因此其思考區塊不會顯示這段詳細的開頭。
* 摘要會以最少的額外延遲保留 Claude 思考過程的關鍵概念，因此摘要可以在產生時即時串流。
* 摘要是由與您在請求中指定的模型不同的模型處理的。思考模型看不到摘要後的輸出。
* 隨著 Anthropic 持續改進思考功能，摘要行為可能會有所變更。

<Note>
  在您需要存取完整思考輸出的少數情況下，請[聯絡 Anthropic 銷售團隊](mailto:sales@anthropic.com)。
</Note>

若要查看模型的推理，請讀取 `thinking` 區塊，而不是在回應文字中提示模型提供推理。在 Claude Fable 5.1、Claude Opus 5.5、Claude Opus 5、Claude Sonnet 5.5 和 Claude Fable 5 上，試圖在回應文字中引出模型內部推理的請求可能會被拒絕，並帶有 `stop_details.category: "reasoning_extraction"`。請參閱[拒絕類別](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#refusal-response)以取得欄位參考，並參閱[將推理保留在思考區塊中](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks)以了解應改為要求什麼。

### 串流思考

思考可與[串流](https://platform.claude.com/docs/zh-TW/build-with-claude/streaming)搭配使用。思考區塊會以 `content_block_delta` 事件中的 `thinking_delta` 事件進行串流，並在區塊的 `content_block_stop` 之前緊接著一個 `signature_delta` 事件。文字區塊隨後照常串流。

<Frame>
  ![帶有思考的串流事件順序圖：思考區塊開啟，只有當 display 設定會回傳文字時（summarized，或針對進度更新區塊的 updates），thinking delta 才會帶有文字，單一 signature delta 關閉區塊，然後串流 text delta](https://platform.claude.com/docs/zh-TW/images/how-thinking-streams.svg)
</Frame>

以下範例使用自適應思考串流回應，並在思考和文字 delta 到達時將其印出：

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 16000,
      "stream": true,
      "thinking": {
        "type": "adaptive",
        "display": "summarized"
      },
      "messages": [
        {
          "role": "user",
          "content": "What is the greatest common divisor of 1071 and 462?"
        }
      ]
    }'
  ```

  ```bash CLI
  ant messages create \
    --model claude-opus-5-5 \
    --max-tokens 16000 \
    --thinking '{type: adaptive, display: summarized}' \
    --message '{role: user, content: "What is the greatest common divisor of 1071 and 462?"}' \
    --stream \
    --format jsonl
  ```

  ```python Python
  client = anthropic.Anthropic()

  with client.messages.stream(
      model="claude-opus-5-5",
      max_tokens=16000,
      thinking={"type": "adaptive", "display": "summarized"},
      messages=[
          {
              "role": "user",
              "content": "What is the greatest common divisor of 1071 and 462?",
          }
      ],
  ) as stream:
      for event in stream:
          match event.type:
              case "content_block_start":
                  print(f"\nStarting {event.content_block.type} block...")
              case "content_block_delta":
                  delta = event.delta
                  match delta.type:
                      case "thinking_delta":
                          print(delta.thinking, end="", flush=True)
                      case "text_delta":
                          print(delta.text, end="", flush=True)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const stream = client.messages.stream({
    model: "claude-opus-5-5",
    max_tokens: 16000,
    thinking: { type: "adaptive", display: "summarized" },
    messages: [{ role: "user", content: "What is the greatest common divisor of 1071 and 462?" }]
  });

  for await (const event of stream) {
    switch (event.type) {
      case "content_block_start":
        console.log(`\nStarting ${event.content_block.type} block...`);
        break;
      case "content_block_delta":
        switch (event.delta.type) {
          case "thinking_delta":
            process.stdout.write(event.delta.thinking);
            break;
          case "text_delta":
            process.stdout.write(event.delta.text);
            break;
        }
        break;
    }
  }
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 16000,
      Thinking = new ThinkingConfigAdaptive { Display = Display.Summarized },
      Messages = [new() { Role = Role.User, Content = "What is the greatest common divisor of 1071 and 462?" }]
  };

  await foreach (var rawEvent in client.Messages.CreateStreaming(parameters))
  {
      if (rawEvent.TryPickContentBlockStart(out var start))
      {
          Console.WriteLine($"\nStarting {start.ContentBlock.Type} block...");
      }
      else if (rawEvent.TryPickContentBlockDelta(out var delta))
      {
          if (delta.Delta.TryPickThinking(out var thinkingDelta))
          {
              Console.Write(thinkingDelta.Thinking);
          }
          else if (delta.Delta.TryPickText(out var textDelta))
          {
              Console.Write(textDelta.Text);
          }
      }
  }
  ```

  ```go Go
  client := anthropic.NewClient()

  stream := client.Messages.NewStreaming(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 16000,
  	Thinking: anthropic.ThinkingConfigParamUnion{
  		OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{
  			Display: anthropic.ThinkingConfigAdaptiveDisplaySummarized,
  		},
  	},
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("What is the greatest common divisor of 1071 and 462?")),
  	},
  })

  for stream.Next() {
  	event := stream.Current()
  	switch eventVariant := event.AsAny().(type) {
  	case anthropic.ContentBlockStartEvent:
  		fmt.Printf("\nStarting %s block...\n", eventVariant.ContentBlock.Type)
  	case anthropic.ContentBlockDeltaEvent:
  		switch deltaVariant := eventVariant.Delta.AsAny().(type) {
  		case anthropic.ThinkingDelta:
  			fmt.Print(deltaVariant.Thinking)
  		case anthropic.TextDelta:
  			fmt.Print(deltaVariant.Text)
  		}
  	}
  }
  if err := stream.Err(); err != nil {
  	log.Fatal(err)
  }
  ```

  ```java Java
  import com.anthropic.models.messages.ThinkingConfigAdaptive;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(16000L)
          .thinking(ThinkingConfigAdaptive.builder()
              .display(ThinkingConfigAdaptive.Display.SUMMARIZED)
              .build())
          .addUserMessage("What is the greatest common divisor of 1071 and 462?")
          .build();

      try (var streamResponse = client.messages().createStreaming(params)) {
          streamResponse.stream().forEach(event -> {
              switch (event.type().value()) {
                  case CONTENT_BLOCK_START -> {
                      var startEvent = event.asContentBlockStart();
                      var block = startEvent.contentBlock();
                      switch (block.type().value()) {
                          case THINKING -> IO.println("\nStarting thinking block...");
                          case TEXT -> IO.println("\nStarting text block...");
                      }
                  }
                  case CONTENT_BLOCK_DELTA -> {
                      var deltaEvent = event.asContentBlockDelta();
                      deltaEvent.delta().thinking().ifPresent(td ->
                          IO.print(td.thinking())
                      );
                      deltaEvent.delta().text().ifPresent(td ->
                          IO.print(td.text())
                      );
                  }
              }
          });
      }
  }
  ```

  ```php PHP
  use Anthropic\Messages\RawContentBlockDeltaEvent;
  use Anthropic\Messages\RawContentBlockStartEvent;
  use Anthropic\Messages\TextDelta;
  use Anthropic\Messages\ThinkingDelta;

  $client = new Client();

  $stream = $client->messages->createStream(
      maxTokens: 16000,
      messages: [
          ['role' => 'user', 'content' => 'What is the greatest common divisor of 1071 and 462?']
      ],
      model: 'claude-opus-5-5',
      thinking: ['type' => 'adaptive', 'display' => 'summarized'],
  );

  foreach ($stream as $event) {
      switch (true) {
          case $event instanceof RawContentBlockStartEvent:
              echo "\nStarting {$event->contentBlock->type} block...\n";
              break;
          case $event instanceof RawContentBlockDeltaEvent:
              switch (true) {
                  case $event->delta instanceof ThinkingDelta:
                      echo $event->delta->thinking;
                      break;
                  case $event->delta instanceof TextDelta:
                      echo $event->delta->text;
                      break;
              }
              break;
      }
  }
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  stream = client.messages.stream(
    model: "claude-opus-5-5",
    max_tokens: 16000,
    # 像這樣的一般 hash 使用 display:。具型別的 ThinkingConfigAdaptive 類別
    # 則寫作 display_（結尾加底線），以避免遮蔽 Ruby 的 Kernel#display。
    # 請求中送出的仍是 display。
    thinking: { type: "adaptive", display: "summarized" },
    messages: [
      { role: "user", content: "What is the greatest common divisor of 1071 and 462?" }
    ]
  )

  stream.each do |event|
    case event
    when Anthropic::Streaming::ThinkingEvent
      print event.thinking
    when Anthropic::Streaming::TextEvent
      print event.text
    end
  end
  ```
</CodeGroup>

若要在串流後重新組合完整的思考區塊及其簽章，請使用您 SDK 的訊息累積輔助工具 `stream.get_final_message()` (typescript: `stream.finalMessage()`; ruby: `stream.accumulated_message`; csharp: `.Aggregate()`; go: `message.Accumulate(event)`; java, php: `MessageAccumulator`)，而不是自行串接 delta。

<Accordion title="完整串流事件追蹤">
  ```sse Output
  event: message_start
  data: {"type": "message_start", "message": {"id": "msg_01...", "type": "message", "role": "assistant", "content": [], "model": "claude-opus-5-5", "stop_reason": null, "stop_sequence": null}}

  event: content_block_start
  data: {"type": "content_block_start", "index": 0, "content_block": {"type": "thinking", "thinking": "", "signature": ""}}

  event: content_block_delta
  data: {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "I need to find the GCD of 1071 and 462 using the Euclidean algorithm.\n\n1071 = 2 × 462 + 147"}}

  event: content_block_delta
  data: {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "\n462 = 3 × 147 + 21\n147 = 7 × 21 + 0\n\nSo GCD(1071, 462) = 21"}}

  // Additional thinking deltas...

  event: content_block_delta
  data: {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "EqQBCgIYAhIM1gbcDa9GJwZA2b..."}}

  event: content_block_stop
  data: {"type": "content_block_stop", "index": 0}

  event: content_block_start
  data: {"type": "content_block_start", "index": 1, "content_block": {"type": "text", "text": ""}}

  event: content_block_delta
  data: {"type": "content_block_delta", "index": 1, "delta": {"type": "text_delta", "text": "The greatest common divisor of 1071 and 462 is **21**."}}

  // Additional text deltas...

  event: content_block_stop
  data: {"type": "content_block_stop", "index": 1}

  event: message_delta
  data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}}

  event: message_stop
  data: {"type": "message_stop"}
  ```
</Accordion>

設定 `display: "omitted"` 時，思考區塊開啟，一個 `thinking` 字串為空的 `thinking_delta` 到達，接著是單一 `signature_delta`，然後區塊關閉。文字串流隨即開始：

```sse Output
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"","signature":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"signature_delta","signature":"EosnCkYICxIMMb3LzNrMu..."}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: content_block_start
data: {"type":"content_block_start","index":1,"content_block":{"type":"text","text":""}}
```

使用 `display: "updates"`（beta）時，推理區塊的串流方式與 `"omitted"` 相同。每個[進度更新區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)會在其所引介的 `tool_use` 區塊之前，以 `thinking_delta` 事件串流其文字。在進度更新區塊開啟之前暫停數秒是正常的：

```sse Output
event: content_block_start
data: {"type":"content_block_start","index":1,"content_block":{"type":"thinking","thinking":"","signature":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":1,"delta":{"type":"thinking_delta","thinking":"Confirmed the retry path never refreshes the expired token. Editing auth.py to add the refresh call."}}

event: content_block_delta
data: {"type":"content_block_delta","index":1,"delta":{"type":"signature_delta","signature":"Es8CCkYICxIM..."}}

event: content_block_stop
data: {"type":"content_block_stop","index":1}

event: content_block_start
data: {"type":"content_block_start","index":2,"content_block":{"type":"tool_use","id":"toolu_01D7FLrfh4GYq7yT1ULFeyMV","name":"edit_file","input":{}}}
```

在 `"updates"` 下，只要區塊的某個 `thinking_delta` 事件帶有非空文字，就將該區塊視為進度更新。

<Note>
  在啟用思考的情況下使用串流時，您可能會注意到文字有時會以較大的區塊到達，並與較小的逐 token 傳送交替出現。這是預期的行為，尤其是對於思考內容。

  串流系統會分批處理內容，這可能會延遲串流事件並將其分組，形成這種「區塊式」的傳送模式。
</Note>

如需一般串流機制，請參閱[串流訊息](https://platform.claude.com/docs/zh-TW/build-with-claude/streaming)。

## 思考與 effort

`thinking` 參數控制 Claude 是否在回答之前於[思考區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking)中進行思考；`effort` 參數則控制 Claude 在整個回應中投入多少工作量，在自適應模式下，這包括它思考的頻率與深度。請勿將 `adaptive` 作為 `effort` 的值傳入：`adaptive` 是一種思考模式，而非努力程度等級。

若要了解每個 effort 等級對思考行為的影響，請參閱[引導思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost)頁面上的[各等級思考行為表](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#effort-levels)。[Effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 頁面說明了該參數本身，包括每個模型支援哪些等級。在 Claude Opus 4.5（唯一支援 effort 的僅擴展思考模型）上，effort 會與 `budget_tokens` 組合運作。請參閱[預算規則與調整](https://platform.claude.com/docs/zh-TW/build-with-claude/extended-thinking#budget-rules-and-tuning)。

由於這兩種控制方式如此區分，請選擇符合您目標的那一種：

* **降低啟用思考之工作負載的成本或延遲：** 先降低 `effort`。它會縮減整個回應，包括思考。
* **Claude 思考得太少或太淺：** 提高 `effort`，或參閱引導頁面上的[引導 Claude 思考的頻率](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#tuning-thinking-behavior)。
* **您需要完全關閉思考：** 在允許的模型上使用 `thinking: {type: "disabled"}`（請參閱[各模型設定表](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting#supported-models)）。Claude Sonnet 5.5 會拒絕 `"disabled"`。其最低設定為 `thinking: {type: "between_tools"}`，可關閉預先思考。
* **您需要嚴格的支出上限：** 使用 `max_tokens`。Effort 是軟性指引，`max_tokens` 則是嚴格的限制。

## 搭配工具使用的思考

思考可與[工具使用](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/overview)搭配運作，讓 Claude 能推理工具的選擇並處理工具結果。適用兩項限制：

1. **工具選擇限制（手動模式）：**&#x642D;配手動擴展思考（`thinking: {type: "enabled"}`）的工具使用僅支援 `tool_choice: {"type": "auto"}`（預設值）或 `tool_choice: {"type": "none"}`。使用 `tool_choice: {"type": "any"}` 或 `tool_choice: {"type": "tool", "name": "..."}` 會導致錯誤，因為這些選項會強制使用工具，而這與手動擴展思考不相容。自適應思考（包括在思考預設開啟的模型上）支援強制工具使用，但 Claude Opus 5.5、Claude Sonnet 5.5、Claude Fable 5.1 和 Claude Mythos 5.1 除外（請參閱[回應預填與強制工具使用](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#limits-and-feature-compatibility)）。在接受強制工具使用的情況下，回應會以工具呼叫開始，且沒有 `thinking` 區塊。
2. **保留思考區塊：** 當您回傳工具結果時，必須將助理訊息中的思考區塊完整且未經修改地傳回 API。請參閱[保留思考區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserving-thinking-blocks)。

**工具使用迴圈是一個助理輪次。** 從模型的角度來看，助理輪次要等到 Claude 完成其完整回應後才算結束，而完整回應可能包含多次工具呼叫和結果。以下整個序列是單一助理輪次：

```text wrap
User: "What's the weather in Paris?"
Assistant: [thinking] + [tool_use: get_weather]
User: [tool_result: "20°C, sunny"]
Assistant: [text: "The weather in Paris is 20°C and sunny"]
```

整個輪次以單一思考模式執行：您無法在輪次中途切換思考，包括在工具使用迴圈期間。在擴展（手動）模式下，API 還會強制要求啟用思考之請求的最後一個助理輪次必須以思考區塊開頭。自適應模式放寬了這項要求：任何助理輪次都不需要以思考區塊開頭。

**輪次中途的衝突會平穩降級。** 如果您在輪次中途切換思考（例如，在傳送工具呼叫和回傳其結果之間），API 不會報錯，而是會靜默地為該請求停用思考。為了維持模型品質，API 可能會移除會造成無效輪次結構的思考區塊，或在對話歷史與啟用思考不相容時停用思考。若要確認思考是否處於啟用狀態，請檢查回應中是否存在 `thinking` 區塊。

**在輪次之間切換，而非在輪次之內。** 在每個輪次開始時規劃您的思考策略。完成助理輪次後，再為下一個輪次變更思考設定：

```text wrap
User: "What's the weather?"
Assistant: [tool_use] (thinking disabled)
User: [tool_result]
Assistant: [text: "It's sunny"]
User: "What about tomorrow?"
Assistant: [thinking] + [text: "..."] (thinking enabled - new turn)
```

切換思考模式也會使提示快取失效。請參閱[思考與提示快取](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-and-prompt-caching)。

### 保留思考區塊

當 Claude 呼叫工具時，它會暫停建構回應，以等待外部資訊。當您傳回工具結果時，Claude 會繼續建構同一個回應，因此其先前的推理必須仍然存在。請將每個 `thinking` 區塊連同其所伴隨的 `tool_use` 區塊，完整且未經修改地傳回 API。這點之所以重要，有兩個原因：

1. **推理連續性：** 思考區塊記錄了導致工具請求的逐步推理。包含這些區塊能讓 Claude 從中斷處繼續推理。
2. **上下文維護：** 在 API 結構中，工具結果會以使用者訊息的形式出現，但它們屬於同一個連續的推理流程。保留思考區塊能在多次 API 呼叫之間維持該流程。

簡而言之：

* **必要：** 在工具使用輪次內，傳回思考區塊。
* **建議：** 跨輪次時，傳回所有內容。
* **允許：** 在工具使用之外，省略先前輪次的思考。

您不需要自行修剪舊的思考內容。在多輪對話中傳回所有思考區塊，API 會自動篩選，保留維持模型推理所需的區塊，並且只針對實際呈現給 Claude 的區塊收取輸入 token 費用。保留哪些先前輪次的區塊因模型而異。請參閱[各模型的思考區塊保留方式](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)。若要覆寫預設行為，請使用 [`clear_thinking_20251015` 上下文編輯策略](https://platform.claude.com/docs/zh-TW/build-with-claude/context-editing#thinking-block-clearing)。

在最新的助理訊息中，連續 `thinking` 區塊的順序必須與模型在原始請求中產生的順序一致：您不能重新排列、編輯或部分捨棄這些區塊。這也包括 [`redacted_thinking` 區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#redacted-thinking-blocks)。

<Note>
  經過修改的思考區塊會以 400 錯誤被拒絕。確切的錯誤訊息、常見原因與修正方式，請參閱[400 錯誤指出思考區塊無法修改](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting#error-thinking-blocks-modified)。唯一的例外是：放入[省略](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#controlling-thinking-display)區塊之空白 `thinking` 欄位中的文字會被忽略，而不會被拒絕。
</Note>

如需包含各 SDK 程式碼的完整兩輪逐步說明，請參閱[工具與多輪工作流程中的思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-tool-workflows#two-turn-tool-use-round-trip)。該範例會定義一個工具、接收包含思考與工具使用的回應，並將助理輪次連同工具結果一起傳回。

### 交錯思考

「Interleaved thinking」（交錯思考）讓 Claude 能在工具呼叫之間思考，在根據每個工具結果採取行動之前先對其進行推理。透過交錯思考，Claude 可以：

* 在決定下一步之前，對工具呼叫的結果進行推理
* 串連多個工具呼叫，並在其間穿插推理步驟
* 根據中間結果做出更細緻的決策

<Note>
  連續的工具呼叫不需要交錯思考。無論是否使用交錯思考，Claude 都能串連工具呼叫。交錯思考改變的是思考區塊在工具呼叫之間出現的位置，而不是工具呼叫能否串連。
</Note>

使用自適應思考時，交錯思考在每個支援自適應思考的模型上都會自動啟用，不需要 beta 標頭。在 Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5、Claude Mythos Preview、Claude Opus 5.5、Claude Opus 5、Claude Sonnet 5.5、Claude Opus 4.8 和 Claude Opus 4.7 上，工具呼叫之間的推理一律會出現在思考區塊中。Claude Haiku 4.5 不支援交錯思考。在使用手動擴展思考的模型上，交錯思考需要 beta 標頭，並會改變思考預算的計算方式。[手動模式下的交錯思考](https://platform.claude.com/docs/zh-TW/build-with-claude/extended-thinking#interleaved-thinking)涵蓋了各模型的規則和特定平台的標頭行為。

使用交錯思考時，思考配額可以涵蓋整個助理輪次，而非單一回應。交錯思考僅支援[透過 Messages API 使用的工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/overview)。

如需展示交錯思考在雙工具工作流程中帶來哪些改變的實際比較，請參閱[交錯思考如何改變流程](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-tool-workflows#how-interleaved-thinking-changes-the-flow)。

### 工具呼叫之間的進度更新

在 Claude Fable 5.1、Claude Mythos 5.1、Claude Opus 5.5、Claude Sonnet 5.5 和 Claude Fable 5 上，模型可以在工具呼叫之間撰寫「progress update」（進度更新）。進度更新是一則說明模型剛發現了什麼以及接下來要做什麼的註記，是寫給觀看代理的人看的，而非作為推理。每則進度更新都會以其自己的 `thinking` 區塊回傳，並帶有自己的 `signature`，與同一位置的任何推理區塊分開。它緊接在其所引介的 `tool_use` 或 `server_tool_use` 區塊之前。每個工具呼叫之前最多只有一則進度更新，且模型可以略過其中任何一則。進度更新並非[交錯思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#interleaved-thinking)：無論工具呼叫之間是否出現推理區塊，它們都會出現，而且一個回應可以同時包含兩者。

進度更新區塊包含的內容取決於 [`display`](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#controlling-thinking-display)：

| `display`              | 推理區塊             | 進度更新區塊           |
| ---------------------- | ---------------- | ---------------- |
| `"omitted"`（這些模型上的預設值） | 空的 `thinking` 欄位 | 空的 `thinking` 欄位 |
| `"updates"`（beta）      | 空的 `thinking` 欄位 | 摘要文字             |
| `"summarized"`         | 摘要文字             | 摘要文字，無法與推理區塊區分   |

在 Claude Sonnet 5.5 上，最低的思考設定是 `thinking: {type: "between_tools"}`。它會關閉預先思考，而每則進度更新都會帶著其摘要文字回傳，就像在 `display: "updates"` 下一樣。`between_tools` 僅在 [effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時被接受。在 `xhigh` 或 `max` 下，使用它的請求會回傳 400 錯誤。`between_tools` 不接受其他欄位：與其一起傳送的 `display`、`budget_tokens` 或 `block_binding` 會回傳 400 錯誤。此設定不需要 beta 標頭，並可在所有提供 Claude Sonnet 5.5 的平台上運作。請原封不動地傳回區塊：您傳回的進度更新區塊會提供模型它所撰寫的完整註記，而非摘要。

對於隱藏推理、並在每個步驟向使用者顯示狀態列的代理介面，請使用 `display: "updates"`。在此設定下，任何帶有非空文字的 `thinking` 區塊都是進度更新，因此只需呈現這些區塊即可。此功能處於 beta 階段，需要 beta 標頭 `thinking-display-updates-2026-08-18`（若要在 Amazon Bedrock、Google Cloud 或 Microsoft Foundry 上傳送，請參閱[其他平台上的 beta 功能](https://platform.claude.com/docs/zh-TW/api/beta-headers#beta-features-on-other-platforms)）。若沒有該標頭，此值會以與未知 `display` 值相同的 400 `invalid_request_error` 被拒絕。

```json
{
  "model": "claude-fable-5-1",
  "max_tokens": 16000,
  "thinking": { "type": "adaptive", "display": "updates" },
  "tools": [
    {
      "name": "edit_file",
      "description": "Replace the contents of a file in the repository.",
      "input_schema": {
        "type": "object",
        "properties": {
          "path": { "type": "string" },
          "content": { "type": "string" }
        },
        "required": ["path", "content"]
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "The login test fails after an hour of uptime. Find out why and fix it."
    }
  ]
}
```

在 `"updates"` 下，`tool_result` 之後的回應開頭如下所示。第一個區塊是推理，保持為空，就像在 `"omitted"` 下一樣。第二個區塊帶有文字，因此它是進度更新。在 `"summarized"` 下兩個區塊都帶有文字，而在 `"omitted"` 下兩者都是空的。

```json Output
{
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "EqMBCkYICxIM..."
    },
    {
      "type": "thinking",
      "thinking": "Confirmed the retry path never refreshes the expired token. Editing auth.py to add the refresh call.",
      "signature": "Es8CCkYICxIM..."
    },
    {
      "type": "tool_use",
      "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
      "name": "edit_file",
      "input": { "path": "auth.py", "content": "..." }
    }
  ]
}
```

使用進度更新時，請注意以下事項：

* 將進度更新區塊與助理輪次的其餘部分一起原封不動地傳回，就像任何其他 `thinking` 區塊一樣。
* 您收到的文字是進度更新的摘要，通常為一兩句話。請勿依賴其長度。進度更新會以其完整長度（而非摘要的長度）計入 `usage.output_tokens`。
* 在任何 `display` 值下，進度更新區塊都可能以空的 `thinking` 欄位回傳。對於空區塊，請不要呈現任何內容。在 `"updates"` 下，它看起來與空的推理區塊相同，不需要另外處理。
* 當回應在工具呼叫或工具結果後不久因 `max_tokens`、`model_context_window_exceeded` 或 `stop_sequence` 而停止時，其最後一個區塊可能是代表模型尚未完成之工作的進度更新區塊。在 `"updates"` 和 `"summarized"` 下，其文字正好是 `This part of the response was interrupted before it finished.`，您可以像顯示任何其他更新一樣顯示它。在 `"omitted"` 下它是空的。若要繼續，請原封不動地傳回助理輪次，並附加一則新的 `user` 訊息（其中針對該輪次中的每個 `tool_use` 區塊包含一個 `tool_result`）。
* [串流](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)時，預期在進度更新區塊開啟之前會暫停數秒。請參閱[串流思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)中的 `"updates"` 追蹤。
* 這些模型在較高的 [effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 下以及在長工具鏈中撰寫的進度更新較少。如果您的介面依賴它們，請參閱[要求面向使用者的進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-fable-5-1#ask-for-user-facing-progress-updates)，或針對 Claude Opus 5.5 參閱[面向使用者的進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-opus-5-5#user-facing-progress-updates)。針對 Claude Sonnet 5.5，請參閱[面向使用者的進度更新](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#user-facing-progress-updates)。

### 各模型的思考區塊保留方式

先前助理輪次中的「thinking block」（思考區塊）預設是否保留在上下文中，取決於模型：

* **保留所有先前輪次：** Claude Opus 4.5 及更新的 Opus 模型、Claude Sonnet 4.6 及更新的 Sonnet 模型、Claude Haiku 5.5、Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5，以及 Claude Mythos Preview。
* **僅保留最後一個輪次：** 較早的 Opus 和 Sonnet 模型，以及截至 Claude Haiku 4.5 的所有 Haiku 模型。當您將較舊的思考區塊傳回時，API 會自動將其移除。您不需要自行移除它們。

保留思考區塊帶來兩項好處：

* **快取最佳化：** 保留的思考區塊可在工具使用期間實現快取命中，因為它們會與工具結果一起傳回，並在整個助理輪次中逐步快取，從而在多步驟工作流程中節省 token。
* **不影響智慧表現：** 保留思考區塊不會對模型效能產生負面影響。

其代價是上下文用量：在保留所有輪次的模型上，長對話會消耗更多上下文空間，因為保留的思考區塊與其他對話歷史一樣計入輸入（請參閱[思考與上下文視窗](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-and-the-context-window)）。在這兩種機制下，此行為都是自動的。不需要變更程式碼或使用 beta 標頭，且您應繼續依照[保留思考區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserving-thinking-blocks)中的說明，將完整、未經修改的思考區塊傳回。若要在任一方向覆寫預設行為，請使用[思考區塊清除](https://platform.claude.com/docs/zh-TW/build-with-claude/context-editing#thinking-block-clearing)。

**在對話中途切換模型。** 當您切換模型時（例如在[分類器拒絕備援](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback)之後），請持續將思考區塊原封不動地傳回。思考區塊只能由產生它的模型及特定其他模型讀取，API 會忽略或捨棄目標模型無法讀取的區塊。在 Claude Fable 5.1 和 Claude Mythos 5.1 上，方向很重要：它們可讀取較早模型的思考區塊，且只有這兩者能讀取彼此的區塊，因此切換到它們會保留對話的推理，而從它們切換到任何其他模型則會捨棄推理（請參閱[被捨棄區塊的計費與回報方式](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#switching-models)）。Claude Opus 5.5 可讀取 Claude Opus 5 的思考區塊，以及較早的 Opus、Sonnet 和 Haiku 模型的思考區塊，並且在 Claude API 和 Google Cloud 上可讀取 Claude Haiku 5.5 的思考區塊，但無法讀取 Claude Fable 和 Claude Mythos 模型的思考區塊；在 Claude API 上，Claude Fable 5.1 和 Claude Mythos 5.1 可讀取 Claude Opus 5.5 的區塊。在 Claude API 上從 Claude Opus 5.5 升級切換到 Claude Fable 5.1 會保留先前輪次的推理；從 Claude Fable 5.1 切換到 Claude Opus 5.5 則會捨棄推理。Claude Sonnet 5.5 可讀取來自 Claude Sonnet 5、Claude Opus 4.8、Claude Haiku 4.5 及較早模型的思考區塊，並且在 Claude API 和 Google Cloud 上可讀取來自 Claude Haiku 5.5 的思考區塊，但無法讀取來自 Claude Opus 5、Claude Opus 5.5 或任何 Claude Fable 或 Claude Mythos 模型的思考區塊。在 Claude API 和 Google Cloud 上，Claude Opus 5.5 可讀取 Claude Sonnet 5.5 的區塊，其他模型則都無法讀取：在 Claude API 和 Google Cloud 上從 Claude Sonnet 5.5 升級切換到 Claude Opus 5.5 會保留先前輪次的推理，而從 Claude Sonnet 5.5 進行的任何其他切換都會捨棄推理。Claude Haiku 5.5 可讀取來自 Claude Sonnet 5、Claude Opus 4.8、Claude Haiku 4.5 及較早模型的思考區塊，但無法讀取來自 Claude Opus 5、Claude Opus 5.5、Claude Sonnet 5.5 或任何 Claude Fable 或 Claude Mythos 模型的思考區塊。在 Claude API 和 Google Cloud 上，Claude Opus 5.5 和 Claude Sonnet 5.5 可讀取 Claude Haiku 5.5 的區塊，其他模型則都無法讀取。只有在模型會忽略而非捨棄先前的 `thinking` 和 `redacted_thinking` 區塊時，才為了節省輸入 token 而自行移除它們；而在兌換[備援抵免](https://platform.claude.com/docs/zh-TW/build-with-claude/fallback-credit)時絕對不要這麼做，因為兌換需要請求主體保持不變。

## 保留思考

[保留思考](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking)決定模型是否能使用您從先前輪次傳回的思考區塊。從 Claude Fable 5.1 開始，API 會檢查請求中每個 `thinking` 或 `redacted_thinking` 區塊的 `signature`，確認兩件事：

* **產生它的模型。** 每個模型都能讀取自己的思考區塊，以及一組固定的其他模型的思考區塊。Claude Fable 5.1 可讀取來自 Claude Opus 5 的區塊，在 Claude API 上也可讀取來自 Claude Opus 5.5 的區塊；Claude Opus 5 和 Claude Opus 5.5 都無法讀取來自 Claude Fable 5.1 的區塊。API 會捨棄目前模型無法讀取的區塊，不會產生錯誤，也不會對其計費。請參閱[在對話中途切換模型](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#switching-models)。
* **在它之前傳送的所有內容。** 只有在頂層 `system` 提示、`tools` 以及它之前的訊息都保持不變時，區塊才會維持有效。如果其中任何一項發生變更，該區塊及之後的所有思考區塊都會失效，API 會依您的選擇，以 400 錯誤拒絕請求或捨棄失效的區塊。請參閱[保持前綴不變](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#prefix-check)。

來自 Claude Sonnet 5.5 和 Claude Haiku 5.5 的思考區塊也與產生它們的帳戶綁定。請參閱[思考區塊僅限產生它們的帳戶使用](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#account-bound-thinking)，了解 API 在何處強制執行此規則。

模型檢查適用於所有帳戶。對於在 2026 年 8 月 31 日 00:00 UTC 或之後建立的帳戶，API 預設會強制執行前綴檢查。在較舊的帳戶上，API 僅對設定了 `thinking.block_binding.prefix_mismatch_behavior` 的請求強制執行此檢查。無論您的帳戶建立時間為何，都請讓您的整合採用僅附加（append-only）的方式，如此相同的程式碼就能在所有帳戶上運作，包括預設強制執行檢查的較新帳戶。

若要讓思考保持有效，請將每個助理輪次完全按照您收到的樣子傳回，並且只在 `messages` 的末尾新增訊息。如果您的程式碼會自行建構 `messages` 陣列，保留思考頁面涵蓋以下內容：

* [哪些變更算是編輯](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#what-counts-as-an-edit)，以及[如何檢查您的程式碼是否進行了編輯](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#how-to-tell-whether-your-integration-is-impacted)。
* [取代各種常見編輯的 API 功能](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#replace-prefix-edits)：用於新指示和每輪提醒的對話中途系統訊息、用於工具變更的 `tool_addition` 和 `tool_removal` 區塊、用於 effort 變更的每則訊息 `output_config`，以及用於修剪的伺服器端壓縮和上下文編輯。
* [用戶端壓縮](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#custom-compaction-on-the-client)：哪些模式能讓思考保持有效，哪些則不能。
* [`thinking-binding-controls-2026-08-01` beta 標頭](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#preserved-thinking-controls)。它會在思考設定中新增 `block_binding.prefix_mismatch_behavior` 欄位（`"error"` 或 `"drop_block"`），並在每個回應中新增 `input_transformations` 陣列。該陣列會列出 API 捨棄的每個思考區塊，或未通過前綴檢查但仍被放行的每個思考區塊。

## 思考與提示快取

[提示快取](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-caching)與思考之間有幾種特定的交互作用。以下規則適用於兩種思考模式。

**設定變更會使快取失效。** 思考設定和解析後的 [`effort`](https://platform.claude.com/docs/zh-TW/build-with-claude/effort) 等級會被呈現在提示本身中，因此變更其中任何一項都會開始新的快取前綴。在 `adaptive`、`enabled` 和 `disabled` 之間切換、變更 `budget_tokens`，以及變更 effort 值，都會使快取斷點失效：訊息層級的斷點一定會未命中，而工具和系統提示的斷點也可能未命中，取決於模型呈現設定的位置。請將任何思考或頂層 effort 的變更視為重新開始快取。在支援[每則訊息 effort](https://platform.claude.com/docs/zh-TW/build-with-claude/effort#change-effort-mid-conversation-beta) 的模型上，透過 `messages` 內的 `role: "system"` 訊息所進行的 effort 變更會讓快取前綴保持完整。保持相同設定的連續請求會保留快取，而將參數明確設定為其預設值等同於省略該參數。API 在任何[保留思考條件](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserved-thinking)下捨棄的思考區塊，會從該區塊的位置開始改變快取前綴。原封不動傳回的區塊則會讓快取保持完整。包含用量輸出的實際示範請參閱[引導思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#prompt-caching)頁面。

**思考區塊會與工具結果一起快取。** 在工具使用迴圈中，當您發出包含工具結果的後續請求時，就會進行快取。此時，先前的對話歷史（包括其思考區塊）可以被快取，而這些快取的思考區塊在從快取讀取時，會在您的用量指標中計為輸入 token。這會自動發生，即使沒有明確的 `cache_control` 標記也是如此，且對一般思考和交錯思考的行為相同。其代價是：您在回應中不會再看到的思考區塊，從快取讀取時仍會計入輸入 token 用量。

**先前的區塊是否存在於上下文中取決於模型。** 這由[保留預設值](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)決定。在保留所有輪次的模型上，先前輪次的思考區塊會保持快取並留在上下文中。在僅保留最後一個輪次的模型上，一旦您傳送非工具結果的使用者訊息，所有先前的思考區塊都會從上下文中移除。在這些模型上，像這樣的對話：

```text wrap
User: ["What's the weather in Paris?"],
Assistant: [thinking_block_1] + [tool_use block 1],
User: [tool_result_1, cache=True],
Assistant: [thinking_block_2] + [text block 2],
User: [Text response, cache=True]
```

會被當作思考區塊從未存在過一樣處理：

```text wrap
User: ["What's the weather in Paris?"],
Assistant: [tool_use block 1],
User: [tool_result_1, cache=True],
Assistant: [text block 2],
User: [Text response, cache=True]
```

在保留所有輪次的模型上，相同的請求會將 `thinking_block_1` 和 `thinking_block_2` 保留在上下文和快取中。

**降級會從可快取的歷史中移除思考。** 如果思考在輪次中途被停用，而您在目前的工具使用輪次中傳入思考內容，則思考內容會被移除，且該請求的思考會維持停用狀態（請參閱[優雅降級](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)）。[交錯思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#interleaved-thinking)會放大快取失效的影響，因為思考區塊可能出現在多個工具呼叫之間。

<Tip>
  大量思考的任務通常需要比預設 5 分鐘快取存留時間更長的時間才能完成。請考慮使用 [1 小時快取期限](https://platform.claude.com/docs/zh-TW/build-with-claude/prompt-caching#1-hour-cache-duration)，以便在較長的思考工作階段和多步驟工作流程中維持快取命中。
</Tip>

## 思考與上下文視窗

`max_tokens`（包含 Claude 在目前輪次中產生的所有思考）會被強制作為嚴格上限。在 Claude 4.5 及更新的模型上，如果輸入 token 加上 `max_tokens` 超過上下文視窗大小，API 仍會接受請求。如果生成過程隨後達到上下文視窗上限，它會以 `stop_reason: "model_context_window_exceeded"` 停止，而不是傳回錯誤。在較早的模型上，API 則會傳回驗證錯誤。請參閱[處理停止原因](https://platform.claude.com/docs/zh-TW/build-with-claude/handling-stop-reasons)。

思考如何計入視窗取決於其產生的時間：

* **目前輪次的思考**一律計入 `max_tokens`，以輸出 token 計費，並在產生它的輪次中佔用上下文視窗空間。
* **先前輪次的思考**取決於[保留預設值](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)。在[保留所有先前輪次的模型](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)上，先前的思考區塊會留在上下文中、計入視窗，並與其餘對話歷史一樣以輸入 token 計費。在僅保留最後一個輪次的模型上，當您將較舊的思考區塊傳回時，API 會自動將其移除，因此它們不會佔用視窗空間或輸入 token。

實務上：

* 在保留所有輪次的模型上，請將思考視為一般對話歷史來規劃您的上下文視窗預算，因為它確實就是。長時間的代理工作階段會在上下文中累積思考。如果您需要回收空間，請使用[思考區塊清除](https://platform.claude.com/docs/zh-TW/build-with-claude/context-editing#thinking-block-clearing)。
* 在僅保留最後一個輪次的模型上，思考只是每輪的成本：每個輪次的思考會計入該輪次的 `max_tokens`，然後從視窗中移除。

以下圖表說明僅保留最後一個輪次（移除）的機制。第一張圖顯示多輪對話：每個輪次的「thinking block」（思考區塊）會在輸出中產生，但不會帶入後續輪次的輸入。

<Frame>
  ![在會移除先前思考區塊的模型上的思考示意圖：每個輪次的思考區塊會在輸出中產生，且不會帶入後續輪次的輸入](https://platform.claude.com/docs/zh-TW/images/context-window-thinking.svg)
</Frame>

第二張圖顯示相同機制搭配「tool use」（工具使用）的情況：在助理輪次期間，思考會與其「tool result」（工具結果）一起留在上下文中，然後在下一個使用者輪次時被移除。

<Frame>
  ![在會移除先前思考區塊的模型上搭配工具使用的思考示意圖：思考會與其工具結果一起保留，然後在下一個使用者輪次時被捨棄](https://platform.claude.com/docs/zh-TW/images/context-window-thinking-tools.svg)
</Frame>

請使用 [token 計數 API](https://platform.claude.com/docs/zh-TW/build-with-claude/token-counting) 取得您特定使用情境的準確計數，特別是包含思考的多輪對話。

## 思考加密

完整的思考內容會經過加密，並在每個思考區塊的 `signature` 欄位中傳回。當您傳回思考區塊時，API 會使用簽章來驗證這些思考區塊是由 Claude 產生的。

使用簽章時，請留意以下事項：

* 只有在[搭配思考使用工具](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)時，才嚴格需要傳回思考區塊。否則，您可以省略先前輪次的思考區塊。如果您確實傳回了它們，API 會保留還是移除它們取決於模型（請參閱[各模型的思考區塊保留方式](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)）。請使用[上下文編輯](https://platform.claude.com/docs/zh-TW/build-with-claude/context-editing)來設定此行為。
* 傳回思考區塊時，請將所有內容完全依照您收到的樣子傳回，以確保一致性並避免潛在問題。
* 在[串流回應](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)時，簽章會在 `content_block_stop` 事件之前，以 `content_block_delta` 事件中的 `signature_delta` 形式送達。
* 在 Claude 4 及之後的模型中，`signature` 值明顯比先前的模型更長。
* `signature` 欄位是不透明的：請勿解讀或剖析它。
* `signature` 值可跨平台相容（Claude API、[Amazon Bedrock](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-in-amazon-bedrock) 和 [Google Cloud](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-on-vertex-ai)）。在一個平台上產生的值可在另一個平台上使用，但來自 Claude Sonnet 5.5 和 Claude Haiku 5.5 的思考區塊只能在產生它們的帳戶或與其連結的帳戶中使用。請參閱[思考區塊僅限產生它們的帳戶使用](https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#account-bound-thinking)。

## 已編修的思考區塊

除了一般的 `thinking` 區塊之外，當 Claude 的部分推理因安全考量而被編修時，API 可能會傳回 `redacted_thinking` 區塊。`redacted_thinking` 區塊在 `data` 欄位中包含加密的思考內容，沒有可讀的文字：

```json
{
  "type": "redacted_thinking",
  "data": "..."
}
```

`data` 欄位是不透明且經過加密的。與一般思考區塊上的 `signature` 欄位一樣，在搭配[工具](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)繼續多輪對話時，請將 `redacted_thinking` 區塊原封不動地傳回 API。

<Tip>
  如果您的程式碼在來回傳遞包含工具使用的回應時，會依類型篩選內容區塊（例如 `block.type == "thinking"`），請同時納入 `redacted_thinking` 區塊。僅依 `block.type == "thinking"` 篩選會在不知不覺中捨棄 `redacted_thinking` 區塊，並破壞[保留思考區塊](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserving-thinking-blocks)中所述的多輪協定。
</Tip>

<Note>
  `redacted_thinking` 區塊是一種獨立的內容區塊類型，會在思考因安全考量而被編修時傳回。這與 [`display: "omitted"`](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#controlling-thinking-display) 選項不同，後者會傳回 `thinking` 欄位為空的一般 `thinking` 區塊。
</Note>

## 限制與功能相容性

### 取樣參數

在 Claude Fable 5.1、Claude Mythos 5.1、Claude Fable 5、Claude Mythos 5、Claude Mythos Preview、Claude Opus 5.5、Claude Opus 5、Claude Opus 4.8、Claude Opus 4.7、Claude Sonnet 5.5、Claude Sonnet 5 和 Claude Haiku 5.5 上，非預設的 `temperature`、`top_p` 或 `top_k` 值在每個請求上都會傳回 400 錯誤，無論是否使用思考。在這些模型上，`top_p` 的預設值為 `0.99`，因此 `top_p` 為 `1` 會傳回 400 錯誤，同時包含 `temperature` 和 `top_p` 的請求也會如此，即使它們都是預設值。請參閱[移除取樣參數](https://platform.claude.com/docs/zh-TW/models/haiku-5-5/migration-guide#remove-sampling-parameters)。在較舊的模型上，此限制僅在思考開啟時適用：`temperature` 和 `top_k` 與思考不相容，而 `top_p` 允許介於 0.95 到 1 之間的值。

### 回應預填與強制工具使用

Claude 4.6 及之後的模型以及 Claude Mythos Preview 會以 400 錯誤拒絕預填的最終助理輪次，無論思考是否開啟（請參閱[不支援預填](https://platform.claude.com/docs/zh-TW/api/errors#prefill-not-supported)）。在較早的模型上，思考開啟時無法預填助理回應。強制工具使用（`tool_choice: {"type": "any"}` 或 `{"type": "tool", ...}`）與手動擴展思考不相容，但可搭配自適應思考使用。例外情況是 Claude Opus 5.5、Claude Sonnet 5.5、Claude Fable 5.1 和 Claude Mythos 5.1，它們會在每個請求上以 400 錯誤拒絕強制工具使用。在這些模型上，請改用 `tool_choice: {"type": "auto"}` 搭配[嚴格工具使用](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/strict-tool-use)或[結構化輸出](https://platform.claude.com/docs/zh-TW/build-with-claude/structured-outputs)。在接受強制工具使用的情況下，回應會以工具呼叫開始，且沒有 `thinking` 區塊。若要讓模型在呼叫工具之前先思考，請使用 `tool_choice: {"type": "auto"}`，並在提示中說明何時使用該工具。請參閱[搭配工具使用的思考](https://platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)。

### 輸出限制

每個模型接受的 `max_tokens` 上限如下所列。在 [Message Batches API](https://platform.claude.com/docs/zh-TW/build-with-claude/batch-processing#extended-output-beta) 上，`output-300k-2026-03-24` [beta 標頭](https://platform.claude.com/docs/zh-TW/api/beta-headers)會為列有批次上限的模型提高該上限。

| Model                 | Max output tokens | Batches beta ceiling |
| :-------------------- | :---------------- | :------------------- |
| Claude Fable 5.1      | 128K              | —                    |
| Claude Mythos 5.1     | 128K              | —                    |
| Claude Fable 5        | 128K              | —                    |
| Claude Mythos 5       | 128K              | —                    |
| Claude Mythos Preview | 128K              | Not available        |
| Claude Opus 5.5       | 128K              | 300K                 |
| Claude Opus 5         | 128K              | 300K                 |
| Claude Opus 4.8       | 128K              | 300K                 |
| Claude Opus 4.7       | 128K              | 300K                 |
| Claude Opus 4.6       | 128K              | 300K                 |
| Claude Opus 4.5       | 64K               | Not available        |
| Claude Sonnet 5.5     | 128K              | 300K                 |
| Claude Sonnet 5       | 128K              | 300K                 |
| Claude Sonnet 4.6     | 128K              | 300K                 |
| Claude Sonnet 4.5     | 64K               | Not available        |
| Claude Haiku 5.5      | 128K              | 300K                 |
| Claude Haiku 4.5      | 64K               | Not available        |

舊版模型的限制請參閱[模型概覽](https://platform.claude.com/docs/zh-TW/models/overview)。

### 長時間請求

當 `max_tokens` 大於 21,333 時，SDK 要求使用串流，以避免長時間執行的請求發生 HTTP 逾時。這是用戶端驗證，而非 API 限制。如果您不需要逐步處理事件，請使用 `.stream()` (java: `.createStreaming()`; csharp: `.CreateStreaming()`; go: `.NewStreaming()`; php: `->createStream()`) 搭配 `.get_final_message()` (typescript: `.finalMessage()`; ruby: `.accumulated_message`; csharp: `.Aggregate()`; go: `message.Accumulate(event)`; java, php: `MessageAccumulator`) 來取得完整的 `Message` 物件，而無需自行從個別事件組合。請參閱[串流訊息](https://platform.claude.com/docs/zh-TW/build-with-claude/streaming#get-the-final-message-without-handling-events)。思考啟用時，回應時間預期會較長，因為產生思考區塊會增加處理時間。對於每個請求的思考量超過約 32k token 的工作負載，請使用[批次處理](https://platform.claude.com/docs/zh-TW/build-with-claude/batch-processing)以避免網路問題：此類請求的執行時間可能長到觸及系統逾時和開放連線數限制。

## 後續步驟

<CardGroup cols={2}>
  <Card title="引導思考" icon="compass" href="https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost">
    透過 effort 等級、系統提示指引和每則訊息引導，控制 Claude 思考的頻率與深度，並了解思考的成本與定價。
  </Card>

  <Card title="工具與多輪工作流程中的思考" icon="wrench" href="https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-tool-workflows">
    逐步了解一個正確保留思考區塊的完整兩輪工具使用往返流程，並查看交錯思考如何改變流程。
  </Card>

  <Card title="保留思考" icon="stack" href="https://platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking">
    確認您的 Messages API 整合是否會編輯對話歷史，並以能讓先前思考區塊保持有效的 API 功能取代每一項編輯。
  </Card>

  <Card title="思考疑難排解" icon="hammer" href="https://platform.claude.com/docs/zh-TW/build-with-claude/thinking-troubleshooting">
    診斷並修正最常見的思考失敗情況：設定造成的 400 錯誤、空白或缺少的思考區塊、max\_tokens 停止，以及快取未命中。
  </Card>

  <Card title="Effort" icon="sliders" href="https://platform.claude.com/docs/zh-TW/build-with-claude/effort">
    使用 effort 參數控制 Claude 回應時使用的 token 數量，在回應的完整度與 token 效率之間取得平衡。
  </Card>
</CardGroup>
