DeepSeek thinking mode: missing reasoning_content in assistant messages causes 400 error

Open 💬 2 comments Opened May 25, 2026 by nengqing-cpu

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

  1. Configure Codex to use a DeepSeek model with thinking mode
  2. Send a multi-turn conversation (any task requiring multiple API calls/tool calls)
  3. 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::ReasoningTurnItem::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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗