Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3955d61b
authored
Dec 24, 2025
by
Calcium-Ion
Committed by
GitHub
Dec 24, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2477 from 1420970597/fix/anthropic-cache-billing
fix: 修复 Anthropic 渠道缓存计费错误
parents
07cb6e96
6e3bc06f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
relay/compatible_handler.go
+8
-2
No files found.
relay/compatible_handler.go
View file @
3955d61b
...
...
@@ -300,14 +300,20 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
if
!
relayInfo
.
PriceData
.
UsePrice
{
baseTokens
:=
dPromptTokens
// 减去 cached tokens
// Anthropic API 的 input_tokens 已经不包含缓存 tokens,不需要减去
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
var
cachedTokensWithRatio
decimal
.
Decimal
if
!
dCacheTokens
.
IsZero
()
{
baseTokens
=
baseTokens
.
Sub
(
dCacheTokens
)
if
relayInfo
.
ChannelType
!=
constant
.
ChannelTypeAnthropic
{
baseTokens
=
baseTokens
.
Sub
(
dCacheTokens
)
}
cachedTokensWithRatio
=
dCacheTokens
.
Mul
(
dCacheRatio
)
}
var
dCachedCreationTokensWithRatio
decimal
.
Decimal
if
!
dCachedCreationTokens
.
IsZero
()
{
baseTokens
=
baseTokens
.
Sub
(
dCachedCreationTokens
)
if
relayInfo
.
ChannelType
!=
constant
.
ChannelTypeAnthropic
{
baseTokens
=
baseTokens
.
Sub
(
dCachedCreationTokens
)
}
dCachedCreationTokensWithRatio
=
dCachedCreationTokens
.
Mul
(
dCachedCreationRatio
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment