diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index f03dfd0593..c74c5ae758 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.110.26 +0.1.110.27 diff --git a/backend/internal/service/account_stats_pricing.go b/backend/internal/service/account_stats_pricing.go index e47b743164..fd67c4ffa1 100644 --- a/backend/internal/service/account_stats_pricing.go +++ b/backend/internal/service/account_stats_pricing.go @@ -10,10 +10,12 @@ import ( // // 优先级(先命中为准): // 1. 自定义规则(始终尝试,不依赖 ApplyPricingToAccountStats 开关) -// 2. ApplyPricingToAccountStats 启用时,用模型定价文件(LiteLLM)中上游模型的标准价格计算 -// 3. nil → 走默认公式 +// 2. ApplyPricingToAccountStats 启用时,直接使用本次请求的客户计费(倍率前的 totalCost) +// 3. 模型定价文件(LiteLLM)中上游模型的默认价格 +// 4. nil → 走默认公式(total_cost × account_rate_multiplier) // // upstreamModel 是最终发往上游的模型 ID。 +// totalCost 是本次请求的客户计费(倍率前),用于优先级 2。 func resolveAccountStatsCost( ctx context.Context, channelService *ChannelService, @@ -23,6 +25,7 @@ func resolveAccountStatsCost( upstreamModel string, tokens UsageTokens, requestCount int, + totalCost float64, ) *float64 { if channelService == nil || upstreamModel == "" { return nil @@ -39,8 +42,17 @@ func resolveAccountStatsCost( return cost } - // 优先级 2:模型定价文件(LiteLLM/fallback)中上游模型的标准价格 - if channel.ApplyPricingToAccountStats && billingService != nil { + // 优先级 2:渠道开启"应用模型定价到账号统计"时,直接使用客户计费(倍率前) + if channel.ApplyPricingToAccountStats { + cost := totalCost + if cost <= 0 { + return nil + } + return &cost + } + + // 优先级 3:模型定价文件(LiteLLM)默认价格 + if billingService != nil { return tryModelFilePricing(billingService, upstreamModel, tokens) } diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index 70f90d4fdd..32c96de22d 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -7837,6 +7837,7 @@ func (s *GatewayService) recordUsageCore(ctx context.Context, input *recordUsage ImageOutputTokens: result.Usage.ImageOutputTokens, }, 1, // requestCount + cost.TotalCost, ) } diff --git a/backend/internal/service/openai_gateway_service.go b/backend/internal/service/openai_gateway_service.go index 77ec3a44aa..3eb71bed30 100644 --- a/backend/internal/service/openai_gateway_service.go +++ b/backend/internal/service/openai_gateway_service.go @@ -4582,7 +4582,7 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec usageLog.AccountStatsCost = resolveAccountStatsCost( ctx, s.channelService, s.billingService, account.ID, *apiKey.GroupID, statsModel, - tokens, 1, + tokens, 1, cost.TotalCost, ) }