feat: /v1/messages端点适配codex账号池

This commit is contained in:
shaw
2026-03-06 22:39:33 +08:00
parent afbe8bf001
commit 921599948b
7 changed files with 341 additions and 297 deletions

View File

@@ -207,7 +207,12 @@ type OpenAIUsage struct {
type OpenAIForwardResult struct {
RequestID string
Usage OpenAIUsage
Model string
Model string // 原始模型(用于响应和日志显示)
// BillingModel is the model used for cost calculation.
// When non-empty, CalculateCost uses this instead of Model.
// This is set by the Anthropic Messages conversion path where
// the mapped upstream model differs from the client-facing model.
BillingModel string
// ReasoningEffort is extracted from request body (reasoning.effort) or derived from model suffix.
// Stored for usage records display; nil means not provided / not applicable.
ReasoningEffort *string
@@ -3610,7 +3615,11 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec
multiplier = resolver.Resolve(ctx, user.ID, *apiKey.GroupID, apiKey.Group.RateMultiplier)
}
cost, err := s.billingService.CalculateCost(result.Model, tokens, multiplier)
billingModel := result.Model
if result.BillingModel != "" {
billingModel = result.BillingModel
}
cost, err := s.billingService.CalculateCost(billingModel, tokens, multiplier)
if err != nil {
cost = &CostBreakdown{ActualCost: 0}
}
@@ -3630,7 +3639,7 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec
APIKeyID: apiKey.ID,
AccountID: account.ID,
RequestID: result.RequestID,
Model: result.Model,
Model: billingModel,
ReasoningEffort: result.ReasoningEffort,
InputTokens: actualInputTokens,
OutputTokens: result.Usage.OutputTokens,