diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index 8775ce89..c74c5ae7 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.110.24 +0.1.110.27 diff --git a/backend/internal/service/account_stats_pricing.go b/backend/internal/service/account_stats_pricing.go index cbe9c76c..8251dede 100644 --- a/backend/internal/service/account_stats_pricing.go +++ b/backend/internal/service/account_stats_pricing.go @@ -11,10 +11,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, @@ -24,6 +26,7 @@ func resolveAccountStatsCost( upstreamModel string, tokens UsageTokens, requestCount int, + totalCost float64, ) *float64 { if channelService == nil || upstreamModel == "" { return nil @@ -40,8 +43,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 5267156d..b67a06a7 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -7598,6 +7598,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 e060b981..9a6fbb8f 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, ) }