Skip to content

feat: support Claude 5 model family - #6587

Open
hjxwz123 wants to merge 2 commits into
QuantumNous:mainfrom
hjxwz123:feat/claude-5-models
Open

feat: support Claude 5 model family#6587
hjxwz123 wants to merge 2 commits into
QuantumNous:mainfrom
hjxwz123:feat/claude-5-models

Conversation

@hjxwz123

@hjxwz123 hjxwz123 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

新增 claude-fable-5claude-sonnet-5claude-opus-5 三个模型,覆盖 Anthropic Claude、AWS Bedrock 与 Google Vertex AI 渠道的模型发现和上游模型 ID 映射。

Claude 5 默认使用 adaptive thinking,不接受 temperaturetop_ptop_k 等采样参数,因此原生 Claude 请求和 OpenAI 转 Claude 请求都会在转发前移除这些字段,避免上游参数校验失败。Fable、Sonnet、Opus 输入倍率分别为 5.01.52.5,其中 Fable 价格是 Opus 的两倍;输出倍率为 5,缓存读取/创建倍率为 0.1/1.25

本次代码由 Codex AI-assisted 完成,并已在本地审查变更范围和测试结果。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

git diff origin/main...HEAD --check
# passed

go test ./relay/channel/claude ./relay/channel/aws ./relay/channel/vertex ./setting/ratio_setting ./relay -count=1
# ok github.com/QuantumNous/new-api/relay/channel/claude
# ok github.com/QuantumNous/new-api/relay/channel/aws
# ?  github.com/QuantumNous/new-api/relay/channel/vertex [no test files]
# ok github.com/QuantumNous/new-api/setting/ratio_setting
# ok github.com/QuantumNous/new-api/relay

cd relaykit && GOWORK=off go test ./...
# passed

Summary by CodeRabbit

  • New Features

    • Added support for Claude Fable 5, Sonnet 5, and Opus 5 models across supported AWS, Vertex, and Claude integrations.
    • Added regional availability for the new models in US, AP, and EU regions.
    • Applied model-specific request handling and default usage ratios.
  • Tests

    • Added coverage verifying model availability, parameter handling, and default ratios for Claude 5 models.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Claude 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.

Changes

Claude 5 model support

Layer / File(s) Summary
Model registration and provider mappings
relay/channel/claude/constants.go, relay/channel/aws/constants.go, relay/channel/vertex/adaptor.go
Adds the three Claude 5 identifiers to model lists and provider mappings. AWS mappings include US, AP, and EU regions.
Claude 5 request normalization
relay/claude_handler.go, relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go, relay/channel/claude/relay_claude_test.go
Preserves the requested model name and removes temperature, top-p, and top-k parameters. Tests cover request conversion and model listing.
Claude 5 ratio settings
setting/ratio_setting/model_ratio.go, setting/ratio_setting/cache_ratio.go, setting/ratio_setting/claude_5_ratio_test.go
Adds default model, cache, and create-cache ratios. Claude 5 models use a locked completion ratio of 5. Tests verify the defaults.

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
Loading

Possibly related PRs

Suggested reviewers: seefs001

Poem

A rabbit adds three models bright,
Fable, Sonnet, Opus in flight.
Their sampling knobs are tucked away,
While ratios guide the charge today.
AWS and Vertex join the play.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for the Claude 5 model family.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hjxwz123 hjxwz123 closed this Aug 1, 2026
@hjxwz123 hjxwz123 reopened this Aug 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cfaba1d and 848aa58.

📒 Files selected for processing (9)
  • relay/channel/aws/constants.go
  • relay/channel/claude/constants.go
  • relay/channel/claude/relay_claude_test.go
  • relay/channel/vertex/adaptor.go
  • relay/claude_handler.go
  • relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go
  • setting/ratio_setting/cache_ratio.go
  • setting/ratio_setting/claude_5_ratio_test.go
  • setting/ratio_setting/model_ratio.go

Comment thread relay/claude_handler.go
Comment on lines +55 to +61
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.go

Repository: 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:


🏁 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.go

Repository: 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:


🌐 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:


🌐 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:


🌐 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:


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.

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.

1 participant