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
Unverified
Commit
49648d8b
authored
Apr 08, 2026
by
Calcium-Ion
Committed by
GitHub
Apr 08, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4128 from zuiho-kai/fix/claude-stream-usage-overwrite
fix: Claude 流式断流时不再整份覆盖 usage,保留 cache 计费字段
parents
48695e0e
c66636a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletions
+10
-1
relay/channel/claude/relay-claude.go
+10
-1
No files found.
relay/channel/claude/relay-claude.go
View file @
49648d8b
...
@@ -809,7 +809,16 @@ func HandleStreamFinalResponse(c *gin.Context, info *relaycommon.RelayInfo, clau
...
@@ -809,7 +809,16 @@ func HandleStreamFinalResponse(c *gin.Context, info *relaycommon.RelayInfo, clau
if
common
.
DebugEnabled
{
if
common
.
DebugEnabled
{
common
.
SysLog
(
"claude response usage is not complete, maybe upstream error"
)
common
.
SysLog
(
"claude response usage is not complete, maybe upstream error"
)
}
}
claudeInfo
.
Usage
=
service
.
ResponseText2Usage
(
c
,
claudeInfo
.
ResponseText
.
String
(),
info
.
UpstreamModelName
,
claudeInfo
.
Usage
.
PromptTokens
)
// 只补缺失字段,不整份覆盖——保留 message_start 已拿到的 cache 字段
fallback
:=
service
.
ResponseText2Usage
(
c
,
claudeInfo
.
ResponseText
.
String
(),
info
.
UpstreamModelName
,
info
.
GetEstimatePromptTokens
())
if
claudeInfo
.
Usage
.
CompletionTokens
==
0
||
(
!
claudeInfo
.
Done
&&
fallback
.
CompletionTokens
>
claudeInfo
.
Usage
.
CompletionTokens
)
{
claudeInfo
.
Usage
.
CompletionTokens
=
fallback
.
CompletionTokens
}
if
claudeInfo
.
Usage
.
PromptTokens
==
0
{
claudeInfo
.
Usage
.
PromptTokens
=
fallback
.
PromptTokens
}
claudeInfo
.
Usage
.
TotalTokens
=
claudeInfo
.
Usage
.
PromptTokens
+
claudeInfo
.
Usage
.
CompletionTokens
}
}
if
claudeInfo
.
Usage
!=
nil
{
if
claudeInfo
.
Usage
!=
nil
{
claudeInfo
.
Usage
.
UsageSemantic
=
"anthropic"
claudeInfo
.
Usage
.
UsageSemantic
=
"anthropic"
...
...
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