Skip to content

400 error: reasoning_content must be passed back for DeepSeek-family models on direct OpenAI-compatible endpoints #815

Closed

Description

@Timmy6942025

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-free on 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

Activity

  1. Timmy6942025 commented on Aug 5, 2026

    @Timmy6942025
    Author

    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 = true on 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 made pub(crate))

    Reference PR body (in case PR creation becomes possible): master...Timmy6942025:fix/deepseek-reasoning-content-passback

  2. added
    bug
    triage: reproducible
    autonomous: likely
    on Aug 6, 2026
  3. iwanro commented on Aug 6, 2026

    @iwanro

    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.

  4. 1jehuang commented on Aug 9, 2026

    @1jehuang
    Owner

    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

  5. added a commit that references this issue on Aug 10, 2026
    9b62569
  6. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  7. added 5 commits that reference this issue on Aug 30, 2026
    bdc74b8
    a8e05a5
    58e498f
    3d1f9cc
    8ac4915
  8. added a commit that references this issue on Sep 18, 2026
    c1442cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: likelybugtriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions