Skip to content

fix: use default model price for radio price model - #3090

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/5ce796dde30f9d7442be5773543ecf96cbefe407
Mar 3, 2026
Merged

fix: use default model price for radio price model#3090
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/5ce796dde30f9d7442be5773543ecf96cbefe407

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Mar 3, 2026

Copy link
Copy Markdown
Member

当前最新合并会导致未配置价格但配置了倍率的视频模型无法使用返回错误
image

修复为只有价格和倍率都没有配置时才返回错误
价格没配置但倍率有配置时, 取配置的默认预扣值

Summary by CodeRabbit

  • Bug Fixes
    • Model pricing now gracefully falls back to default prices and model ratios when explicit pricing is unavailable, reducing configuration errors.

@coderabbitai

coderabbitai Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The ModelPriceHelperPerCall function now implements a fallback strategy for unset model prices. Instead of immediately erroring when default price is missing, it attempts to use a default price map, then falls back to ratio-based pricing calculated from pre-consumed quota, only erroring if both are unavailable and conditions disallow it.

Changes

Cohort / File(s) Summary
Price Resolution Logic
relay/helper/price.go
Modified ModelPriceHelperPerCall to add fallback mechanisms: attempts default price retrieval, then ratio-based pricing via PreConsumedQuota/QuotaPerUnit calculation, only erroring when neither approach is viable and unset ratios are disallowed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰✨ A helper now bends without breaking,
When prices hide, new paths start shaking—
Default, ratio, quota dance in line,
Fallbacks bloom where errors'd opine! 🌟

🚥 Pre-merge checks | ✅ 3
✅ 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 'fix: use default model price for radio price model' is directly related to the main change, which addresses using default model prices as a fallback when explicit prices are not configured.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@relay/helper/price.go`:
- Around line 151-153: Normalize the model name the same way used for ratio
lookups before consulting GetDefaultModelPriceMap(): call the existing
normalization/alias-stripping logic (the same function used elsewhere for ratio
resolution) on info.OriginModelName and use that normalized name for the map
lookup that assigns defaultPrice to modelPrice; also apply the same
normalization when performing the other default-price lookup path that currently
uses the raw model name so aliases/variant suffixes (e.g., “-thinking”)
correctly match configured defaults.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e71f5a4 and d12cc3a.

📒 Files selected for processing (1)
  • relay/helper/price.go

Comment thread relay/helper/price.go
Comment on lines 151 to 153
defaultPrice, ok := ratio_setting.GetDefaultModelPriceMap()[info.OriginModelName]
if !ok {
// 不再使用默认价格,而是返回错误
return types.PriceData{}, fmt.Errorf("模型 %s 价格未配置,请联系管理员设置", info.OriginModelName)
} else {
if ok {
modelPrice = defaultPrice

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 | 🟠 Major

Normalize model name before default-price map lookup to avoid wrong fallback billing.

Line 151 uses info.OriginModelName directly against GetDefaultModelPriceMap(). This bypasses the model-name matching path used by ratio lookups, so alias/variant names can miss configured defaults and incorrectly fall back to Line 165’s generic pre-consume price.

Suggested fix
-		defaultPrice, ok := ratio_setting.GetDefaultModelPriceMap()[info.OriginModelName]
+		defaultPriceMap := ratio_setting.GetDefaultModelPriceMap()
+		normalizedName := ratio_setting.FormatMatchingModelName(info.OriginModelName)
+		defaultPrice, ok := defaultPriceMap[normalizedName]
+		if !ok {
+			// keep backward compatibility for exact keys if any exist
+			defaultPrice, ok = defaultPriceMap[info.OriginModelName]
+		}
 		if ok {
 			modelPrice = defaultPrice
 		} else {

Based on learnings: Claude “-thinking” variants can rely on name normalization/suffix handling before map-based ratio/price resolution.

Also applies to: 165-165

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/helper/price.go` around lines 151 - 153, Normalize the model name the
same way used for ratio lookups before consulting GetDefaultModelPriceMap():
call the existing normalization/alias-stripping logic (the same function used
elsewhere for ratio resolution) on info.OriginModelName and use that normalized
name for the map lookup that assigns defaultPrice to modelPrice; also apply the
same normalization when performing the other default-price lookup path that
currently uses the raw model name so aliases/variant suffixes (e.g.,
“-thinking”) correctly match configured defaults.

@Calcium-Ion
Calcium-Ion merged commit ae1c8e4 into QuantumNous:main Mar 3, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 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.

2 participants