feat(billing): 网关计费迁移到 CalculateCostUnified + 模型限制错误统一
- GatewayService/OpenAIGatewayService 注入 ModelPricingResolver - RecordUsage 从旧路径迁移到 CalculateCostUnified(支持 per_request/image 模式) - 无渠道时自动回退旧路径,保持原有行为 - 长上下文双倍计费仅在无渠道定价时生效 - CostBreakdown 新增 BillingMode 字段,使用日志记录实际计费模式 - 模型限制错误改为与"无可用账号"相同的 503 响应
This commit is contained in:
@@ -104,6 +104,7 @@ type CostBreakdown struct {
|
||||
CacheReadCost float64
|
||||
TotalCost float64
|
||||
ActualCost float64 // 应用倍率后的实际费用
|
||||
BillingMode string // 计费模式("token"/"per_request"/"image"),由 CalculateCostUnified 填充
|
||||
}
|
||||
|
||||
// BillingService 计费服务
|
||||
@@ -439,12 +440,21 @@ func (s *BillingService) CalculateCostUnified(input CostInput) (*CostBreakdown,
|
||||
input.RateMultiplier = 1.0
|
||||
}
|
||||
|
||||
var breakdown *CostBreakdown
|
||||
var err error
|
||||
switch resolved.Mode {
|
||||
case BillingModePerRequest, BillingModeImage:
|
||||
return s.calculatePerRequestCost(resolved, input)
|
||||
breakdown, err = s.calculatePerRequestCost(resolved, input)
|
||||
default: // BillingModeToken
|
||||
return s.calculateTokenCost(resolved, input)
|
||||
breakdown, err = s.calculateTokenCost(resolved, input)
|
||||
}
|
||||
if err == nil && breakdown != nil {
|
||||
breakdown.BillingMode = string(resolved.Mode)
|
||||
if breakdown.BillingMode == "" {
|
||||
breakdown.BillingMode = string(BillingModeToken)
|
||||
}
|
||||
}
|
||||
return breakdown, err
|
||||
}
|
||||
|
||||
// calculateTokenCost 按 token 区间计费
|
||||
|
||||
Reference in New Issue
Block a user