fix: use default model price for radio price model - #3090
Conversation
WalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 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.
| defaultPrice, ok := ratio_setting.GetDefaultModelPriceMap()[info.OriginModelName] | ||
| if !ok { | ||
| // 不再使用默认价格,而是返回错误 | ||
| return types.PriceData{}, fmt.Errorf("模型 %s 价格未配置,请联系管理员设置", info.OriginModelName) | ||
| } else { | ||
| if ok { | ||
| modelPrice = defaultPrice |
There was a problem hiding this comment.
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.
当前最新合并会导致未配置价格但配置了倍率的视频模型无法使用返回错误

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