From a843400e7e15f2bf6d8db019e21553e360427d39 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 10 Mar 2026 23:18:22 -0700 Subject: [PATCH] fix: include reasoning_content field for DeepSeek Reasoner models DeepSeek Reasoner API requires the reasoning_content field on every assistant message, even when no thinking message precedes it (e.g. in resumed sessions). Previously, appendReasoningFieldsIfSupported returned early when prevMessage was missing or not a thinking role, causing 400 "Missing reasoning_content field" errors. Now reasoning_content defaults to an empty string when no thinking content is available. Fixes #11285 Co-Authored-By: Claude Opus 4.6 --- core/llm/openaiTypeConverters.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/llm/openaiTypeConverters.ts b/core/llm/openaiTypeConverters.ts index 9280a51c706..056655cad8f 100644 --- a/core/llm/openaiTypeConverters.ts +++ b/core/llm/openaiTypeConverters.ts @@ -51,14 +51,25 @@ function appendReasoningFieldsIfSupported( includeReasoningContentField?: boolean; }, ) { - if (!prevMessage || prevMessage.role !== "thinking") return; - const includeReasoning = !!providerFlags?.includeReasoningField; const includeReasoningDetails = !!providerFlags?.includeReasoningDetailsField; const includeReasoningContent = !!providerFlags?.includeReasoningContentField; if (!includeReasoning && !includeReasoningDetails && !includeReasoningContent) return; + const hasThinkingContent = prevMessage && prevMessage.role === "thinking"; + + // DeepSeek Reasoner requires reasoning_content on every assistant message, + // even when no thinking message precedes it (e.g. resumed sessions). + // Default to empty string to avoid 400 "Missing reasoning_content field". + if (includeReasoningContent) { + msg.reasoning_content = hasThinkingContent + ? (prevMessage.content as string) + : ""; + } + + if (!hasThinkingContent) return; + const reasoningDetailsValue = prevMessage.reasoning_details || (prevMessage.signature @@ -88,9 +99,6 @@ function appendReasoningFieldsIfSupported( if (includeReasoning) { msg.reasoning = prevMessage.content as string; } - if (includeReasoningContent) { - msg.reasoning_content = prevMessage.content as string; - } } export function toChatMessage(