fix: support adaptive thinking for Claude Opus 4.8/4.7/… - #568
Merged
Conversation
Opus 4.8/4.7 no longer accept thinking.type="enabled" with budget_tokens and return 400 errors. This commit adds: - ThinkingFormat enum (ADAPTIVE/ENABLED) with @volatile cached state - Model name heuristic (prefersAdaptiveThinking) for known models - Error-driven auto-fallback (isThinkingTypeError) for proxy routes - Single-flip guard per request to prevent infinite retry loops - display="summarized" for Opus to return thinking content
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.
问题
Claude Opus 4.8/4.7 不再支持
thinking.type: "enabled"+budget_tokens,API 返回 400:
"thinking.type.enabled" is not supported for this model同时 Opus 4.8/4.7 默认
display: "omitted",返回空 thinking block,需显式设置
display: "summarized"才能展示思考内容。方案
ThinkingFormat枚举(ADAPTIVE/ENABLED)+@Volatile缓存prefersAdaptiveThinking()按模型名启发式匹配(opus-4-8/4-7/4-6/sonnet-4-6){type:"adaptive", display:"summarized"};ENABLED 保持原有{type:"enabled", budget_tokens:N}isThinkingTypeError()检测 thinking 相关 400 错误,自动翻转并缓存,不消耗 retry 额度兼容性
修改文件
ClaudeProvider.kt(+141 / -22)验证