feat: add reasoning effort suffix support in model pricing - #2575
feat: add reasoning effort suffix support in model pricing#2575RedwindA wants to merge 1 commit into
Conversation
WalkthroughIntroduces normalization in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
setting/ratio_setting/model_ratio.go (1)
73-78: Remove dead code: explicit o3-mini suffix entries are now unreachable.With the new suffix-stripping logic at lines 838-845, model names like
o3-mini-highwill be normalized too3-minibefore map lookup. The explicit entries foro3-mini-high,o3-mini-2025-01-31-high,o3-mini-low,o3-mini-2025-01-31-low,o3-mini-medium, ando3-mini-2025-01-31-mediumwill never be used.Since all these variants have the same ratio (0.55) as their base models, removing them won't change behavior.
🔎 Proposed cleanup
"o3-mini": 0.55, "o3-mini-2025-01-31": 0.55, - "o3-mini-high": 0.55, - "o3-mini-2025-01-31-high": 0.55, - "o3-mini-low": 0.55, - "o3-mini-2025-01-31-low": 0.55, - "o3-mini-medium": 0.55, - "o3-mini-2025-01-31-medium": 0.55, "o3": 1.0, // $2 / 1M tokens
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
setting/ratio_setting/model_ratio.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
📚 Learning: 2025-08-05T17:14:17.246Z
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
Applied to files:
setting/ratio_setting/model_ratio.go
|
|
||
| // Strip reasoning effort suffixes for pricing | ||
| reasoningSuffixes := []string{"-high", "-minimal", "-low", "-medium", "-none", "-xhigh"} | ||
| for _, suffix := range reasoningSuffixes { | ||
| if strings.HasSuffix(name, suffix) { | ||
| name = strings.TrimSuffix(name, suffix) | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's understand the context better
head -c 10000 setting/ratio_setting/model_ratio.go | wc -lRepository: QuantumNous/new-api
Length of output: 66
🏁 Script executed:
# Check the file size and examine the specific lines
wc -l setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 103
🏁 Script executed:
# Examine the code around lines 837-845
sed -n '820,860p' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 1374
🏁 Script executed:
# Search for models ending with reasoning suffixes
echo "=== Models ending with reasoning suffixes in model_ratio.go ==="
rg -n '^\s*"[^"]*-(high|minimal|low|medium|none|xhigh)"\s*:' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 451
🏁 Script executed:
# Check if corresponding base models exist
echo "=== Checking for base models (without suffixes) ==="
rg -n '^\s*"[^"]+":\s*\{' setting/ratio_setting/model_ratio.go | head -20Repository: QuantumNous/new-api
Length of output: 114
🏁 Script executed:
# Look at the function this code is in to understand the usage
sed -n '800,850p' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 1649
🏁 Script executed:
# Check if "yi" base model exists in pricing
rg -n '"yi"' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 45
🏁 Script executed:
# Get more context around yi-medium definition
sed -n '220,230p' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 505
🏁 Script executed:
# Search for all -medium, -high, -low models to identify false positives
rg -n '^\s*"[^"]*-(medium|high|low|minimal|none|xhigh)"\s*:' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 387
🏁 Script executed:
# Check where FormatMatchingModelName is called from
rg -n 'FormatMatchingModelName' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 411
🏁 Script executed:
# Check if yi-medium has specific pricing
rg -n 'yi-medium' setting/ratio_setting/model_ratio.go -B 2 -A 2Repository: QuantumNous/new-api
Length of output: 397
🏁 Script executed:
# Search for ALL models ending with -medium, -high, -low, -minimal, -none, -xhigh in both maps
echo "=== All models in defaultModelPrice ending with reasoning suffixes ==="
rg -n '^\s*"[^"]*-(medium|high|low|minimal|none|xhigh)"' setting/ratio_setting/model_ratio.go | head -50Repository: QuantumNous/new-api
Length of output: 458
🏁 Script executed:
# Check what models are defined starting with "yi" to see if there's a base yi
rg -n '"yi[^"]*"' setting/ratio_setting/model_ratio.go | head -30Repository: QuantumNous/new-api
Length of output: 622
🏁 Script executed:
# Check the calls to FormatMatchingModelName in context to understand the impact
sed -n '410,415p' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 182
🏁 Script executed:
# Understand the complete picture - check GetModelPrice function
sed -n '400,420p' setting/ratio_setting/model_ratio.goRepository: QuantumNous/new-api
Length of output: 536
Fix suffix-stripping logic to avoid breaking legitimate model names.
The suffix-stripping logic breaks pricing lookup for legitimate models that end with reasoning-effort suffixes. Specifically, yi-medium gets normalized to yi, which doesn't exist in the pricing map, causing lookup failures.
The issue is that the logic strips suffixes from ANY model, not just reasoning-effort variants. The o3-mini variants work because they're explicitly defined with each suffix variant, but models like yi-medium are legitimate standalone models with their own pricing and should not be normalized.
Fix: Only strip reasoning-effort suffixes from models that support reasoning (e.g., o3-mini variants), or verify the base model exists in the pricing map before stripping. Otherwise, add explicit model entries for the non-suffixed variants, or use a more selective approach that doesn't affect existing models.
🤖 Prompt for AI Agents
In setting/ratio_setting/model_ratio.go around lines 837 to 845, the current
loop strips reasoning-effort suffixes from any model name, which incorrectly
normalizes legitimate model names like "yi-medium"; change the logic to first
check whether the base model (name with the suffix removed) exists in the
pricing map (or in a whitelist of models that support reasoning variants) before
trimming: only assign name = strings.TrimSuffix(name, suffix) if the pricing map
contains the base key (or the model is in the supported-variants list);
otherwise leave the original name unchanged so standalone models keep their
pricing lookup working.
|
这个吧,是就这样设计的,没打算让他定一个价格全部应用 |
|
如果设置了gemini-3-flash-preview-minimal的价格,那就无法按照gemini-3-flash-preview-minimal计费了 |
|
那改成默认使用base model的价格,如果单独配置就遵从单独的? 一个模型配四五个价格还是有点蛋疼 rabbit说的也有道理,先关了 |
PR 描述
背景
当前模型定价系统无法自动处理带有推理力度后缀(reasoning effort suffixes)的模型名称,导致这些模型无法使用基础模型的定价配置。
实现内容
在
FormatMatchingModelName函数中增加对以下六种推理力度后缀的支持:-high- 高推理力度-minimal- 最小推理力度-low- 低推理力度-medium- 中等推理力度-none- 无推理力度-xhigh- 超高推理力度工作原理
当模型名称包含上述后缀时,系统会自动移除后缀,使用基础模型名称进行价格和倍率查询。例如:
gemini-3-flash-preview-minimal→ 查询gemini-3-flash-preview的定价优势
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.