deepseek-ai / deepseek-ai/awesome-deepseek-agent
deepseek-v4-pro使用 web_search 时,tool_choice.type = "tool" 会导致请求失败
- Dominant language
- No language data
- Stars
- 6.1k
- Forks
- 724
- PR merge metrics
- No merged PRs in 30d
Description
## 问题描述
最近在 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 错误。
## 文档描述
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`,这一点也比较令人困惑。不确定这是否和内部路由或参数校验逻辑有关。
Contributor guide
Assessment
This issue has not been assessed yet.