diff --git a/relay/compatible_handler.go b/relay/compatible_handler.go index 6c36f83d2..1a534f588 100644 --- a/relay/compatible_handler.go +++ b/relay/compatible_handler.go @@ -335,6 +335,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage var audioInputQuota decimal.Decimal var audioInputPrice float64 + isClaudeUsageSemantic := relayInfo.ChannelType == constant.ChannelTypeAnthropic if !relayInfo.PriceData.UsePrice { baseTokens := dPromptTokens // 减去 cached tokens @@ -342,14 +343,14 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage // OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去 var cachedTokensWithRatio decimal.Decimal if !dCacheTokens.IsZero() { - if relayInfo.ChannelType != constant.ChannelTypeAnthropic { + if !isClaudeUsageSemantic { baseTokens = baseTokens.Sub(dCacheTokens) } cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio) } var dCachedCreationTokensWithRatio decimal.Decimal if !dCachedCreationTokens.IsZero() { - if relayInfo.ChannelType != constant.ChannelTypeAnthropic { + if !isClaudeUsageSemantic { baseTokens = baseTokens.Sub(dCachedCreationTokens) } dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio) @@ -459,6 +460,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage } logContent := strings.Join(extraContent, ", ") other := service.GenerateTextOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio, cacheTokens, cacheRatio, modelPrice, relayInfo.PriceData.GroupRatioInfo.GroupSpecialRatio) + // For chat-based calls to the Claude model, tagging is required. Using Claude's rendering logs, the two approaches handle input rendering differently. + if isClaudeUsageSemantic { + other["claude"] = true + other["usage_semantic"] = "anthropic" + } if imageTokens != 0 { other["image"] = true other["image_ratio"] = imageRatio