Skip to content

feat: add reasoning effort suffix support in model pricing - #2575

Closed
RedwindA wants to merge 1 commit into
QuantumNous:mainfrom
RedwindA:feat/unifyModelPriceWithSuffix
Closed

feat: add reasoning effort suffix support in model pricing#2575
RedwindA wants to merge 1 commit into
QuantumNous:mainfrom
RedwindA:feat/unifyModelPriceWithSuffix

Conversation

@RedwindA

@RedwindA RedwindA commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

PR 描述

背景

当前模型定价系统无法自动处理带有推理力度后缀(reasoning effort suffixes)的模型名称,导致这些模型无法使用基础模型的定价配置。

实现内容

FormatMatchingModelName 函数中增加对以下六种推理力度后缀的支持:

  • -high - 高推理力度
  • -minimal - 最小推理力度
  • -low - 低推理力度
  • -medium - 中等推理力度
  • -none - 无推理力度
  • -xhigh - 超高推理力度

工作原理

当模型名称包含上述后缀时,系统会自动移除后缀,使用基础模型名称进行价格和倍率查询。例如:

  • gemini-3-flash-preview-minimal → 查询 gemini-3-flash-preview 的定价

优势

  1. 灵活性提升:无需为每个推理力度后缀变体单独配置价格
  2. 统一管理:所有模型的不同推理力度变体共享基础模型的定价配置
  3. 易于扩展:未来新增的模型自动支持这些推理力度后缀

Summary by CodeRabbit

  • Bug Fixes
    • Fixed model pricing lookup to correctly handle model name variations by normalizing pricing-related suffixes, ensuring consistent price and ratio resolution across different model name formats.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Introduces normalization in FormatMatchingModelName that strips pricing-related reasoning suffixes from model names. The change removes -high, -minimal, -low, -medium, -none, and -xhigh suffixes after existing gizmo-prefix handling to standardize upstream model names before downstream price and ratio lookups.

Changes

Cohort / File(s) Summary
Model Name Normalization
setting/ratio_setting/model_ratio.go
Adds suffix-stripping logic to FormatMatchingModelName to remove pricing-related reasoning suffixes (-high, -minimal, -low, -medium, -none, -xhigh). Affects downstream model price and ratio lookups by normalizing names before map searches.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 A fuzzy hop through ratio lands so fine,
Stripping suffixes like carrots off the line,
-High, -low, and all between,
Cleaner names than we've seen!
Normalization's the game, precision's the win! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding support for reasoning effort suffixes in model pricing by normalizing model names in FormatMatchingModelName.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@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: 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-high will be normalized to o3-mini before map lookup. The explicit entries for o3-mini-high, o3-mini-2025-01-31-high, o3-mini-low, o3-mini-2025-01-31-low, o3-mini-medium, and o3-mini-2025-01-31-medium will 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

📥 Commits

Reviewing files that changed from the base of the PR and between 443b058 and 7a75177.

📒 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

Comment on lines +837 to +845

// 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
}
}

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the context better
head -c 10000 setting/ratio_setting/model_ratio.go | wc -l

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

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

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

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

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

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

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

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

Repository: QuantumNous/new-api

Length of output: 387


🏁 Script executed:

# Check where FormatMatchingModelName is called from
rg -n 'FormatMatchingModelName' setting/ratio_setting/model_ratio.go

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

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

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

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

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

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

@seefs001

seefs001 commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator

这个吧,是就这样设计的,没打算让他定一个价格全部应用

@Calcium-Ion

Copy link
Copy Markdown
Member

如果设置了gemini-3-flash-preview-minimal的价格,那就无法按照gemini-3-flash-preview-minimal计费了

@RedwindA

RedwindA commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

那改成默认使用base model的价格,如果单独配置就遵从单独的?

一个模型配四五个价格还是有点蛋疼


rabbit说的也有道理,先关了

@RedwindA RedwindA closed this Jan 4, 2026
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.

3 participants