400 error: `reasoning_content` must be passed back for DeepSeek-family models on direct OpenAI-compatible endpoints
Problem
Multi-turn sessions against DeepSeek-family models served by direct OpenAI-compatible profiles (no OpenRouter provider features — e.g. OpenCode Zen, opencode.ai/zen/v1) fail on the second request with:
400 The `reasoning_content` in the thinking mode must be passed back to the API.
The endpoint runs server-managed thinking mode and requires the assistant reasoning_content to be replayed on follow-up requests. jcode stores it (stores_reasoning_content_for_context) but drops it at request-build time for these profiles, because reasoning passback is only unlocked when OpenRouter provider features are enabled or the endpoint is the Kimi coding endpoint (#322).
Repro
- Any model in the DeepSeek family (e.g.
deepseek-v4-flash-freeon OpenCode Zen) via a direct OpenAI-compatible profile - Start a session, let the model emit a tool call (which carries a stored reasoning block), then send a follow-up request
- 400 error above
Workaround (verified): set allow_provider_pinning = true on the named profile so provider features are treated as enabled, which unlocks the reasoning passback path.
Related
- #322 — same mechanism for the Kimi coding endpoint (fixed)
- #321, #341 — neighboring DeepSeek/Kimi thinking-mode 400s
Ready-to-apply patch (verified against master 02439b4, fully tested). The change is on branch fix/deepseek-reasoning-content-passback in fork Timmy6942025/jcode (commit 4e9f6c9) — a PR couldn't be opened from this account due to a GitHub-side permission flag on PR creation, so here's everything in one place.
Production change
crates/jcode-provider-openrouter-runtime/src/openrouter_provider_impl.rs, in complete():
@@ -53,6 +53,18 @@
// `thinking` field (the endpoint already manages thinking itself), so
// this is kept separate from `thinking_enabled`.
let kimi_coding_endpoint = self.is_kimi_coding_endpoint(&model);
+ // DeepSeek-family models served through direct OpenAI-compatible
+ // endpoints (e.g. OpenCode Zen) run in server-managed thinking mode and
+ // require `reasoning_content` to be passed back on assistant messages in
+ // multi-turn requests; DeepSeek's API docs mandate it and the endpoint
+ // enforces it with a 400 "The `reasoning_content` in the thinking mode
+ // must be passed back to the API." error. Those profiles carry no
+ // OpenRouter provider features, so unlock reasoning passback by model
+ // family instead. Like the Kimi coding endpoint, this must NOT add the
+ // OpenRouter-specific top-level `thinking` field (the endpoint manages
+ // thinking itself), so it stays separate from `thinking_enabled`.
+ let deepseek_thinking_endpoint =
+ !self.supports_provider_features && Self::model_is_deepseek_family(&model);
let thinking_enabled = thinking_override.or_else(|| {
if Self::is_kimi_model(&model) {
Some(true)
@@ -60,8 +72,9 @@
None
}
});
- let allow_reasoning = (self.supports_provider_features || kimi_coding_endpoint)
- && thinking_enabled != Some(false);
+ let allow_reasoning =
+ (self.supports_provider_features || kimi_coding_endpoint || deepseek_thinking_endpoint)
+ && thinking_enabled != Some(false);
let include_reasoning_content = thinking_enabled == Some(true)
|| (allow_reasoning && Self::is_kimi_model(&model))
|| kimi_coding_endpoint;
This mirrors the existing Kimi coding-endpoint handling (#322) and deliberately does not add the OpenRouter-specific top-level thinking field — the endpoint manages thinking itself.
Regression test
crates/jcode-provider-openrouter-runtime/src/openrouter_deepseek_tests.rs (new file, registered as mod openrouter_deepseek_tests in lib.rs): deepseek_direct_compat_tool_call_message_replays_stored_reasoning_content — builds an OpenCode-Zen-style direct profile (supports_provider_features: false), replays a multi-turn conversation whose assistant tool-call turn carries a stored reasoning block, and asserts the outgoing request replays reasoning_content on the assistant message.
Verification
cargo test -p jcode-provider-openrouter-runtime: 113 passed, 0 failed (regression test included)cargo fmt --all -- --check: clean- Clippy: no new diagnostics from changed files
- Test/other ratchets: no new violations vs master
- Live-verified end-to-end: multi-turn tool loop against OpenCode Zen works with the fix (also reproducible via config workaround
allow_provider_pinning = trueon the named profile)
Files
crates/jcode-provider-openrouter-runtime/src/openrouter_provider_impl.rs(+13)crates/jcode-provider-openrouter-runtime/src/openrouter_deepseek_tests.rs(+112, new)crates/jcode-provider-openrouter-runtime/src/lib.rs(+4, test-module registration)crates/jcode-provider-openrouter-runtime/src/openrouter_tests.rs(±0 net: 3 helpers madepub(crate))
Reference PR body (in case PR creation becomes possible): https://github.com/1jehuang/jcode/compare/master...Timmy6942025:fix/deepseek-reasoning-content-passback
Confirmed independently, with one important detail for anyone applying the workaround.
Problem reproduction: using deepseek-v4-flash-free (and other DeepSeek-family models) via OpenCode Zen (https://opencode.ai/zen/v1) in a multi-turn session, the first 1-2 exchanges succeed, then the request hits the strict "Console" upstream backend and fails with 400 The reasoning_content in the thinking mode must be passed back to the API. I also confirmed in the log that the failing provider instance had provider_features=false (reasoning passback gated off), matching this issue's root cause.
Workaround works, but only with a NON-builtin profile name. I first tried [providers.opencode] (shadowing the built-in profile), but it is silently ignored: in resolve_config_provider_selection (crates/jcode-base/src/provider/selection.rs) the built-in catalog lookup for opencode runs before the config.providers.contains_key check, so the runtime is always built from the catalog with supports_provider_features=false hardcoded (new_openai_compatible_profile_runtime).
Using a profile name that is NOT in the built-in catalog (e.g. [providers.opencode-zen]) with allow_provider_pinning = true works: the runtime is then built via new_named_openai_compatible, provider_features becomes true, and multi-turn tool-call sessions stop 400ing. Verified end-to-end with a tool-call loop (both requests in the turn carried provider_features=true, no 400).
The proper fix in the proposed patch (unlock reasoning passback for DeepSeek-family models on direct OpenAI-compatible endpoints, without adding the OpenRouter thinking field) is the right direction and would remove the need for this workaround. Hoping it lands in an update.
🔥🧪🔥 消费失败进死信后怎么人工修
失败重试有没有指数退避 🧪📦
协议选型理由能展开说说吗 📌🧠🔥
Implemented an independent fix in PR #863. DeepSeek reasoning passback is now explicitly scoped to direct OpenAI-compatible routes, without enabling OpenRouter-only request behavior. The focused regression and full affected crate suite pass (115 passed, 1 ignored).
--- — Jcode agent (automated triage), on behalf of @1jehuang