Merge pull request #2477 from 1420970597/fix/anthropic-cache-billing
fix: 修复 Anthropic 渠道缓存计费错误
This commit is contained in:
commit
3955d61b3e
@ -300,14 +300,20 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
|
|||||||
if !relayInfo.PriceData.UsePrice {
|
if !relayInfo.PriceData.UsePrice {
|
||||||
baseTokens := dPromptTokens
|
baseTokens := dPromptTokens
|
||||||
// 减去 cached tokens
|
// 减去 cached tokens
|
||||||
|
// Anthropic API 的 input_tokens 已经不包含缓存 tokens,不需要减去
|
||||||
|
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
|
||||||
var cachedTokensWithRatio decimal.Decimal
|
var cachedTokensWithRatio decimal.Decimal
|
||||||
if !dCacheTokens.IsZero() {
|
if !dCacheTokens.IsZero() {
|
||||||
baseTokens = baseTokens.Sub(dCacheTokens)
|
if relayInfo.ChannelType != constant.ChannelTypeAnthropic {
|
||||||
|
baseTokens = baseTokens.Sub(dCacheTokens)
|
||||||
|
}
|
||||||
cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio)
|
cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio)
|
||||||
}
|
}
|
||||||
var dCachedCreationTokensWithRatio decimal.Decimal
|
var dCachedCreationTokensWithRatio decimal.Decimal
|
||||||
if !dCachedCreationTokens.IsZero() {
|
if !dCachedCreationTokens.IsZero() {
|
||||||
baseTokens = baseTokens.Sub(dCachedCreationTokens)
|
if relayInfo.ChannelType != constant.ChannelTypeAnthropic {
|
||||||
|
baseTokens = baseTokens.Sub(dCachedCreationTokens)
|
||||||
|
}
|
||||||
dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio)
|
dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user