外观
Claude深度思考
深度思考为Claude提供了增强的推理能力,用于处理复杂任务,同时在提供最终答案之前,以不同程度的透明度展示其逐步思考过程。
支持的模型 深度思考在以下模型中受支持:
Claude Opus 4 (claude-opus-4-20250514) Claude Sonnet 4 (claude-sonnet-4-20250514) Claude Sonnet 3.7 (claude-3-7-sonnet-20250219)
深度思考的工作原理
当启用深度思考时,Claude会创建thinking内容块,在其中输出其内部推理过程。Claude在制定最终回应之前,会整合这些推理中的见解。
API响应将包含thinking内容块,随后是text内容块。
以下是默认响应格式的示例:
js
{
"content": [
{
"type": "thinking",
"thinking": "让我逐步分析一下...",
"signature": "WaUjzkypQ2mUEVM36O2TxuC06KN8xyfbJwyem2dw3URve/op91XWHOEBLLqIOMfFG/UvLEczmEsUjavL...."
},
{
"type": "text",
"text": "基于我的分析..."
}
]
}如何使用深度思考
以下是在消息API中使用深度思考的示例:
js
curl https://mishu.one/anthropic/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data \
'{
"model": "claude-3-7-sonnet-20250219",
"max_tokens": 1600,
"thinking": {
"type": "enabled",
"budget_tokens": 1024
},
"messages": [
{
"role": "user",
"content": "Hello, world"
}
]
}'要启用深度思考,请添加一个thinking对象,将thinking参数设置为enabled,并将budget_tokens设置为指定的深度思考令牌预算。
budget_tokens参数确定了Claude在内部推理过程中允许使用的最大令牌数量。在Claude 4模型中,此限制适用于完整思考令牌,而不是摘要输出。更大的预算可以通过为复杂问题启用更全面的分析来提高响应质量,尽管Claude可能不会使用分配的整个预算,特别是在超过32k的范围内。
budget_tokens必须设置为小于max_tokens的值。但是,当使用工具的交错思考时,您可以超过此限制,因为令牌限制变为您的整个上下文窗口(200k令牌)。 返回示例:
js
{
"id": "msg_01WDr8tS3qFLr6ynZxcLtfkX",
"type": "message",
"role": "assistant",
"model": "claude-3-7-sonnet-20250219",
"content": [
{
"type": "thinking",
"thinking": "The user has sent a simple \"Hello, world\" message, which is a common first greeting or test message. This is often used as the first program people write when learning a new programming language, but here it's just being used as a greeting.\n\nI should respond with a friendly greeting and perhaps indicate my readiness to assist with whatever they might need.",
"signature": "ErUBCkYIBBgCIkAFZawd/fZNLEeoI82a/lO4OqoZ9MjgNWOoj/deBqL2j2asb2vQW+1NPjgBaNjEzGu7mXRCmzTlrAoz/zdoJ+wdEgy3XrZeI66CzJwTGkMaDPZCb8P51389U6JlwCIwVv1tZE13Oo5dofBvjbX9Gjf2Mpl3lcRFZHgm/M9HY4Fw+tEDaU2MDpKFn3ecgPoJKh3Xqmj0/1dDo8Q+yLetQUT719lxNuSuQBU0dFrvzBgC"
},
{
"type": "text",
"text": "Hello! It's nice to meet you. I'm an AI assistant ready to help with information, answer questions, or just chat. How are you doing today, and is there something specific I can help you with?"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 38,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 129,
"service_tier": "standard"
}
}