Skip to content

DeepSeek Anthropic API 路径下 thinking 块被丢弃导致请求失败 #136

@grayfalcon666

Description

@grayfalcon666

环境

  • 系统:Fedora Linux 43 (KDE Plasma Desktop Edition), x86_64
  • .NET: 10.0
  • Chats.BE 版本:1.11.0
  • 模型:DeepSeek v4 Pro
  • API 路径:Anthropic Messages (/v1/messages)
  • Thinking 模式:已启用(budget_tokens: 31999

问题

通过 Anthropic Messages API 路径接入 DeepSeek v4 Pro,开启 thinking 模式后,当对话历史中存在同时包含 thinking 块和 tool_use 块的助手消息时,请求失败:

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

根因

AnthropicChatService.ConvertMessages() 硬编码了只有 WebChat 来源才保留 thinking 块:

bool reallyAllowThinkingBlocks = allowThinkingBlocks && source == UsageSource.WebChat;

非 WebChat 来源(如 Claude Code API 调用)下,NeutralThinkContent 被全部丢弃,导致 DeepSeek 收到缺少 thinking 块的请求而报错。

关键文件

  • Services/Models/ChatServices/Anthropic/AnthropicChatService.csConvertMessages() 第567行
  • Services/Models/ChatServices/Anthropic/DeepSeekAnthropicService.cs — 仅重写 GetEndpointAndKey()

复现步骤

  1. 配置 DeepSeek v4 Pro,DBApiType: AnthropicMessagesDBModelProvider: DeepSeek
  2. 开启 thinking(设置 ThinkingBudget
  3. 通过 /v1/messages 发送多轮对话,前一轮助手消息包含 thinking + tool_use
  4. DeepSeek 返回上述错误

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions