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
5c1d43fc
authored
Jan 15, 2026
by
Seefs
Committed by
GitHub
Jan 15, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2670 from seefs001/fix/chat2claude-log
parents
2a15e3b1
f9c7daed
Show 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 @
5c1d43fc
...
@@ -335,6 +335,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
...
@@ -335,6 +335,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
var
audioInputQuota
decimal
.
Decimal
var
audioInputQuota
decimal
.
Decimal
var
audioInputPrice
float64
var
audioInputPrice
float64
isClaudeUsageSemantic
:=
relayInfo
.
ChannelType
==
constant
.
ChannelTypeAnthropic
if
!
relayInfo
.
PriceData
.
UsePrice
{
if
!
relayInfo
.
PriceData
.
UsePrice
{
baseTokens
:=
dPromptTokens
baseTokens
:=
dPromptTokens
// 减去 cached tokens
// 减去 cached tokens
...
@@ -342,14 +343,14 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
...
@@ -342,14 +343,14 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
var
cachedTokensWithRatio
decimal
.
Decimal
var
cachedTokensWithRatio
decimal
.
Decimal
if
!
dCacheTokens
.
IsZero
()
{
if
!
dCacheTokens
.
IsZero
()
{
if
relayInfo
.
ChannelType
!=
constant
.
ChannelTypeAnthrop
ic
{
if
!
isClaudeUsageSemant
ic
{
baseTokens
=
baseTokens
.
Sub
(
dCacheTokens
)
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
()
{
if
relayInfo
.
ChannelType
!=
constant
.
ChannelTypeAnthrop
ic
{
if
!
isClaudeUsageSemant
ic
{
baseTokens
=
baseTokens
.
Sub
(
dCachedCreationTokens
)
baseTokens
=
baseTokens
.
Sub
(
dCachedCreationTokens
)
}
}
dCachedCreationTokensWithRatio
=
dCachedCreationTokens
.
Mul
(
dCachedCreationRatio
)
dCachedCreationTokensWithRatio
=
dCachedCreationTokens
.
Mul
(
dCachedCreationRatio
)
...
@@ -459,6 +460,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
...
@@ -459,6 +460,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
}
}
logContent
:=
strings
.
Join
(
extraContent
,
", "
)
logContent
:=
strings
.
Join
(
extraContent
,
", "
)
other
:=
service
.
GenerateTextOtherInfo
(
ctx
,
relayInfo
,
modelRatio
,
groupRatio
,
completionRatio
,
cacheTokens
,
cacheRatio
,
modelPrice
,
relayInfo
.
PriceData
.
GroupRatioInfo
.
GroupSpecialRatio
)
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
{
if
imageTokens
!=
0
{
other
[
"image"
]
=
true
other
[
"image"
]
=
true
other
[
"image_ratio"
]
=
imageRatio
other
[
"image_ratio"
]
=
imageRatio
...
...
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