You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: DeepSeek reasoning_content not passed back in multi-turn conversations #24261
Bug: DeepSeek reasoning_content not passed back in multi-turn conversations
Affected provider: DeepSeek (via OpenRouter or DeepSeek API directly) Affected models: DeepSeek V4 Pro (and any DeepSeek model with thinking mode enabled)
Description
When using a DeepSeek model with thinking mode enabled, the API requires that reasoning_content blocks returned in assistant messages are passed back as-is in subsequent turns. OpenCode currently does not preserve these blocks when building the conversation history, causing the following error on the second message:
[DeepSeek] The `reasoning_content` in the thinking mode must be passed back to the API.
Steps to Reproduce
Configure OpenCode with DeepSeek V4 Pro via OpenRouter (openrouter/deepseek/deepseek-v4-pro) or DeepSeek API directly
Enable thinking mode (or use a model where it is on by default)
Send a first message — response succeeds
Send a second message in the same session
Error is thrown immediately
Expected Behavior
OpenCode should preserve the reasoning_content block from assistant messages and include it verbatim when building the messages array for subsequent API calls.
Expected assistant message format in history:
{
"role": "assistant",
"content": [
{
"type": "reasoning_content",
"reasoning_content": "<content returned by the model>"
},
{
"type": "text",
"text": "<actual response>"
}
]
}
Actual Behavior
The reasoning_content block is stripped from the assistant message before the next API call, causing DeepSeek to reject the request.
In trying out deepseek v4, I was originally getting nonspecific AI_APICallError(s) when adding queries after the first response... In researching it here, I then saw multiple reports of outstanding errors along these lines (such as the above), but then saw that opencode 1.14.24 claimed to fix such... after downloading it, I was able to submit a ~handful of queries before it again is now responding " Bad Request: {"error":{"message":"The content[].thinking in the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code": "invalid_request_error"}}"...
[FWIW, I think that my 'provider' for deepseek v4 is configured to use the claude api, as their web site currently recommends...]
This is not an isolated issue — it's a systemic compatibility problem affecting multiple open-source projects using DeepSeek V4 thinking mode + tool calls. Same root cause, same error across all of them.
Root cause: AI SDKs (@ai-sdk/openai-compatible, OpenRouter gateway) don't preserve reasoning_content on assistant messages with tool_calls across turns. DeepSeek V4 thinking mode requires it on every assistant message after a tool call — including empty strings.
Fix direction (verified across projects): Unconditionally inject reasoning_content: "" for all assistant messages before API dispatch. Our fork (fkyah3/opencode-fkyah3, commit b5b6ad05d) implements this at the normalizeMessages() level. OpenClaw implemented a similar approach in #71105.
This is not a config issue on your side — you don't need to switch providers or models.
Sorry for delay yall, was traveling but have a PR that I validated should behave as expected w/ openrouter now, contains a small code change and a bump to openrouter sdk package that we use, I talked w/ openrouter team and they made this patch specifically due to us raising the issue.
?? 'DeepSeek API directly' as shown in issue title. In my "~/.config/opencode/opencode.json" (before the build reportedly may now include it?), I had added:
Activity
github-actions commentedon Apr 25, 2026
This issue might be a duplicate of existing issues. Please check:
reasoning_contentnot round-tripped on multi-turn conversations with DeepSeek V4, same error message, same root cause, already assigned and being worked on.Please add a "+1" or your additional context to the existing issue instead.
hanfengcan commentedon Apr 25, 2026
+1
DXXS commentedon Apr 25, 2026
In trying out deepseek v4, I was originally getting nonspecific AI_APICallError(s) when adding queries after the first response... In researching it here, I then saw multiple reports of outstanding errors along these lines (such as the above), but then saw that opencode 1.14.24 claimed to fix such... after downloading it, I was able to submit a ~handful of queries before it again is now responding " Bad Request: {"error":{"message":"The
content[].thinkingin the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code": "invalid_request_error"}}"...[FWIW, I think that my 'provider' for deepseek v4 is configured to use the claude api, as their web site currently recommends...]
5918vo commentedon Apr 25, 2026
same issue
ronald2wing commentedon Apr 25, 2026
+1
fkyah3 commentedon Apr 25, 2026
This is not an isolated issue — it's a systemic compatibility problem affecting multiple open-source projects using DeepSeek V4 thinking mode + tool calls. Same root cause, same error across all of them.
Known affected projects (as of April 26):
Root cause: AI SDKs (@ai-sdk/openai-compatible, OpenRouter gateway) don't preserve reasoning_content on assistant messages with tool_calls across turns. DeepSeek V4 thinking mode requires it on every assistant message after a tool call — including empty strings.
Fix direction (verified across projects): Unconditionally inject reasoning_content: "" for all assistant messages before API dispatch. Our fork (fkyah3/opencode-fkyah3, commit b5b6ad05d) implements this at the normalizeMessages() level. OpenClaw implemented a similar approach in #71105.
This is not a config issue on your side — you don't need to switch providers or models.
rekram1-node commentedon Apr 26, 2026
Sorry for delay yall, was traveling but have a PR that I validated should behave as expected w/ openrouter now, contains a small code change and a bump to openrouter sdk package that we use, I talked w/ openrouter team and they made this patch specifically due to us raising the issue.
Will release soon
DXXS commentedon Apr 29, 2026
I have no idea why this has been marked 'closed' as it still appears to be happening in 1.14.29 said to have been built yesterday
fkyah3 commentedon Apr 29, 2026
rekram1-node commentedon Apr 29, 2026
@DXXS tell me more info please, what provider are you using? Is it openrouter? If it's not openrouter then maybe open a new issue?
Is it a custom provider?
DXXS commentedon Apr 30, 2026
?? 'DeepSeek API directly' as shown in issue title. In my "~/.config/opencode/opencode.json" (before the build reportedly may now include it?), I had added: