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
68e1e635
authored
Jan 25, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: logs show reject reason
parent
7af4d078
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
0 deletions
+33
-0
constant/context_key.go
+4
-0
model/log.go
+1
-0
relay/channel/gemini/relay-gemini-native.go
+6
-0
relay/channel/gemini/relay-gemini.go
+6
-0
relay/channel/openai/relay-openai.go
+7
-0
relay/compatible_handler.go
+6
-0
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx
+3
-0
No files found.
constant/context_key.go
View file @
68e1e635
...
...
@@ -55,4 +55,8 @@ const (
ContextKeyLocalCountTokens
ContextKey
=
"local_count_tokens"
ContextKeySystemPromptOverride
ContextKey
=
"system_prompt_override"
// ContextKeyAdminRejectReason stores an admin-only reject/block reason extracted from upstream responses.
// It is not returned to end users, but can be persisted into consume/error logs for debugging.
ContextKeyAdminRejectReason
ContextKey
=
"admin_reject_reason"
)
model/log.go
View file @
68e1e635
...
...
@@ -59,6 +59,7 @@ func formatUserLogs(logs []*Log) {
// Remove admin-only debug fields.
delete
(
otherMap
,
"admin_info"
)
delete
(
otherMap
,
"request_conversion"
)
delete
(
otherMap
,
"reject_reason"
)
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
logs
[
i
]
.
Id
=
logs
[
i
]
.
Id
%
1024
...
...
relay/channel/gemini/relay-gemini-native.go
View file @
68e1e635
package
gemini
import
(
"fmt"
"io"
"net/http"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/logger"
relaycommon
"github.com/QuantumNous/new-api/relay/common"
...
...
@@ -35,6 +37,10 @@ func GeminiTextGenerationHandler(c *gin.Context, info *relaycommon.RelayInfo, re
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeBadResponseBody
,
http
.
StatusInternalServerError
)
}
if
len
(
geminiResponse
.
Candidates
)
==
0
&&
geminiResponse
.
PromptFeedback
!=
nil
&&
geminiResponse
.
PromptFeedback
.
BlockReason
!=
nil
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyAdminRejectReason
,
fmt
.
Sprintf
(
"gemini_block_reason=%s"
,
*
geminiResponse
.
PromptFeedback
.
BlockReason
))
}
// 计算使用量(基于 UsageMetadata)
usage
:=
dto
.
Usage
{
PromptTokens
:
geminiResponse
.
UsageMetadata
.
PromptTokenCount
,
...
...
relay/channel/gemini/relay-gemini.go
View file @
68e1e635
...
...
@@ -1197,6 +1197,10 @@ func geminiStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http
return
false
}
if
len
(
geminiResponse
.
Candidates
)
==
0
&&
geminiResponse
.
PromptFeedback
!=
nil
&&
geminiResponse
.
PromptFeedback
.
BlockReason
!=
nil
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyAdminRejectReason
,
fmt
.
Sprintf
(
"gemini_block_reason=%s"
,
*
geminiResponse
.
PromptFeedback
.
BlockReason
))
}
// 统计图片数量
for
_
,
candidate
:=
range
geminiResponse
.
Candidates
{
for
_
,
part
:=
range
candidate
.
Content
.
Parts
{
...
...
@@ -1372,12 +1376,14 @@ func GeminiChatHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.R
var
newAPIError
*
types
.
NewAPIError
if
geminiResponse
.
PromptFeedback
!=
nil
&&
geminiResponse
.
PromptFeedback
.
BlockReason
!=
nil
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyAdminRejectReason
,
fmt
.
Sprintf
(
"gemini_block_reason=%s"
,
*
geminiResponse
.
PromptFeedback
.
BlockReason
))
newAPIError
=
types
.
NewOpenAIError
(
errors
.
New
(
"request blocked by Gemini API: "
+*
geminiResponse
.
PromptFeedback
.
BlockReason
),
types
.
ErrorCodePromptBlocked
,
http
.
StatusBadRequest
,
)
}
else
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyAdminRejectReason
,
"gemini_empty_candidates"
)
newAPIError
=
types
.
NewOpenAIError
(
errors
.
New
(
"empty response from Gemini API"
),
types
.
ErrorCodeEmptyResponse
,
...
...
relay/channel/openai/relay-openai.go
View file @
68e1e635
...
...
@@ -229,6 +229,13 @@ func OpenaiHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Respo
return
nil
,
types
.
WithOpenAIError
(
*
oaiError
,
resp
.
StatusCode
)
}
for
_
,
choice
:=
range
simpleResponse
.
Choices
{
if
choice
.
FinishReason
==
constant
.
FinishReasonContentFilter
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyAdminRejectReason
,
"openai_finish_reason=content_filter"
)
break
}
}
forceFormat
:=
false
if
info
.
ChannelSetting
.
ForceFormat
{
forceFormat
=
true
...
...
relay/compatible_handler.go
View file @
68e1e635
...
...
@@ -237,6 +237,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
}
extraContent
=
append
(
extraContent
,
"上游无计费信息"
)
}
adminRejectReason
:=
common
.
GetContextKeyString
(
ctx
,
constant
.
ContextKeyAdminRejectReason
)
useTimeSeconds
:=
time
.
Now
()
.
Unix
()
-
relayInfo
.
StartTime
.
Unix
()
promptTokens
:=
usage
.
PromptTokens
cacheTokens
:=
usage
.
PromptTokensDetails
.
CachedTokens
...
...
@@ -461,6 +464,9 @@ 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
)
if
adminRejectReason
!=
""
{
other
[
"reject_reason"
]
=
adminRejectReason
}
// 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
...
...
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx
View file @
68e1e635
...
...
@@ -578,6 +578,9 @@ export const getLogsColumns = ({
other
?.
is_system_prompt_overwritten
,
'openai'
,
);
if
(
isAdminUser
&&
other
?.
reject_reason
)
{
content
+=
`\nBlock reason:
${
other
.
reject_reason
}
`
;
}
return
(
<
Typography
.
Paragraph
ellipsis=
{
{
...
...
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