feat: support Claude 5 model family - #6587
Conversation
WalkthroughClaude Fable 5, Sonnet 5, and Opus 5 are added to AWS, Claude, and Vertex mappings. Their requests omit unsupported sampling parameters. Ratio defaults and tests are added for all three models. ChangesClaude 5 model support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ClaudeRequest
participant ClaudeHelper
participant ConvertOpenAIRequest
ClaudeRequest->>ClaudeHelper: submit Claude 5 model and sampling parameters
ClaudeHelper->>ConvertOpenAIRequest: convert request
ConvertOpenAIRequest-->>ClaudeHelper: preserve model and clear temperature, top-p, and top-k
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/claude_handler.go`:
- Around line 55-61: Normalize Claude 5 thinking after all input-specific
branches in relay/claude_handler.go around the model handling block: map legacy
enabled or disabled thinking inputs to adaptive thinking with
OutputConfig.effort, while preserving native Claude 5 requests in adaptive mode
before relay conversion. Update
relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go at the cited
conversion site to apply the same Claude 5 normalization, ensuring both
reasoning-derived and native requests avoid budget_tokens and disabled thinking
settings.
- Around line 55-61: Update the Claude 5 normalization block in the request
handling flow to set request.Thinking to the adaptive native-thinking
configuration for claude-fable-5, claude-sonnet-5, and claude-opus-5, rather
than preserving legacy or explicitly enabled thinking modes. Ensure any effort
setting is represented through request.OutputConfig, or reject -thinking
variants before reaching AWS Bedrock.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8fab9bea-f185-4c57-8256-6cba4481585d
📒 Files selected for processing (9)
relay/channel/aws/constants.gorelay/channel/claude/constants.gorelay/channel/claude/relay_claude_test.gorelay/channel/vertex/adaptor.gorelay/claude_handler.gorelaykit/relayconvert/internal/oai_chat/to_claude_messages_req.gosetting/ratio_setting/cache_ratio.gosetting/ratio_setting/claude_5_ratio_test.gosetting/ratio_setting/model_ratio.go
| if strings.HasPrefix(request.Model, "claude-fable-5") || | ||
| strings.HasPrefix(request.Model, "claude-sonnet-5") || | ||
| strings.HasPrefix(request.Model, "claude-opus-5") { | ||
| request.Temperature = nil | ||
| request.TopP = nil | ||
| request.TopK = nil | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== files =="
fd -a 'claude_handler\.go|to_claude_messages_req\.go|expr\.md' . | sed 's#^\./##'
echo "== relay/claude_handler outline =="
ast-grep outline relay/claude_handler.go 2>/dev/null || true
echo "== relevant relay/claude_handler snippets =="
nl -ba relay/claude_handler.go | sed -n '1,140p'
echo "== relevant converter snippets =="
nl -ba relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go | sed -n '1,220p'
echo "== thinking/model references in relay/claude_handler.go =="
rg -n "thinking|Model|claude-|Temperature|TopP|TopK|-thinking|budget" relay/claude_handler.go
echo "== thinking/model references in converter =="
rg -n "thinking|Model|claude-fable-5|claude-sonnet-5|claude-opus-5|ReasoningEffort|Reasoning|BudgetTokens|OutputConfig|effort" relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.goRepository: QuantumNous/new-api
Length of output: 1927
🌐 Web query:
AWS Bedrock Claude messages adaptive thinking Fable 5 rejected thinking Type enabled disabled
💡 Result:
Adaptive thinking is a dynamic reasoning configuration in Amazon Bedrock for Anthropic Claude models that replaces the older manual approach of setting fixed budget_tokens [1][2]. Instead of defining a static token budget for thinking, adaptive thinking allows the model to dynamically allocate reasoning resources based on the complexity of the request [1][3]. Claude Fable 5 and related models (such as Opus 4.7 and Mythos 5) exclusively support adaptive thinking [1][4][5]. Attempting to use the legacy thinking.type: "enabled" (with budget_tokens) or thinking.type: "disabled" configuration with these models will result in a 400 invalid_request_error [1][4][5]. For models that support adaptive thinking, the behavior is controlled via the thinking object in the API request: - To enable adaptive thinking, set thinking.type to "adaptive" [1][2]. - To control the reasoning depth, use the output_config.effort parameter, which accepts values such as low, medium, high, xhigh, or max [1][2]. - For Claude Fable 5, thinking is always enabled; passing thinking.type: "disabled" is not supported [5][6]. Older models, such as Claude Sonnet 4.5 or Opus 4.5, do not support adaptive thinking and require the use of thinking.type: "enabled" with a specified budget_tokens value [1][7]. Claude Sonnet 4.6 and Opus 4.6 represent a transition period where both adaptive thinking and the older extended thinking configuration were supported, though extended thinking is now deprecated for these models [1][7].
Citations:
- 1: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-adaptive-thinking.html
- 2: https://builder.aws.com/content/3Cl90CMMnqzCrkk6mXcmnGo1WTG/claude-opus-47-on-amazon-bedrock-apis-features-and-migration-guide
- 3: https://aws.amazon.com/blogs/aws/introducing-anthropics-claude-opus-4-7-model-in-amazon-bedrock/
- 4: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-extended-thinking.html
- 5: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-fable-5.html
- 6: https://platform.claude.com/docs/en/about-claude/models/introducing-claude-fable-5-and-claude-mythos-5
- 7: https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== files =="
fd -a 'claude_handler\.go|to_claude_messages_req\.go|expr\.md' . | sed 's#^\./##'
echo "== relay/claude_handler.go relevant snippet =="
nl -ba relay/claude_handler.go | sed -n '1,140p'
echo "== converter relevant snippet =="
nl -ba relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go | sed -n '1,220p'
echo "== thinking/model references =="
rg -n "thinking|claude-fable-5|claude-sonnet-5|claude-opus-5|ReasoningEffort|Reasoning|BudgetTokens|OutputConfig|effort|adaptive|-thinking|enabled|disabled" relay/claude_handler.go relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.goRepository: QuantumNous/new-api
Length of output: 1927
Normalize Claude 5 thinking after all input-specific branches.
Claude Fable 5 and Claude 5 Sonnet/Opus models only support adaptive thinking; legacy thinking.type: "enabled" with budget_tokens or thinking.type: "disabled" fail for these models. Map reasoning inputs to adaptive thinking with OutputConfig.effort, and keep native Claude 5 requests in adaptive mode before relay conversion sends the request.
📍 Affects 2 files
relay/claude_handler.go#L55-L61(this comment)relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go#L133-L139
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@relay/claude_handler.go` around lines 55 - 61, Normalize Claude 5 thinking
after all input-specific branches in relay/claude_handler.go around the model
handling block: map legacy enabled or disabled thinking inputs to adaptive
thinking with OutputConfig.effort, while preserving native Claude 5 requests in
adaptive mode before relay conversion. Update
relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go at the cited
conversion site to apply the same Claude 5 normalization, ensuring both
reasoning-derived and native requests avoid budget_tokens and disabled thinking
settings.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate file =="
fd -a 'claude_handler.go' . || true
echo "== file outline =="
ast-grep outline relay/claude_handler.go || true
echo "== relevant source =="
cat -n relay/claude_handler.go | sed -n '1,150p'Repository: QuantumNous/new-api
Length of output: 1927
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== search for Thinking and request fields definitions/usages =="
rg -n "Thinking|claude-fable-5|claude-sonnet-5|claude-opus-5|adaptive|OutputConfig|streamSupportedChannels|to_claude_messages_req.go" -S .Repository: QuantumNous/new-api
Length of output: 1927
🌐 Web query:
Claude Fable 5 adaptive thinking AWS Bedrock messages only enabled disabled error
💡 Result:
The error you are encountering occurs because newer Claude models, such as Claude Fable 5, support only adaptive thinking and do not accept the legacy extended thinking parameters [1][2]. Specifically, these models reject requests that include thinking.type: "enabled" or thinking.type: "disabled" and will return a 400 validation error [1][2]. To resolve this issue, you must update your API requests to use the adaptive thinking configuration [1][2]. Required Changes: 1. Replace thinking.type: "enabled" (which required budget_tokens) with thinking.type: "adaptive" [1][2]. 2. If you need to control the thinking depth, use the output_config.effort parameter [1][2]. Note that this effort parameter must be placed within an output_config object in your request body, not inside the thinking object, to avoid a ValidationException [1]. 3. If you previously used thinking.type: "disabled", you can simply omit the thinking parameter entirely, as adaptive thinking is enabled by default for these models [2]. For further guidance, consult the official Amazon Bedrock documentation on adaptive thinking [1]. If you are using client libraries that automatically generate these parameters, ensure you are using the latest version of the SDK or tool, as older versions have previously experienced this 400 error when they incorrectly defaulted to legacy thinking modes for newer models [3][4][5].
Citations:
- 1: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-adaptive-thinking.html
- 2: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-extended-thinking.html
- 3: [Bug] Opus 4.8 on Bedrock: "thinking.type.enabled" not supported — regression from #51439 anthropics/claude-code#63546
- 4: Bedrock: thinking.type.enabled not supported by newer models behind inference profile ARNs anthropics/claude-code#51439
- 5: Opus 4.7 via Bedrock application inference profiles fails with thinking.type.enabled error anthropics/claude-code#51711
🌐 Web query:
Claude Fable 5 AWS Bedrock thinking adaptive only -thinking parameters
💡 Result:
Claude Fable 5, released on June 9, 2026, is an Anthropic "Mythos-class" model available on Amazon Bedrock [1][2][3]. It exclusively supports "adaptive thinking" and does not support the legacy "extended thinking" mode (manual budget-based thinking) [1][4]. Parameters for adaptive thinking on Claude Fable 5: 1. Thinking Configuration: The model uses thinking.type: "adaptive", which is mandatory [1][4]. The budget_tokens parameter used in older "extended thinking" modes is not supported and will result in a 400 error if provided [1][4]. 2. Controlling Reasoning Depth: You can influence the model's reasoning process using the output_config.effort parameter [5]. This parameter should be placed inside a separate output_config object in your request body, rather than inside the thinking object [5]. 3. Effort Levels: Valid effort levels include low, medium, high, xhigh, and max [5][6]. 4. Important Restrictions: - If thinking is set to disabled (e.g., {"thinking": {"type": "disabled"}}), the output_config.effort parameter is capped at high; using xhigh or max with disabled thinking will return an invalid_request_error [5]. - Adaptive thinking is the default and recommended behavior [5][4]. - Unlike some earlier models, sampling parameters like temperature, top_p, and top_k are often not supported or recommended for these advanced reasoning models; check specific model documentation if you are migrating from earlier versions [7]. Always ensure your request adheres to the structure required by the Amazon Bedrock API for Claude models [1][8]. [5][4]
Citations:
- 1: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-fable-5.html
- 2: https://aws.amazon.com/blogs/aws/anthropic-claude-fable-5-on-aws-mythos-class-capabilities-with-built-in-safeguards-now-available/
- 3: https://aws.amazon.com/about-aws/whats-new/2026/06/claude-fable-5-aws/
- 4: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-extended-thinking.html
- 5: https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-adaptive-thinking.html
- 6: https://github.com/aws-samples/sample-amazon-bedrock-global-cris/blob/main/global-cris/foundation_models/invoke_model/advanced_claude_opus_4_6_invoke_model_example.py
- 7: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-4-7.html
- 8: https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock.md
🌐 Web query:
Site:github.com QuantumNous/new-api relay/claude_handler.go claude-fable-5 Thinking
💡 Result:
In the QuantumNous/new-api project, the relay/claude_handler.go file handles model requests, including those for Claude's "Thinking" capabilities [1][2][3]. Regarding your specific query about claude-fable-5 and Thinking: 1. Context: Claude Fable 5 is an advanced Anthropic model released in June 2026 [4]. It is part of the Mythos-class tier and supports "extended thinking" capabilities [5][4]. 2. Handler Implementation: The claude_handler.go logic distinguishes between models that support standard thinking (enabled via the -thinking suffix or specific configuration) and those with more restrictive or adaptive requirements [1][2]. 3. Adaptive Thinking: For specific high-capability models (like Opus 4.7/4.8, and by extension Fable 5, as it utilizes similar advanced architecture), the handler often configures the Thinking parameter to type "adaptive" with an effort level set to "high" [1][3]. It also enforces constraints where certain parameters like temperature, top_p, and top_k are set to nil (or ignored) to comply with the model's strict requirements for these modes [1][2][6]. 4. Thinking Configuration: If a request uses the -thinking suffix, the handler automatically manages the budget tokens (often set as 80% of max_tokens) and enables the Thinking feature if not provided by the user [1][3]. Because Claude Fable 5 is a recent model [4], integration in community projects like new-api involves updating allow-lists and capability configurations to ensure the model correctly routes through these thinking-logic handlers [7][8]. The handler ensures that when a user requests "thinking" for these newer models, the API request is properly formatted with the required "adaptive" or "enabled" thinking blocks, respecting the strict parameter constraints mandated by the Anthropic API [1][2].
Citations:
- 1: https://github.com/QuantumNous/new-api/blob/b08febaa/relay/claude_handler.go
- 2: https://github.com/QuantumNous/new-api/blob/7c28993f/relay/claude_handler.go
- 3: https://github.com/QuantumNous/new-api/blob/f7dae5cb/relay/claude_handler.go
- 4: https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/Official/2026-06-09-claude-fable-5.md
- 5: https://github.com/anthropics/claude-cookbooks/blob/main/fable_5_fallback_billing/guide.ipynb
- 6: fix: If top_p is not provided, ignore it #3141
- 7: feat(models): add Fable 5 as a selectable Anthropic model utensils/claudette#995
- 8: fix(anthropic): add Fable 5 to Claude CLI catalog openclaw/openclaw#101453
🌐 Web query:
"Type: \"enabled\"" "claude" "temperature = 1.0"
💡 Result:
In the current Claude API, the behavior of the temperature parameter depends on the specific model and whether thinking is enabled. For older models that support the temperature parameter, the default value is 1.0, and the range is 0.0 to 1.0 [1][2][3]. When extended thinking is enabled on these models, the API forces temperature to 1.0 [4][5]. However, for Claude 4.7, 5, and later model versions, the temperature parameter is deprecated and not supported [4][6][7]. Attempting to set temperature to any value (including 1.0) on these models will return a 400 error [8][6][9]. For these newer models, you must omit the temperature parameter from your request entirely and use system prompts to guide the model's behavior [8][6][7]. Summary of temperature settings: - Models supporting temperature: Default is 1.0; range is 0.0–1.0 [1][2]. - Models with thinking enabled: Must be set to 1.0 or left unset [4]. - Claude 4.7, 5, and later: Do not set temperature; omit it to avoid a 400 error [6][9][7].
Citations:
- 1: https://platform.claude.com/docs/en/api/messages
- 2: https://github.com/anthropics/anthropic-sdk-python/blob/04b468da/src/anthropic/types/beta/message_create_params.py
- 3: https://github.com/anthropics/anthropic-sdk-java/blob/64d4019c/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/MessageCreateParams.kt
- 4: https://platform.claude.com/docs/en/claude_api_primer
- 5: https://tools.yiteai.com/en/books/claude-guide/ch07
- 6: https://platform.claude.com/docs/en/build-with-claude/working-with-messages
- 7: https://platform.claude.com/docs/en/about-claude/models/whats-new-sonnet-5
- 8: https://clauder-navi.com/en/claude-opus-4-7-migration-guide/
- 9: https://platform.claude.com/docs/en/about-claude/models/migration-guide
Enforce adaptive thinking for Claude 5 models.
For claude-fable-5, claude-sonnet-5, and claude-opus-5, this block clears Temperature, TopP, and TopK, but it leaves request.Thinking unchanged. If an old-thinking request remains or the -thinking branch enables thinking again, AWS Bedrock rejects Claude Fable 5 because it only accepts thinking.type: "adaptive" and supports effort through OutputConfig. Normalize native thinking for Claude 5 to adaptive and preserve effort outside Thinking, or reject -thinking requests.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@relay/claude_handler.go` around lines 55 - 61, Update the Claude 5
normalization block in the request handling flow to set request.Thinking to the
adaptive native-thinking configuration for claude-fable-5, claude-sonnet-5, and
claude-opus-5, rather than preserving legacy or explicitly enabled thinking
modes. Ensure any effort setting is represented through request.OutputConfig, or
reject -thinking variants before reaching AWS Bedrock.
Important
📝 变更描述 / Description
新增
claude-fable-5、claude-sonnet-5和claude-opus-5三个模型,覆盖 Anthropic Claude、AWS Bedrock 与 Google Vertex AI 渠道的模型发现和上游模型 ID 映射。Claude 5 默认使用 adaptive thinking,不接受
temperature、top_p和top_k等采样参数,因此原生 Claude 请求和 OpenAI 转 Claude 请求都会在转发前移除这些字段,避免上游参数校验失败。Fable、Sonnet、Opus 输入倍率分别为5.0、1.5、2.5,其中 Fable 价格是 Opus 的两倍;输出倍率为5,缓存读取/创建倍率为0.1/1.25。本次代码由 Codex AI-assisted 完成,并已在本地审查变更范围和测试结果。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
New Features
Tests