[GH-ISSUE #70] deepseek-v4-pro使用 web_search 时,tool_choice.type = "tool" 会导致请求失败 #23

Open
opened 2026-10-26 09:43:47 +00:00 by bsakaguchi · 5 comments
Owner

Originally created by @PageGeorge on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/deepseek-ai/awesome-deepseek-agent/issues/70

问题描述

最近在 Claude Code 中使用 DeepSeek V4 Pro 的 web search 时,偶尔会遇到工具调用失败。之前类似用法是可以正常工作的。

我还没有抓到 Claude Code 实际发出的完整请求,所以目前只能推测:失败可能和 Claude Code 在某些情况下传入了 tool_choice.type = "tool" 有关。

为了排查,我使用 DeepSeek Anthropic-compatible API 做了最小复现测试,发现 deepseek-v4-pro + web_search_20250305 在使用 tool_choice.type = "tool" 时会返回 400 错误。

Image

文档描述

DeepSeek 官方文档中对 tool_choice 的支持情况描述如下:

Value Support Status
none Fully Supported
auto Supported (disable_parallel_tool_use is ignored)
any Supported (disable_parallel_tool_use is ignored)
tool Supported (disable_parallel_tool_use is ignored)

文档地址:

https://api-docs.deepseek.com/zh-cn/guides/anthropic_api

复现请求

curl -s https://api.deepseek.com/anthropic/v1/messages \
  -H "x-api-key: sk-xxxx" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 2048,
    "tools": [
      {
        "type": "web_search_20250305",
        "name": "web_search",
        "max_uses": 8
      }
    ],
    "tool_choice": {
      "type": "tool",
      "name": "web_search"
    },
    "messages": [
      {
        "role": "user",
        "content": "今天北京天气怎么样"
      }
    ]
  }'

实际返回

{
  "error": {
    "message": "deepseek-reasoner does not support this tool_choice",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_request_error"
  }
}

这里请求的模型是 deepseek-v4-pro,但错误信息中出现了 deepseek-reasoner,这一点也比较令人困惑。不确定这是否和内部路由或参数校验逻辑有关。

Originally created by @PageGeorge on GitHub (May 6, 2026). Original GitHub issue: https://github.com/deepseek-ai/awesome-deepseek-agent/issues/70 ## 问题描述 最近在 Claude Code 中使用 DeepSeek V4 Pro 的 web search 时,偶尔会遇到工具调用失败。之前类似用法是可以正常工作的。 我还没有抓到 Claude Code 实际发出的完整请求,所以目前只能推测:失败可能和 Claude Code 在某些情况下传入了 `tool_choice.type = "tool"` 有关。 为了排查,我使用 DeepSeek Anthropic-compatible API 做了最小复现测试,发现 `deepseek-v4-pro` + `web_search_20250305` 在使用 `tool_choice.type = "tool"` 时会返回 400 错误。 <img width="1235" height="688" alt="Image" src="https://github.com/user-attachments/assets/133515ab-fc2e-4283-9935-48c032056084" /> ## 文档描述 DeepSeek 官方文档中对 `tool_choice` 的支持情况描述如下: | Value | Support Status | | --- | --- | | `none` | Fully Supported | | `auto` | Supported (`disable_parallel_tool_use` is ignored) | | `any` | Supported (`disable_parallel_tool_use` is ignored) | | `tool` | Supported (`disable_parallel_tool_use` is ignored) | 文档地址: https://api-docs.deepseek.com/zh-cn/guides/anthropic_api ## 复现请求 ```bash curl -s https://api.deepseek.com/anthropic/v1/messages \ -H "x-api-key: sk-xxxx" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "deepseek-v4-pro", "max_tokens": 2048, "tools": [ { "type": "web_search_20250305", "name": "web_search", "max_uses": 8 } ], "tool_choice": { "type": "tool", "name": "web_search" }, "messages": [ { "role": "user", "content": "今天北京天气怎么样" } ] }' ``` ## 实际返回 ```json { "error": { "message": "deepseek-reasoner does not support this tool_choice", "type": "invalid_request_error", "param": null, "code": "invalid_request_error" } } ``` 这里请求的模型是 `deepseek-v4-pro`,但错误信息中出现了 `deepseek-reasoner`,这一点也比较令人困惑。不确定这是否和内部路由或参数校验逻辑有关。
Author
Owner

@Scarlet1ssimo commented on GitHub (May 15, 2026):

有相同问题。也是deepseek-reasoner does not support this tool_choice

<!-- gh-comment-id:4456367874 --> @Scarlet1ssimo commented on GitHub (May 15, 2026): 有相同问题。也是deepseek-reasoner does not support this tool_choice
Author
Owner

@102BFW commented on GitHub (May 17, 2026):

同样的问题,请问是怎么解决的?

<!-- gh-comment-id:4469847119 --> @102BFW commented on GitHub (May 17, 2026): 同样的问题,请问是怎么解决的?
Author
Owner

@PageGeorge commented on GitHub (May 17, 2026):

同样的问题,请问是怎么解决的?

因为这个问题是偶尔会发生,所以我也没什么好的解决方法。最近都是正常的。如果想要解决的话,或许自己部署SearXNG这样的服务,或者是使用Tavily这样的服务,会是一个选择。

<!-- gh-comment-id:4470177179 --> @PageGeorge commented on GitHub (May 17, 2026): > 同样的问题,请问是怎么解决的? 因为这个问题是偶尔会发生,所以我也没什么好的解决方法。最近都是正常的。如果想要解决的话,或许自己部署SearXNG这样的服务,或者是使用Tavily这样的服务,会是一个选择。
Author
Owner

@PageGeorge commented on GitHub (May 17, 2026):

有相同问题。也是deepseek-reasoner does not support this tool_choice

感觉是官方的问题。只能期待官方能够看到这条issue,然后修复吧。

<!-- gh-comment-id:4470182181 --> @PageGeorge commented on GitHub (May 17, 2026): > 有相同问题。也是deepseek-reasoner does not support this tool_choice 感觉是官方的问题。只能期待官方能够看到这条issue,然后修复吧。
Author
Owner

@tianhao8687 commented on GitHub (Aug 17, 2026):

这个最小复现很有价值:当前官方 Anthropic 兼容表仍声明 tool_choice.type = "tool" 受支持,因此该行为更像是“强制选择内置 web_search”这一分支的服务端兼容缺陷,而不是请求格式写错。错误里出现旧的 deepseek-reasoner 名称,也可能说明请求进入了旧的校验路径,但仅凭报错还不能确定内部路由。

现阶段可用的规避方式:

  1. 能控制请求时,把内置 Web Search 的 tool_choice 改为 auto 或 any;
  2. 需要“必须搜索”时,用普通自定义工具/MCP 包一层搜索服务,再让模型强制调用普通工具;
  3. Claude Code 内部生成请求、无法直接修改时,可在本地适配层中仅针对 name = "web_search" 把 type = "tool" 改为 auto,不要全局删除所有 tool_choice。

若再次出现,建议补充响应头中的 request ID、UTC 时间、实际模型名和去除密钥后的完整 JSON;这些信息能让官方区分偶发路由问题与稳定的参数校验问题。

<!-- gh-comment-id:5317547943 --> @tianhao8687 commented on GitHub (Aug 17, 2026): 这个最小复现很有价值:当前[官方 Anthropic 兼容表](https://api-docs.deepseek.com/zh-cn/guides/anthropic_api)仍声明 `tool_choice.type = "tool"` 受支持,因此该行为更像是“强制选择内置 `web_search`”这一分支的服务端兼容缺陷,而不是请求格式写错。错误里出现旧的 `deepseek-reasoner` 名称,也可能说明请求进入了旧的校验路径,但仅凭报错还不能确定内部路由。 现阶段可用的规避方式: 1. 能控制请求时,把内置 Web Search 的 `tool_choice` 改为 `auto` 或 `any`; 2. 需要“必须搜索”时,用普通自定义工具/MCP 包一层搜索服务,再让模型强制调用普通工具; 3. Claude Code 内部生成请求、无法直接修改时,可在本地适配层中仅针对 `name = "web_search"` 把 `type = "tool"` 改为 `auto`,不要全局删除所有 `tool_choice`。 若再次出现,建议补充响应头中的 request ID、UTC 时间、实际模型名和去除密钥后的完整 JSON;这些信息能让官方区分偶发路由问题与稳定的参数校验问题。
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/awesome-deepseek-agent#23
No description provided.