@@ -482,10 +482,12 @@ type ClaudeUsage struct {
482482
483483// ForwardResult 转发结果
484484type ForwardResult struct {
485- RequestID string
486- Usage ClaudeUsage
487- Model string
488- UpstreamModel string // Actual upstream model after mapping (empty = no mapping)
485+ RequestID string
486+ Usage ClaudeUsage
487+ Model string
488+ // UpstreamModel is the actual upstream model after mapping.
489+ // Prefer empty when it is identical to Model; persistence normalizes equal values away as no-op mappings.
490+ UpstreamModel string
489491 Stream bool
490492 Duration time.Duration
491493 FirstTokenMs * int // 首字时间(流式请求)
@@ -7516,6 +7518,7 @@ func (s *GatewayService) RecordUsage(ctx context.Context, input *RecordUsageInpu
75167518 }
75177519
75187520 var cost * CostBreakdown
7521+ billingModel := forwardResultBillingModel (result .Model , result .UpstreamModel )
75197522
75207523 // 根据请求类型选择计费方式
75217524 if result .MediaType == "image" || result .MediaType == "video" {
@@ -7531,7 +7534,7 @@ func (s *GatewayService) RecordUsage(ctx context.Context, input *RecordUsageInpu
75317534 if result .MediaType == "image" {
75327535 cost = s .billingService .CalculateSoraImageCost (result .ImageSize , result .ImageCount , soraConfig , multiplier )
75337536 } else {
7534- cost = s .billingService .CalculateSoraVideoCost (result . Model , soraConfig , multiplier )
7537+ cost = s .billingService .CalculateSoraVideoCost (billingModel , soraConfig , multiplier )
75357538 }
75367539 } else if result .MediaType == "prompt" {
75377540 cost = & CostBreakdown {}
@@ -7545,7 +7548,7 @@ func (s *GatewayService) RecordUsage(ctx context.Context, input *RecordUsageInpu
75457548 Price4K : apiKey .Group .ImagePrice4K ,
75467549 }
75477550 }
7548- cost = s .billingService .CalculateImageCost (result . Model , result .ImageSize , result .ImageCount , groupConfig , multiplier )
7551+ cost = s .billingService .CalculateImageCost (billingModel , result .ImageSize , result .ImageCount , groupConfig , multiplier )
75497552 } else {
75507553 // Token 计费
75517554 tokens := UsageTokens {
@@ -7557,7 +7560,7 @@ func (s *GatewayService) RecordUsage(ctx context.Context, input *RecordUsageInpu
75577560 CacheCreation1hTokens : result .Usage .CacheCreation1hTokens ,
75587561 }
75597562 var err error
7560- cost , err = s .billingService .CalculateCost (result . Model , tokens , multiplier )
7563+ cost , err = s .billingService .CalculateCost (billingModel , tokens , multiplier )
75617564 if err != nil {
75627565 logger .LegacyPrintf ("service.gateway" , "Calculate cost failed: %v" , err )
75637566 cost = & CostBreakdown {ActualCost : 0 }
@@ -7589,6 +7592,7 @@ func (s *GatewayService) RecordUsage(ctx context.Context, input *RecordUsageInpu
75897592 AccountID : account .ID ,
75907593 RequestID : requestID ,
75917594 Model : result .Model ,
7595+ RequestedModel : result .Model ,
75927596 UpstreamModel : optionalNonEqualStringPtr (result .UpstreamModel , result .Model ),
75937597 ReasoningEffort : result .ReasoningEffort ,
75947598 InboundEndpoint : optionalTrimmedStringPtr (input .InboundEndpoint ),
@@ -7719,6 +7723,7 @@ func (s *GatewayService) RecordUsageWithLongContext(ctx context.Context, input *
77197723 }
77207724
77217725 var cost * CostBreakdown
7726+ billingModel := forwardResultBillingModel (result .Model , result .UpstreamModel )
77227727
77237728 // 根据请求类型选择计费方式
77247729 if result .ImageCount > 0 {
@@ -7731,7 +7736,7 @@ func (s *GatewayService) RecordUsageWithLongContext(ctx context.Context, input *
77317736 Price4K : apiKey .Group .ImagePrice4K ,
77327737 }
77337738 }
7734- cost = s .billingService .CalculateImageCost (result . Model , result .ImageSize , result .ImageCount , groupConfig , multiplier )
7739+ cost = s .billingService .CalculateImageCost (billingModel , result .ImageSize , result .ImageCount , groupConfig , multiplier )
77357740 } else {
77367741 // Token 计费(使用长上下文计费方法)
77377742 tokens := UsageTokens {
@@ -7743,7 +7748,7 @@ func (s *GatewayService) RecordUsageWithLongContext(ctx context.Context, input *
77437748 CacheCreation1hTokens : result .Usage .CacheCreation1hTokens ,
77447749 }
77457750 var err error
7746- cost , err = s .billingService .CalculateCostWithLongContext (result . Model , tokens , multiplier , input .LongContextThreshold , input .LongContextMultiplier )
7751+ cost , err = s .billingService .CalculateCostWithLongContext (billingModel , tokens , multiplier , input .LongContextThreshold , input .LongContextMultiplier )
77477752 if err != nil {
77487753 logger .LegacyPrintf ("service.gateway" , "Calculate cost failed: %v" , err )
77497754 cost = & CostBreakdown {ActualCost : 0 }
@@ -7771,6 +7776,7 @@ func (s *GatewayService) RecordUsageWithLongContext(ctx context.Context, input *
77717776 AccountID : account .ID ,
77727777 RequestID : requestID ,
77737778 Model : result .Model ,
7779+ RequestedModel : result .Model ,
77747780 UpstreamModel : optionalNonEqualStringPtr (result .UpstreamModel , result .Model ),
77757781 ReasoningEffort : result .ReasoningEffort ,
77767782 InboundEndpoint : optionalTrimmedStringPtr (input .InboundEndpoint ),
0 commit comments