Commit 0fbc9a44 authored by erio's avatar erio
Browse files

fix(billing): 按次计费回退到默认 PerRequestPrice

ResolvedPricing 新增 DefaultPerRequestPrice,当无层级匹配时使用渠道的默认按次价格
parent 632035aa
...@@ -542,6 +542,11 @@ func (s *BillingService) calculatePerRequestCost(resolved *ResolvedPricing, inpu ...@@ -542,6 +542,11 @@ func (s *BillingService) calculatePerRequestCost(resolved *ResolvedPricing, inpu
unitPrice = input.Resolver.GetRequestTierPriceByContext(resolved, totalContext) unitPrice = input.Resolver.GetRequestTierPriceByContext(resolved, totalContext)
} }
// 回退到默认按次价格
if unitPrice == 0 {
unitPrice = resolved.DefaultPerRequestPrice
}
totalCost := unitPrice * float64(count) totalCost := unitPrice * float64(count)
actualCost := totalCost * input.RateMultiplier actualCost := totalCost * input.RateMultiplier
......
...@@ -19,6 +19,9 @@ type ResolvedPricing struct { ...@@ -19,6 +19,9 @@ type ResolvedPricing struct {
// 按次/图片模式:分层定价 // 按次/图片模式:分层定价
RequestTiers []PricingInterval RequestTiers []PricingInterval
// 按次/图片模式:默认价格(未命中层级时使用)
DefaultPerRequestPrice float64
// 来源标识 // 来源标识
Source string // "channel", "litellm", "fallback" Source string // "channel", "litellm", "fallback"
...@@ -136,6 +139,9 @@ func (r *ModelPricingResolver) applyTokenOverrides(chPricing *ChannelModelPricin ...@@ -136,6 +139,9 @@ func (r *ModelPricingResolver) applyTokenOverrides(chPricing *ChannelModelPricin
// applyRequestTierOverrides 应用按次/图片模式的渠道覆盖 // applyRequestTierOverrides 应用按次/图片模式的渠道覆盖
func (r *ModelPricingResolver) applyRequestTierOverrides(chPricing *ChannelModelPricing, resolved *ResolvedPricing) { func (r *ModelPricingResolver) applyRequestTierOverrides(chPricing *ChannelModelPricing, resolved *ResolvedPricing) {
resolved.RequestTiers = chPricing.Intervals resolved.RequestTiers = chPricing.Intervals
if chPricing.PerRequestPrice != nil {
resolved.DefaultPerRequestPrice = *chPricing.PerRequestPrice
}
} }
// GetIntervalPricing 根据 context token 数获取区间定价。 // GetIntervalPricing 根据 context token 数获取区间定价。
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment