DeepSeek thinking mode 报错处理:`content[].thinking` Must Be Passed Back to the API

7 阅读1分钟

如果你在恢复或继续 Claude Code / coding agent 对话时遇到这个报错:

API Error: 400 {"error":{"message":"The `content[].thinking` in the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

这个问题更常见于 Claude Code、OpenCode、Cursor,或者其他会重放历史工具调用链的 Agent 工具里。常见原因是:请求里还带着旧的工具调用上下文,但对应的 thinking 内容没有一起传回去。DeepSeek 的 thinking 模式对工具调用链的连续性要求更严格。

通用处理思路是:不要再把旧的 thinking / tool-call 结构块当成可续接状态传给模型;把有用的上下文转成普通文本,让模型从清洗后的文本上下文继续。

可以按这个思路清洗历史:

遍历 history 里的每条 message:
  遍历 message.content 里的每个 block:
    如果 block.type 是 "thinking" 或 "redacted_thinking":
      删除这个 block

    如果 block.type 是旧的工具调用 / 媒体 / provider 特有结构:
      替换成普通文本:
        {
          "type": "text",
          "text": "[sanitized <block.type> block]\n" + JSON.stringify(block)
        }

    其他 block:
      原样保留

  如果 message.content 变空:
    删除这条 message,或者替换成一条简短的文本占位

实际处理时,可以重点把旧的 tool_usetool_result、MCP 工具块、web search 结果、code execution 结果、图片、文档,以及其他 provider 特有 content block 转成普通文本。

如果你使用 cc-usecc-use@0.2.3 已经按这个思路实现了 Claude Code 历史导入清洗:

cc-use import-history deepseek --all --sanitize

只处理当前项目的话:

cc-use import-history deepseek --sanitize

这个操作只会修改 ~/.cc-use/sessions/<profile>/ 下的导入副本,不会改你的原始 ~/.claude/ 历史。