Skip to content

fix: support adaptive thinking for Claude Opus 4.8/4.7/… - #568

Merged
AAswordman merged 1 commit into
AAswordman:mainfrom
luojiaping:pr_claude_thinking
May 30, 2026
Merged

fix: support adaptive thinking for Claude Opus 4.8/4.7/…#568
AAswordman merged 1 commit into
AAswordman:mainfrom
luojiaping:pr_claude_thinking

Conversation

@luojiaping

Copy link
Copy Markdown
Collaborator

问题

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" 才能展示思考内容。

方案

  1. ThinkingFormat 枚举(ADAPTIVE/ENABLED)+ @Volatile 缓存
  2. prefersAdaptiveThinking() 按模型名启发式匹配(opus-4-8/4-7/4-6/sonnet-4-6)
  3. ADAPTIVE 发送 {type:"adaptive", display:"summarized"};ENABLED 保持原有 {type:"enabled", budget_tokens:N}
  4. isThinkingTypeError() 检测 thinking 相关 400 错误,自动翻转并缓存,不消耗 retry 额度
  5. 中转/代理平台的自定义模型名无需配置,首次失败后自动修正

兼容性

模型 thinking 格式
Opus 4.8/4.7 adaptive + display=summarized
Opus 4.6/Sonnet 4.6 adaptive(推荐)/ enabled 仍可用
Sonnet 4.5 及更早 enabled + budget_tokens

修改文件

  • ClaudeProvider.kt (+141 / -22)

验证

  • Opus 4.8 测试通过,思考内容正常显示
  • Sonnet 4.6 测试通过
  • 关闭思考模式正常

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
@AAswordman
AAswordman merged commit 089cf68 into AAswordman:main May 30, 2026
@luojiaping
luojiaping deleted the pr_claude_thinking branch June 15, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants