fix: preserve unsigned thinking blocks for DeepSeek Anthropic endpoint#18509
Open
SivanCola wants to merge 3 commits intoNousResearch:mainfrom
Open
fix: preserve unsigned thinking blocks for DeepSeek Anthropic endpoint#18509SivanCola wants to merge 3 commits intoNousResearch:mainfrom
SivanCola wants to merge 3 commits intoNousResearch:mainfrom
Conversation
…dpoints DeepSeek /anthropic and Kimi /coding endpoints require thinking blocks to be passed back in subsequent API requests when thinking mode is enabled. Previously, signed thinking blocks from reasoning_details were extracted first, which set _already_has_thinking=True and prevented the unsigned reasoning_content path from creating blocks. The signed blocks were then stripped by the thinking-block management pass (since DeepSeek/Kimi cannot validate Anthropic signatures), resulting in no thinking blocks at all and HTTP 400 errors. Fix: skip extracting signed thinking blocks from reasoning_details when the target endpoint is DeepSeek /anthropic or Kimi /coding, allowing the reasoning_content path to create unsigned blocks that these endpoints accept. Also widen the DeepSeek V-series model regex to accept bracket suffixes like [1m] (e.g. deepseek-v4-flash[1m] for 1M context), which were previously falling back to deepseek-chat.
Collaborator
Scope the fix to DeepSeek /anthropic endpoint only, as Kimi has not been verified to have the same issue.
Collaborator
…canonical models Add [1m] context-window variants to _DEEPSEEK_CANONICAL_MODELS and _PROVIDER_MODELS so these model IDs resolve explicitly (not just via the V-series regex fallback). Related: NousResearch#18509
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/anthropicendpoint with thinking mode enabled[1m](e.g.deepseek-v4-flash[1m]for 1M context)Problem
When replaying multi-turn conversations through DeepSeek's
/anthropicendpoint, the API returns:Root cause:
_extract_preserved_thinking_blocks()extracts signed thinking blocks fromreasoning_detailsfirst, setting_already_has_thinking=True. This prevents thereasoning_contentpath from creating unsigned blocks. The signed blocks are then stripped by the thinking-block management pass (since DeepSeek cannot validate Anthropic signatures), resulting in no thinking blocks at all.Fix
In
convert_messages_to_anthropic(), skip extracting signed thinking blocks fromreasoning_detailswhen the target endpoint is DeepSeek/anthropic. This allows thereasoning_contentpath to create unsigned blocks that DeepSeek accepts.Also widen the
_DEEPSEEK_V_SERIES_REregex from^deepseek-v\d+([-.].+)?$to^deepseek-v\d+.*$so model names with bracket suffixes (likedeepseek-v4-flash[1m]) are correctly recognized as V-series models instead of being normalized todeepseek-chat.Test plan
deepseek-v4-flash[1m]via/anthropicendpoint — multi-turn conversations now work without HTTP 400deepseek-v4-flash[1m]→deepseek-v4-flash[1m](notdeepseek-chat)