Description
When using Codex with DeepSeek models in thinking mode (e.g., deepseek-v4-pro, deepseek-reasoner), multi-turn conversations fail with:
400 Bad Request
{"error":{"message":"The `reasoning_content` in the thinking mode must be passed back to the API.","type":"invalid_request_error"}}
Root Cause
DeepSeek API requires that every assistant message in conversation history includes a reasoning_content field when thinking mode is enabled. This is documented at https://api-docs.deepseek.com/guides/thinking_mode#tool-calls.
Codex correctly captures reasoning content internally (ReasoningItem::raw_content in codex-rs/protocol/src/items.rs:120), but when building the messages array for the next API request, the reasoning_content field is not included in the serialized assistant message.
Steps to Reproduce
- Configure Codex to use a DeepSeek model with thinking mode
- Send a multi-turn conversation (any task requiring multiple API calls/tool calls)
- After the first turn produces reasoning content, the second API request fails with the above error
Expected Behavior
When using DeepSeek thinking mode, each assistant message in the API request should include:
{
"role": "assistant",
"content": "...",
"reasoning_content": "..."
}
Affected Code
The conversion from ResponseItem::Reasoning → TurnItem::Reasoning in codex-rs/core/src/event_mapping.rs:156-182 preserves raw_content, but the downstream serialization to API-compatible messages does not map it to the reasoning_content field required by DeepSeek.
Related Issues
This is a known pattern affecting multiple projects using DeepSeek API:
Suggested Fix
When building the messages array for provider API calls, for DeepSeek models specifically, include reasoning_content from ReasoningItem::raw_content in every assistant message. For other providers (OpenAI), omit it as before (OpenAI ignores unknown fields but DeepSeek requires this field).
Environment
- Codex version: latest
- Model: deepseek-v4-pro (thinking mode)
- OS: macOS
Description
When using Codex with DeepSeek models in thinking mode (e.g.,
deepseek-v4-pro,deepseek-reasoner), multi-turn conversations fail with:Root Cause
DeepSeek API requires that every assistant message in conversation history includes a
reasoning_contentfield when thinking mode is enabled. This is documented at https://api-docs.deepseek.com/guides/thinking_mode#tool-calls.Codex correctly captures reasoning content internally (
ReasoningItem::raw_contentincodex-rs/protocol/src/items.rs:120), but when building the messages array for the next API request, thereasoning_contentfield is not included in the serialized assistant message.Steps to Reproduce
Expected Behavior
When using DeepSeek thinking mode, each assistant message in the API request should include:
{ "role": "assistant", "content": "...", "reasoning_content": "..." }Affected Code
The conversion from
ResponseItem::Reasoning→TurnItem::Reasoningincodex-rs/core/src/event_mapping.rs:156-182preservesraw_content, but the downstream serialization to API-compatible messages does not map it to thereasoning_contentfield required by DeepSeek.Related Issues
This is a known pattern affecting multiple projects using DeepSeek API:
Suggested Fix
When building the messages array for provider API calls, for DeepSeek models specifically, include
reasoning_contentfromReasoningItem::raw_contentin every assistant message. For other providers (OpenAI), omit it as before (OpenAI ignores unknown fields but DeepSeek requires this field).Environment