Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions relay/helper/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,22 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) (types
// 如果没有配置价格,检查模型倍率配置
if !success {

// 没有配置费用,返回错误
// 没有配置费用,也要使用默认费用,否则按费率计费模型无法使用
defaultPrice, ok := ratio_setting.GetDefaultModelPriceMap()[info.OriginModelName]
if !ok {
// 不再使用默认价格,而是返回错误
return types.PriceData{}, fmt.Errorf("模型 %s 价格未配置,请联系管理员设置", info.OriginModelName)
} else {
if ok {
modelPrice = defaultPrice
Comment on lines 151 to 153

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.

}
// 没有配置倍率也不接受没配置,那就返回错误
_, ratioSuccess, matchName := ratio_setting.GetModelRatio(info.OriginModelName)
if !ratioSuccess {
} else {
// 没有配置倍率也不接受没配置,那就返回错误
_, ratioSuccess, matchName := ratio_setting.GetModelRatio(info.OriginModelName)
acceptUnsetRatio := false
if info.UserSetting.AcceptUnsetRatioModel {
acceptUnsetRatio = true
}
if !acceptUnsetRatio {
if !ratioSuccess && !acceptUnsetRatio {
return types.PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请联系管理员设置或开始自用模式;Model %s ratio or price not set, please set or start self-use mode", matchName, matchName)
}
// 未配置价格但配置了倍率,使用默认预扣价格
modelPrice = float64(common.PreConsumedQuota) / common.QuotaPerUnit
}

}
Expand Down