频繁出现 Warn Anthropic API error (HTTP 400 Bad Request invalid_request_error): 'type' must be in ["enabled", "disabled", "auto"]
现象
使用 providers.openmodel(兼容 Anthropic Messages API)时,频繁收到以下错误:
Warn Anthropic API error (HTTP 400 Bad Request invalid_request_error):
'type' must be in ["enabled", "disabled", "auto"]
重试后偶尔能正常通过,但错误反复出现,无固定规律。
重现步骤
- 配置
~/.codewhale/config.toml,使用 OpenModel 作为 Anthropic 兼容 provider:
provider = "openmodel"
[providers.openmodel]
base_url = "https://token.sensenova.cn/v1"
api_key = "sk-..."
model = "deepseek-v4-flash"
- 在 TUI 中确保
reasoning_effort不为off(默认通常是high) - 输入任意问题,触发模型调用
- 观察日志输出,出现 HTTP 400 错误
系统环境
| 项目 | 值 |
|---|---|
| CodeWhale 版本 | v0.9.1(git describe 确认) |
| 操作系统 | Windows 11 10.0.26200 |
| Rust 版本 | rustc 1.96.1 (31fca3adb 2026-06-26) |
| Provider | openmodel(Anthropic Messages 兼容网关) |
| 模型 | 任意支持 reasoning 的模型(如 deepseek-v4-flash) |
当前版本
- Tag:
v0.9.1 - **v0.9.0 ** 原先没有这个问题,升级v0.9.1出现这个问题,但是这次我把版本还原回v0.9.0,还是有这个问题。很奇怪,难道是sensenova的接口变更了吗?
你记得确实没错,090的时候确实可以工作。最近似乎sensenove的网关校验变严格了,之前adaptive还能过,现在多半是它在抽风。Anthropic官方的SDK已经承认adaptive是thinking.type的官方推荐值,enabled被标记为可能在未来废弃(deprecated)。我觉得这个大概是sensenova那边的问题。
You're right. It did work back in v0.9.0. Recently, it seems Sensenova's gateway validation has become stricter; previously adaptive would pass, but now it's most likely just misbehaving. The official Anthropic SDK has acknowledged that adaptive is the recommended value for thinking.type, and enabled has been marked as deprecated and may be removed in the future. I think this is probably an issue on Sensenova's side.
ah - thank you both. I am changing how anthropic urls are selected now but I don't think that will help ..... I have a feeling it's a provider side issue
另外我用 sensenove 的 https://token.sensenova.cn/v1/chat/completions 地址,也不行,返回的内容会误认为工具调用。但是这个接口放在 OpenClaw 里是可以用的,放在CodeWhale里就不正常。 会话内容是这个样子的。 { "schema_version": 1, "metadata": { "id": "c3cd0eec-3581-41a8-b5fa-b8511a8e3056", "title": "看一下 千岛湖旅行规划方案.md", "created_at": "2026-08-03T09:39:58.503881600Z", "updated_at": "2026-08-03T09:39:58.503881600Z", "message_count": 14, "total_tokens": 10572, "model": "deepseek-v4-flash", "model_provider": "openai", "model_provider_id": "openai", "workspace": "F:\wyw\桌面\travel", "mode": "ACT", "cost": { "session_cost_usd": 0.0, "session_cost_cny": 0.0, "subagent_cost_usd": 0.0, "subagent_cost_cny": 0.0, "displayed_cost_high_water_usd": 0.0, "displayed_cost_high_water_cny": 0.0, "priced_turns": 0, "unpriced_turns": 1, "cny_priced_turns": 0, "cny_unpriced_turns": 1, "unpriced_reasons": [ "unknown_billing_basis" ], "cny_unpriced_reasons": [ "unknown_billing_basis" ], "route_receipts": [ "provider=openai identity=openai model=deepseek-v4-flash surface=unclassified endpoint_fp=5601daf2dd128128b3d8385bc4329ecd4143f368668590b108aa927c0a1ec330 billing_mode=unknown currency=unpriced" ], "coverage_recorded": true }, "cumulative_turn_secs": 0 }, "messages": [ { "role": "user", "content": [ { "type": "text", "text": "看一下 千岛湖旅行规划方案.md" }, { "type": "text", "text": "<turn_meta>\nCurrent local date: 2026-08-03\nCurrent workspace: F:\wyw\桌面\travel\nCurrent model: deepseek-v4-flash\nCurrent mode: agent\nCurrent permission posture: Full Access\nInput provenance: external_user\nInput authority: external_current_turn\nContext pressure: low (0.6% used, 6498 / 1000000 tokens; 730334 input tokens available)\n## Repo Working Set\nWorkspace: F:\wyw\桌面\travel\nTop-level dirs: pycache\nWhen in doubt, use tools to verify and keep changes focused on the working set.\nGit workspace: master | 1 modified, 8 untracked\n</turn_meta>" } ] }, { "role": "assistant", "content": [ { "type": "thinking", "thinking": "。" }, { "type": "tool_use", "id": "call_f62e357c94ef4c2d97606d2b", "name": "File", "input": {} }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": {} }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": ""action": "read"" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": ", "path": "F:\\" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "wy" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "w\\" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "桌面\\" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "travel\\" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "千岛" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "湖旅行" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": "规划方案" } }, { "type": "tool_use", "id": "", "name": "unknown_tool", "input": { "raw_arguments": ".md"}" } } ] },
对于sensenova 的 Anthropic 应该是后加的服务对 thinking 做了校验,限制在必须是"enabled", "disabled", "auto"了。 路由到新实例就会报错,路由到旧实例就可以用,这可以解释出错时重试又可以的情况。 因为我是重载了 Openmodel 的,所以在本地直接在 Openmodel 里进行了修改,设置了 thinking ,用起来确实不报错了。
---------------------- crates/tui/src/client/anthropic.rs ----------------------
index 437c289ae..2f37757cb 100644
@@ -130,12 +130,24 @@ impl DeepSeekClient {
&model,
);
let is_deepseek = self.api_provider == ApiProvider::DeepseekAnthropic;
+ let is_openmodel = self.api_provider == ApiProvider::Openmodel;
let effort = request
.reasoning_effort
.as_deref()
.map(|raw| raw.trim().to_ascii_lowercase());
match effort.as_deref() {
_ if is_minimax_provider && !is_minimax => {}
+ _ if is_openmodel && thinking_capable => match effort.as_deref() {
+ Some("off" | "disabled" | "none" | "false") => {
+ body["thinking"] = json!({ "type": "disabled" });
+ }
+ Some(_) => {
+ body["thinking"] = json!({ "type": "enabled" });
+ }
+ None => {
+ body["thinking"] = json!({ "type": "auto" });
+ }
+ },
Some("off" | "disabled" | "none" | "false")
if (is_minimax || is_deepseek) && thinking_capable =>
{
@w1w218 这样看应该是 Sensenova 不兼容 Anthropic 那边推荐的 adaptive 了,毕竟他们声称自己是竞品。
我看了 @Hmbown 的commit 0f76f11代码,他应该已经解决了你的问题。
代码现在会进行判断,对于非 Anthropic 官方网关,不再发送 adaptive 类型,而是发送 Anthropic 官方文档中标准的 {"type":"enabled","budget_tokens":N} 格式。提交中甚至包含了一个名为compat_gateway_sends_enabled_budget_thinking_instead_of_adaptive 的测试,专门用来验证对 Sensenova 这类网关的修复是否有效。
另外,你说的“工具调用”问题也在这个 commit 里被解决了。他给这种消息加了个函数,在请求发送前自动检查并修复这种 tool_use,为其插入一个 tool_result 占位符。
我没太用过 Sensenova 没法给你测。你如果电脑上有 Rust 环境可以去 clone 一下最新的 main 下来编译一下看看你那边能不能跑成功,或者等0.9.4发布也行。
@w1w218, it seems that Sensenova is not compatible with the adaptive type recommended by Anthropic, especially since they claim to be a competitor.
I looked at @Hmbown's commit 0f76f11 and it appears he has already fixed your issue.
The code now checks whether the gateway is non‑Anthropic, and if so, it no longer sends the adaptive type; instead, it sends the standard format {"type":"enabled","budget_tokens":N} as defined in Anthropic's official documentation. The commit even includes a test named compat_gateway_sends_enabled_budget_thinking_instead_of_adaptive specifically designed to verify that the fix works for gateways like Sensenova.
In addition, the “tool call” issue you mentioned is also addressed in this commit. He added a function that automatically checks and repairs such tool_use messages before sending the request, inserting a tool_result placeholder for them.
I haven't used Sensenova much myself, so I can't test it for you. If you have a Rust environment on your computer, you could clone the latest main branch and compile it to see if it works on your side, or you could wait for the 0.9.4 release.
哦,等等,好像还没合并到 main 分支。看来你得再等等。
Oh, wait, it seems it hasn't been merged into the main branch yet. Looks like you’ll have to wait a bit longer.