English
中文
English

Building with extended thinking

中文

使用 Extended Thinking 建構

English

Extended thinking gives Claude enhanced reasoning capabilities for complex tasks, while providing varying levels of transparency into its step-by-step thought process.

中文

Extended thinking 為 Claude 提供增強的推理能力來處理複雜任務,同時對其逐步思考過程提供不同程度的透明度。

English

Supported models

中文

支援的模型

English
  • Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
  • Claude Sonnet 4 (claude-sonnet-4-20250514)
  • Claude Haiku 4.5 (claude-haiku-4-5-20251001)
  • Claude Opus 4.5 (claude-opus-4-5-20251101)
  • Claude Opus 4.1 (claude-opus-4-1-20250805)
  • Claude Opus 4 (claude-opus-4-20250514)
中文
  • Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
  • Claude Sonnet 4 (claude-sonnet-4-20250514)
  • Claude Haiku 4.5 (claude-haiku-4-5-20251001)
  • Claude Opus 4.5 (claude-opus-4-5-20251101)
  • Claude Opus 4.1 (claude-opus-4-1-20250805)
  • Claude Opus 4 (claude-opus-4-20250514)
English

How extended thinking works

中文

Extended thinking 如何運作

English

When extended thinking is turned on, Claude creates thinking content blocks where it outputs its internal reasoning. Claude incorporates insights from this reasoning before crafting a final response.

中文

當啟用 extended thinking 時,Claude 會建立 thinking 內容區塊來輸出其內部推理。Claude 會在生成最終回應之前納入這些推理的見解。

English

How to use extended thinking

中文

如何使用 extended thinking

English

Add a thinking object with type set to enabled and budget_tokens to a specified token budget. The budget_tokens parameter determines the maximum number of tokens Claude is allowed to use for its internal reasoning.

中文

新增一個 thinking 物件,將 type 設為 enabled,並將 budget_tokens 設為指定的 token 預算。budget_tokens 參數決定 Claude 可以用於內部推理的最大 token 數。

python
import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{
        "role": "user",
        "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?"
    }]
)
English

Summarized thinking

中文

摘要思考

English

With extended thinking enabled, the Messages API for Claude 4 models returns a summary of Claude's full thinking process. You're charged for the full thinking tokens, not the summary tokens.

中文

啟用 extended thinking 後,Claude 4 模型的 Messages API 會回傳 Claude 完整思考過程的摘要。你需要支付完整思考 token 的費用,而不是摘要 token。

English

Extended thinking with tool use

中文

Extended thinking 與工具使用

English

Extended thinking can be used alongside tool use. During tool use, you must pass thinking blocks back to the API. Include the complete unmodified block to maintain reasoning continuity.

中文

Extended thinking 可以與工具使用一起使用。在工具使用期間,你必須將 thinking 區塊傳回 API。包含完整未修改的區塊以維持推理連續性。

English

Best practices

中文

最佳實踐

English
  • Start with larger thinking budgets (16k+ tokens) for complex tasks.
  • Use batch processing for thinking budgets above 32k to avoid networking issues.
  • Monitor thinking token usage to optimize costs and performance.
  • Use extended thinking for complex tasks like math, coding, and analysis.
中文
  • 對於複雜任務,從較大的思考預算(16k+ token)開始。
  • 對於超過 32k 的思考預算,使用批次處理以避免網路問題。
  • 監控思考 token 使用量以優化成本和效能。
  • 對於數學、程式設計和分析等複雜任務使用 extended thinking。