---
title: 思考
url: https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking
description: 了解 Claude 的思考如何運作：開啟思考、讀取思考輸出、透過 effort 調整思考深度，以及將思考與工具、快取和串流搭配使用。
featureMetadata:
  status: stable
  zdr:
    eligibility: eligible
    note: Excludes [Covered Models](https://code.saschaberens.de/_h/platform.claude.com/docs/en/manage-claude/api-and-data-retention#model-specific-data-retention-requirements).
  supportedModels:
    - claude-fable-5-2
    - claude-mythos-5-2
    - 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-sonnet-5
    - claude-haiku-5-5
    - claude-haiku-4-5-20251001
    - claude-opus-4-8
    - claude-opus-4-7
    - claude-opus-4-6
    - claude-sonnet-4-6
    - claude-opus-4-5-20251101
    - claude-sonnet-4-5-20250929
  supportedPlatforms:
    Claude API: stable
    Amazon Bedrock: stable
    Amazon Bedrock (bedrock-runtime): stable
    Claude Platform on AWS: stable
    Claude Models on Google Cloud (Anthropic managed): stable
    Claude Models on Google Cloud (Google managed): stable
    Microsoft Foundry: stable
---

**API 支援**：用法因產品而異。

* **Messages API**：預設開啟。在接受該值的模型上，`thinking: {"type": "disabled"}` 可將其關閉。若預設為關閉，請設定 `thinking` 以將其開啟。
* **Managed Agents**：永遠開啟。思考設定由 Managed Agents 設定；代理定義中沒有 `thinking` 欄位。

一次就給出答案的模型必須在第一次嘗試時就把所有事情做對：沒有草稿、沒有檢查，也無法在中途改變做法。對於證明、棘手的錯誤或長時間的代理任務而言，第一種做法往往不是最好的。

思考消除了這項限制。當思考啟用時，Claude 會在回答之前先以自己的話處理問題：重新陳述問題、嘗試各種做法、檢查中間結果，並放棄站不住腳的路徑。這些前置思考會以 `thinking` 內容區塊的形式出現在回應之前，Claude 會藉此產生最終答案。這就是為什麼思考能提升數學、程式撰寫、分析及長時間執行的代理工作等複雜任務的表現——在這些任務中，答案的品質取決於中間過程，而這些過程若不思考，便會被壓縮進回應本身或被略過。

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

## 思考如何運作

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

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

以下是前置思考在回應中的樣貌：一個或多個 `thinking` 內容區塊會出現在 `text` 區塊之前。思考區塊仍然是生成的內容，就像其後的 `text` 區塊一樣，但它與正式回應是分開的。每個思考區塊也帶有一個 `signature` 欄位，這是完整推理的加密副本，您在多輪對話和工具使用對話中需原封不動地傳回（請參閱[思考加密](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#summarized-thinking)。思考設定上的 `display` 欄位控制是否回傳該摘要：`"summarized"` 會回傳摘要，而 `"omitted"`（許多模型上的預設值）則會回傳 `thinking` 欄位為空的思考區塊。無論哪種方式，該區塊的計費相同，在多輪對話中的傳回方式也相同。請參閱[控制思考顯示](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#controlling-thinking-display)以了解各模型的預設值和詳細資訊。

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

## 設定思考

在大多數模型上，思考預設為開啟，或只需一個參數即可開啟。下表顯示每個模型對請求可傳送的各個 `thinking` 值的處理方式。400 錯誤表示 API 拒絕該請求，[思考疑難排解](https://code.saschaberens.de/_h/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.2 | 自適應思考 | 自適應思考 | 400 錯誤 | 400 錯誤 | 400 錯誤 |
| Claude Mythos 5.2 | 自適應思考 | 自適應思考 | 400 錯誤 | 400 錯誤 | 400 錯誤 |
| 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 5 及更新的模型和 Claude Mythos Preview 上，思考已經開啟，不需要任何設定。這些模型上的 `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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/overview)替換後，即可在這些模型上開啟思考。以下範例設定了 `display: "summarized"` 以顯示思考文字，並使用較大的 `max_tokens`：

<CodeGroup>
  ```bash cURL
  curl https://code.saschaberens.de/_h/api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -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?"}'
  ```

  ```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 UserMessageParam { 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\Model;
  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: 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: Anthropic::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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#cost-control)以及[思考與上下文視窗](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-and-the-context-window)。

### 關閉思考

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

<CodeGroup>
  ```bash cURL
  curl https://code.saschaberens.de/_h/api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -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 UserMessageParam { 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: Model::CLAUDE_SONNET_5,
      thinking: ['type' => 'disabled'],
  );
  ```

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

  message = client.messages.create(
    model: Anthropic::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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時被接受。模型仍會回傳其[工具呼叫之間的進度更新](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)。沒有工具時，回應只包含文字，就如同在 Claude Sonnet 5 上使用 `disabled` 一樣。請參閱[在不進行前置思考的情況下執行](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時接受 `thinking: {type: "disabled"}`。在 `xhigh` 或 `max` effort 下，該組合會回傳 400 錯誤。若要減少思考，請先降低 effort 等級。在思考關閉的情況下，當您同時要求 JSON 輸出時，模型可能會略過它需要的工具呼叫。當思考關閉時，與目前生效等級不同的[每則訊息 `output_config.effort`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort-per-message) 也會回傳 400 錯誤。請參閱[使用 effort 控制思考](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#use-effort-to-control-thinking)和[搭配 JSON 輸出與您自己的工具使用自適應思考](https://code.saschaberens.de/_h/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.2、Claude Mythos 5.2、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"` 或 `"between_tools"`，請從 Models API 讀取其 `capabilities.thinking.types.disabled.supported` 或 `capabilities.thinking.types.between_tools.supported` 值。[使用 Models API](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/overview#using-the-models-api) 說明了這兩個欄位。

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

## 讀取思考輸出

### 控制思考顯示

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

* `"summarized"`：思考區塊包含[摘要後的思考](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-encryption)）。這是 Claude Fable 5.2、Claude Mythos 5.2、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://code.saschaberens.de/_h/anthropic.com/glasswing) 和 Claude Haiku 5.5 上的預設值。
* `"updates"`（beta）：推理區塊會以空的 `thinking` 欄位回傳，與 `"omitted"` 相同，而部分模型在工具呼叫之間撰寫的簡短[進度更新](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#progress-updates)會串流帶有文字的 `thinking_delta` 事件。請參閱[串流思考](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)以了解事件順序。

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

### 摘要後的思考

當 `display` 為 `"summarized"` 時，您收到的思考文字是 Claude 完整思考過程的摘要，而非原始的思維鏈。摘要後的思考既能提供思考的完整智慧效益，又能防止濫用。沒有任何 `display` 設定會回傳原始的思維鏈。

使用摘要後的思考時，請留意以下事項：

* 您需支付原始請求所產生的完整思考 token 費用，而非摘要 token 的費用。計費的輸出 token 數量與您在回應中看到的 token 數量並不相符。
* 在 Claude Opus 4.6、Claude Sonnet 4.6 及更早的模型上，思考輸出的前幾行會較為詳細，提供對提示工程特別有幫助的詳細推理。[Claude Mythos Preview](https://code.saschaberens.de/_h/anthropic.com/glasswing) 從第一個 token 就開始摘要，因此其思考區塊不會出現這段詳細的開場內容。
* 摘要會保留 Claude 思考過程的關鍵概念，且僅增加極少的延遲，因此摘要可以在產生時即時串流。
* 摘要是由與您在請求中指定之模型不同的另一個模型處理的。思考模型不會收到摘要後的輸出。

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

若要查看模型推理的摘要，請在 `display` 設為 `"summarized"` 的情況下讀取 `thinking` 區塊，而非在回應文字中以提示要求推理。部分模型可能會拒絕要求在回應文字中提供其內部推理的請求。該拒絕會帶有 `stop_details.category: "reasoning_extraction"`。如需這些模型的清單以及應改為要求什麼，請參閱[將推理保留在思考區塊中](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks)。如需欄位參考，請參閱[拒絕的樣貌](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#refusal-response)。

### 串流思考

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

<Frame>
  ![Thinking stream（思考串流）：區塊開啟，僅在 display 回傳文字時增量才帶有文字，一個簽章增量將其關閉，接著是文字](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/images/how-thinking-streams.svg)
</Frame>

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

<CodeGroup>
  ```bash cURL
  curl https://code.saschaberens.de/_h/api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -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 UserMessageParam { 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.Raw()} 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(thinkingDelta ->
                          IO.print(thinkingDelta.thinking())
                      );
                      deltaEvent.delta().text().ifPresent(textDelta ->
                          IO.print(textDelta.text())
                      );
                  }
              }
          });
      }
  }
  ```

  ```php PHP
  use Anthropic\Messages\Model;
  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: 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: Anthropic::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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/streaming)。

## 思考與 effort

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

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

在兩種控制以這種方式分開的情況下，請選擇符合您目標的那一種：

* **降低啟用思考之工作負載的成本或延遲：** 先降低 `effort`。它會縮減整個回應，包括思考在內。
* **Claude 思考得太少或太淺：** 提高 `effort`，或參閱引導頁面上的[引導 Claude 思考的頻率](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking-steering-and-cost#tuning-thinking-behavior)。
* **您需要完全關閉思考：** 在允許的模型上使用 `thinking: {type: "disabled"}`（請參閱[各模型設定表](https://code.saschaberens.de/_h/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` 是嚴格的限制。

## 搭配工具使用的思考

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

1. **工具選擇限制（手動模式）：** 搭配手動擴展思考（`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.2、Claude Mythos 5.2、Claude Fable 5.1 和 Claude Mythos 5.1 除外（請參閱[回應預填與強制工具使用](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#response-prefill-and-forced-tool-use)）。在接受強制工具使用的情況下，回應會以工具呼叫開頭，且不含 `thinking` 區塊。
2. **保留思考區塊：** 當您回傳工具結果時，必須將助理訊息中的思考區塊完整且未經修改地傳回 API。請參閱[保留思考區塊](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)。若要覆寫預設行為，請使用 [`clear_thinking_20251015` 上下文編輯策略](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/context-editing#thinking-block-clearing)。

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

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

如需每個 SDK 都附有程式碼的完整範例，請參閱[逐步了解兩輪工具使用往返](https://code.saschaberens.de/_h/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>

使用自適應思考時，交錯思考在所有支援自適應思考的模型上都會自動啟用。在 Claude Fable 5.2、Claude Mythos 5.2、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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/extended-thinking#interleaved-thinking)涵蓋了各模型的規則以及各平台特定的標頭行為。

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

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

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

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

進度更新區塊包含的內容取決於 [`display`](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort) 為 `high` 或更低時被接受。在 `xhigh` 或 `max` 下，使用它的請求會回傳 400 錯誤。`between_tools` 不接受任何其他欄位：與其一起傳送的 `display`、`budget_tokens` 或 `block_binding` 會回傳 400 錯誤。此設定可在所有提供 Claude Sonnet 5.5 的平台上運作。請原封不動地傳回這些區塊：您傳回的進度更新區塊會提供模型它所撰寫的完整註記，而非摘要。

若您的代理介面會隱藏推理並在每個步驟向使用者顯示狀態列，請使用 `display: "updates"`。在此設定下，任何帶有非空文字的 `thinking` 區塊都是進度更新，因此只需呈現這些區塊即可。此功能處於 beta 階段，需要 beta 標頭 `thinking-display-updates-2026-08-18`。若要在雲端平台上傳送此標頭，請參閱[其他平台上的 beta 功能](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/api/beta-headers#beta-features-on-other-platforms)。若沒有此標頭，API 會以與未知 `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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#streaming-thinking)中的 `"updates"` 追蹤。
* 這些模型在較高的 [effort](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort) 下以及在較長的工具鏈中會撰寫較少的進度更新。如果您的介面依賴進度更新，請參閱[要求面向使用者的進度更新](https://code.saschaberens.de/_h/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 和 Claude Sonnet 5.5，請參閱[為 Claude Opus 5.5 撰寫提示](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#user-facing-progress-updates)中的「面向使用者的進度更新」。針對 Claude Fable 5.2，請參閱[在長回合期間讓使用者掌握進度](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/prompt-engineering/prompting-claude-fable-5-2#keep-users-informed-during-long-turns)。

### 各模型的思考區塊保留行為

先前助理回合中的思考區塊是否預設保留在上下文中，取決於模型：

* **保留所有先前回合：** Claude Opus 4.5 及更新的 Opus 模型、Claude Sonnet 4.6 及更新的 Sonnet 模型、Claude Haiku 5.5、Claude Fable 5.2、Claude Mythos 5.2、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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-and-the-context-window)）。在這兩種機制下，此行為都是自動的。請依照[保留思考區塊](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserving-thinking-blocks)中的說明，持續傳回完整且未經修改的思考區塊。若要朝任一方向覆寫預設值，請使用[思考區塊清除](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/context-editing#thinking-block-clearing)。

**在對話中途切換模型。** 當您切換模型時（例如在[分類器拒絕備援](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback)之後），請持續將思考區塊原封不動地傳回。思考區塊只能由產生它的模型及特定其他模型讀取。API 會忽略或捨棄目標模型無法讀取的區塊（請參閱[切換模型再切換回來](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#switching-models)）。針對下列清單中的每個模型，清單說明該模型能讀取哪些區塊，以及哪些模型能讀取它的區塊：

* **Claude Fable 5.2 和 Claude Mythos 5.2：** 在 Claude API 和 Claude Models on Google Cloud (Google managed) 上，它們能讀取彼此的思考區塊。在這些平台上，它們也能讀取其他模型的區塊，包括 Claude Opus 5.5、Claude Sonnet 5.5 和 Claude Haiku 5.5。沒有任何其他模型能讀取 Claude Fable 5.2 或 Claude Mythos 5.2 的區塊。因此，從它們其中任一個切換到這一對以外的模型都會捨棄先前回合的推理。
* **Claude Fable 5.1 和 Claude Mythos 5.1：** 它們能讀取彼此的思考區塊以及[較早模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#which-model-switches-keep-reasoning)的思考區塊，但 Claude Mythos Preview 的除外。在 Claude API 和 Claude Models on Google Cloud (Google managed) 上，Claude Fable 5.2 和 Claude Mythos 5.2 也能讀取它們的區塊。其他模型則不能。從它們能讀取其區塊的模型切換到 Claude Fable 5.1 或 Claude Mythos 5.1，會保留對話的推理。從它們其中任一個切換到無法讀取其區塊的模型，則會捨棄推理。
* **Claude Opus 5.5：** 它能讀取 Claude Opus 5 以及[較早的 Claude Opus、Claude Sonnet 和 Claude Haiku 模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#earlier-models)的思考區塊。在 Claude API 和 Claude Models on Google Cloud (Google managed) 上，它也能讀取 Claude Sonnet 5.5 和 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 Models on Google Cloud (Google managed) 上，Claude Fable 5.2 和 Claude Mythos 5.2 也能讀取這些區塊。在 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 Opus、Claude Sonnet 和 Claude Haiku 模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#earlier-models)的思考區塊。在 Claude API 和 Claude Models on Google Cloud (Google managed) 上，它也能讀取 Claude Haiku 5.5 的思考區塊。它無法讀取 Claude Opus 5、Claude Opus 5.5 或任何 Claude Fable 或 Claude Mythos 模型的思考區塊。在這兩個平台上，Claude Opus 5.5、Claude Fable 5.2 和 Claude Mythos 5.2 能讀取 Claude Sonnet 5.5 的區塊。其他模型則不能。在那裡從 Claude Sonnet 5.5 向上切換到這三個模型之一，會保留先前回合的推理。從 Claude Sonnet 5.5 進行的任何其他切換都會捨棄推理。
* **Claude Haiku 5.5：** 它能讀取 Claude Sonnet 5、Claude Opus 4.8、Claude Haiku 4.5 以及[較早的 Claude Opus、Claude Sonnet 和 Claude Haiku 模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#earlier-models)的思考區塊。它無法讀取 Claude Opus 5、Claude Opus 5.5、Claude Sonnet 5.5 或任何 Claude Fable 或 Claude Mythos 模型的思考區塊。有四個模型能讀取 Claude Haiku 5.5 的區塊：Claude Opus 5.5、Claude Sonnet 5.5、Claude Fable 5.2 和 Claude Mythos 5.2。它們在 Claude API 和 Claude Models on Google Cloud (Google managed) 上能這麼做。其他模型則不能。

切換時請勿移除思考區塊。API 會捨棄無法讀取的區塊且不對其計費，而能讀取這些區塊的模型仍會收到它們。移除區塊也會讓您失去[備援額度](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/fallback-credit)，因為備援額度要求請求本文保持不變。

## 保留思考

在[具有保留思考的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#outcomes)上，每個傳回思考區塊的請求都會經過[前綴檢查](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#prefix-check)。如果您的程式碼變更了 `system`、`tools` 或較早的訊息，則已經位於該變更之後的每個思考區塊都會未通過前綴檢查。此時，該請求可能會收到 400 錯誤。

另外兩項規則會捨棄區塊，且不會產生錯誤。模型只能讀取部分其他模型的思考區塊（請參閱[切換模型再切換回來](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#switching-models)）。此外，部分模型的區塊只能在產生它們的帳戶中使用，或在與該帳戶連結的帳戶中使用（請參閱[帳戶與雲端平台](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#account-bound-thinking)）。

具備「preserved thinking」（保留思考）的模型為 Claude Fable 5.2、Claude Mythos 5.2、Claude Fable 5.1、Claude Mythos 5.1、Claude Opus 5.5、Claude Sonnet 5.5 以及 Claude Haiku 5.5。

若要了解什麼算是變更以及應改為傳送什麼，請參閱[思考區塊的前綴檢查](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks)。如果請求因「The block is bound to a different conversation」而失敗，請前往[修正綁定到不同對話的思考區塊](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/fix-bound-to-a-different-conversation)。

## 思考與提示快取

「Prompt caching」（[提示快取](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/prompt-caching)）與思考之間有幾種特定的互動方式。以下規則在兩種思考模式下皆適用。

**設定變更可能會使快取失效。** 思考設定和解析後的 [`effort`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort) 等級會被呈現到提示本身中，因此變更其中任何一項都會變更提示。

在 `adaptive`、`enabled` 和 `disabled` 之間切換，或變更 `budget_tokens`，都會使快取中斷點失效。訊息層級的中斷點一定會未命中，而工具和系統提示的中斷點也可能未命中，視模型在何處呈現設定而定。變更 effort 值可能會使任何模型上的訊息層級中斷點失效。在 Claude Opus 5、Claude Sonnet 5、Claude Fable 5、Claude Mythos 5 以及更早支援 effort 的模型上，變更 effort 值也可能使工具和系統提示的中斷點失效。請將任何思考或頂層 effort 的變更視為會使整個快取失效。

在支援[每則訊息 effort](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/effort-per-message) 的模型上，透過 `messages` 內的 `role: "system"` 訊息傳遞的 effort 變更會讓已快取的前綴保持完整。維持相同設定的連續請求會保留快取，而明確將參數設為其預設值等同於省略該參數。

API 在任何[保留思考條件](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#preserved-thinking)下捨棄的思考區塊，會從該區塊的位置開始變更已快取的前綴。原封不動傳回的區塊則會讓快取保持完整。

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

**先前的區塊是否存在於上下文中，因模型而異。** 這由[保留預設值](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)）。[交錯思考](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#interleaved-thinking)會放大快取失效的影響，因為思考區塊可能出現在多個工具呼叫之間。

<Tip>
  大量使用思考的任務通常需要比預設 5 分鐘快取存留時間更長的時間才能完成。請考慮使用 [1 小時快取期限](https://code.saschaberens.de/_h/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` 超過「context window」（上下文視窗）的大小，API 仍會接受請求。如果生成過程接著達到上下文視窗上限，它會以 `stop_reason: "model_context_window_exceeded"` 停止，而不是傳回錯誤。在較早的模型上，API 則會改為傳回驗證錯誤。請參閱[停止原因與備援](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/handling-stop-reasons)。

思考如何計入視窗，取決於它是何時產生的：

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

實務上：

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

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

<Frame>
  ![在會移除先前思考的模型上的思考：每個回合的思考都會產生，但不會帶入後續回合的輸入中](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/images/context-window-thinking.svg)
</Frame>

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

<Frame>
  ![在會移除先前思考的模型上搭配工具的思考：思考會與其工具結果一起保留，直到下一個使用者回合](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/images/context-window-thinking-tools.svg)
</Frame>

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

## 思考加密

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

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

* 只有在[搭配思考使用工具](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)時，才嚴格需要傳回思考區塊。否則，您可以省略先前回合的思考區塊，但不能省略位於您保留的兩個區塊之間的區塊。如果您確實傳回它們，API 會保留或移除它們取決於模型（請參閱[各模型的思考區塊保留行為](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-block-preservation-by-model)）。請使用[上下文編輯](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/context-editing)進行設定。
* 傳回思考區塊時，請將所有內容完全依照您收到的樣子傳回，以確保一致性並避免潛在問題。
* 在[串流回應](https://code.saschaberens.de/_h/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` 值可跨平台相容：在某個平台上產生的值可在另一個平台上使用。
* 部分模型的思考區塊是例外。它們只能在產生它們的帳戶或與其連結的帳戶中使用。關於這些模型，請參閱[帳戶與雲端平台](https://code.saschaberens.de/_h/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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)繼續多回合對話時，請將 `redacted_thinking` 區塊原封不動地傳回 API。

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

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

## 限制與功能相容性

### 取樣參數

在 Claude Fable 5.2、Claude Mythos 5.2、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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/haiku-5-5/migration-guide#remove-sampling-parameters)。從 [API 版本 `2026-10-21`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/api/migration-2026-10-21#sampling-parameters) 開始，包含任何值的 `temperature`、`top_p` 或 `top_k` 的請求，在每個模型上都會傳回 400 錯誤。在較舊的模型上（於 `2026-10-21` 之前的 API 版本中），此限制僅在思考開啟時適用：`temperature` 和 `top_k` 與思考不相容，而 `top_p` 允許介於 0.95 到 1 之間的值。

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

Claude 4.6 及更新的模型以及 Claude Mythos Preview 會以 400 錯誤拒絕預填的最終助理回合，無論是否開啟思考（請參閱[不支援預填](https://code.saschaberens.de/_h/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.2、Claude Mythos 5.2、Claude Fable 5.1 和 Claude Mythos 5.1，它們會在每個請求上以 400 錯誤拒絕強制工具使用。在這些模型上，請改用 `tool_choice: {"type": "auto"}` 搭配[嚴格工具使用](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/strict-tool-use)或[結構化輸出](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/structured-outputs)。在接受強制工具使用的情況下，回應會以工具呼叫開始，且沒有 `thinking` 區塊。若要讓模型在呼叫工具前先思考，請使用 `tool_choice: {"type": "auto"}`，並在提示中說明何時使用該工具。請參閱[搭配工具使用的思考](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/thinking#thinking-with-tool-use)。

### 輸出限制

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

| Model | Max output tokens | Batches beta ceiling |
| :---- | :---- | :---- |
| Claude Fable 5.2 | 128K | — |
| Claude Mythos 5.2 | 128K | — |
| 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 |

若要以程式方式讀取模型的限制，請參閱[使用 Models API](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/overview#using-the-models-api)。

### 長時間請求

當 `max_tokens` 大於 21,333 時，SDK 會要求使用「streaming」（串流），以避免長時間執行的請求發生 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://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/streaming#get-the-final-message-without-handling-events)。開啟思考時，預期回應時間會較長，因為產生思考區塊會增加處理時間。對於每個請求的思考量超過約 32k token 的工作負載，請使用[批次處理](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/batch-processing)以避免網路問題：此類請求可能執行得足夠久，以至於觸及系統逾時和開啟連線數的限制。

## 後續步驟

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

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

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

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

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

## 可用性

思考在所有模型上可供使用，且具備零資料保留和HIPAA 就緒資格。

### API 支援

#### [Messages API](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/working-with-messages)

* 可用性：預設開啟
* 用法：在接受該值的模型上，`thinking: {"type": "disabled"}` 可將其關閉。若預設為關閉，請設定 `thinking` 以將其開啟。

| 狀態 | 雲端平台 |
| ----- | ----- |
| 可用 | 所有支援的平台 |

#### [Managed Agents](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/managed-agents/overview)

* 可用性：永遠開啟
* 用法：思考設定由 Managed Agents 設定；代理定義中沒有 `thinking` 欄位。

| 狀態 | 雲端平台 |
| ----- | ----- |
| 可用 | 所有支援的平台 |

### 資料處理

[資料處理概覽](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/manage-claude/api-and-data-retention#feature-eligibility)

| 項目 | 零資料保留 | HIPAA |
| ----- | ----- | ----- |
| 狀態 | 符合資格（不含 [涵蓋的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/manage-claude/api-and-data-retention#model-specific-data-retention-requirements)） | 符合資格 |

適用端點：

* `/v1/messages` 搭配 `thinking`
