Back to Blog

LangChain + DeepSeek Reasoner: Fixing the reasoning_content 400 in Tool-Calling Chains (2026)

2026-08-24·3 min read·CodeRouter Team

TL;DR — In LangChain, the DeepSeek reasoner 400 shows up when your chain's message history replays assistant turns without the reasoning_content DeepSeek attached to them — most commonly in agent loops with tool calling, custom memory classes, or message-trimming middleware. Fixes: keep langchain-deepseek current (round-trip handling has improved across 2026 releases), make sure your memory preserves additional_kwargs on AI messages instead of reconstructing bare messages, or route through an endpoint that runs DeepSeek with thinking mode off.

Why LangChain setups hit this

Pattern What it does to the thinking trace Fix
Custom memory rebuilding AIMessage(content=...) Drops additional_kwargs entirely Append the original message object, not a reconstruction
Trimming / summarization middleware Rewrites history and loses unknown fields Make it pass unknown fields through
Pinned old langchain-deepseek Predates reasoning-field round-trip support Upgrade first — this is the cheapest fix

LangChain represents turns as message objects, and DeepSeek's thinking trace rides along in the AI message's additional fields. Three common patterns break the round-trip:

  1. Custom memory / history classes that rebuild messages from plain text (AIMessage(content=...)) — the thinking block never makes it back
  2. Message trimming or summarization middleware that rewrites history before the next call
  3. Older integration versions predating full reasoning-field support — the 2026 releases of the DeepSeek integration handle the round-trip much better, so pinning an old version is a self-inflicted 400

The checklist

The infrastructure alternative

If the chain logic is not yours to change (or you support multiple reasoning providers), move the problem out of the framework: point LangChain's OpenAI-compatible client at CodeRouter and let the router own provider-specific field contracts. CodeRouter sends DeepSeek, Kimi and GLM requests with thinking mode disabled wherever the model allows it, so your chain can keep bare messages and never has a reasoning_content to replay — the same class of fix as for proxies and degraded-reasoning warnings. The trade-off: you don't get DeepSeek's thinking mode through CodeRouter; if you need it, fix the history in the chain.

Related

Try phase-aware routing on your own workload

One base URL for Claude Code, Cursor or Aider. Free trial, no credit card.

Start free trial

Get weekly AI cost optimization tips

Join developers cutting their agent bills