codex - 💡(How to fix) Fix DeepSeek thinking mode: missing reasoning_content in assistant messages causes 400 error

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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"}}

Error Message

{"error":{"message":"The reasoning_content in the thinking mode must be passed back to the API.","type":"invalid_request_error"}} 3. After the first turn produces reasoning content, the second API request fails with the above 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.

Code Example

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

---

{
  "role": "assistant",
  "content": "...",
  "reasoning_content": "..."
}
RAW_BUFFERClick to expand / collapse

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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING