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
7af4d078
authored
Jan 25, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Charge locally even if there's an error
parent
c09c2725
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
relay/channel/gemini/relay-gemini.go
+33
-4
No files found.
relay/channel/gemini/relay-gemini.go
View file @
7af4d078
...
...
@@ -1355,20 +1355,50 @@ func GeminiChatHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.R
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeBadResponseBody
,
http
.
StatusInternalServerError
)
}
if
len
(
geminiResponse
.
Candidates
)
==
0
{
// [FIX] Return meaningful error when Candidates is empty
usage
:=
dto
.
Usage
{
PromptTokens
:
geminiResponse
.
UsageMetadata
.
PromptTokenCount
,
}
usage
.
CompletionTokenDetails
.
ReasoningTokens
=
geminiResponse
.
UsageMetadata
.
ThoughtsTokenCount
for
_
,
detail
:=
range
geminiResponse
.
UsageMetadata
.
PromptTokensDetails
{
if
detail
.
Modality
==
"AUDIO"
{
usage
.
PromptTokensDetails
.
AudioTokens
=
detail
.
TokenCount
}
else
if
detail
.
Modality
==
"TEXT"
{
usage
.
PromptTokensDetails
.
TextTokens
=
detail
.
TokenCount
}
}
if
usage
.
PromptTokens
<=
0
{
usage
.
PromptTokens
=
info
.
GetEstimatePromptTokens
()
}
var
newAPIError
*
types
.
NewAPIError
if
geminiResponse
.
PromptFeedback
!=
nil
&&
geminiResponse
.
PromptFeedback
.
BlockReason
!=
nil
{
return
nil
,
types
.
NewOpenAIError
(
newAPIError
=
types
.
NewOpenAIError
(
errors
.
New
(
"request blocked by Gemini API: "
+*
geminiResponse
.
PromptFeedback
.
BlockReason
),
types
.
ErrorCodePromptBlocked
,
http
.
StatusBadRequest
,
)
}
else
{
return
nil
,
types
.
NewOpenAIError
(
newAPIError
=
types
.
NewOpenAIError
(
errors
.
New
(
"empty response from Gemini API"
),
types
.
ErrorCodeEmptyResponse
,
http
.
StatusInternalServerError
,
)
}
service
.
ResetStatusCode
(
newAPIError
,
c
.
GetString
(
"status_code_mapping"
))
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
c
.
JSON
(
newAPIError
.
StatusCode
,
gin
.
H
{
"type"
:
"error"
,
"error"
:
newAPIError
.
ToClaudeError
(),
})
default
:
c
.
JSON
(
newAPIError
.
StatusCode
,
gin
.
H
{
"error"
:
newAPIError
.
ToOpenAIError
(),
})
}
return
&
usage
,
nil
}
fullTextResponse
:=
responseGeminiChat2OpenAI
(
c
,
&
geminiResponse
)
fullTextResponse
.
Model
=
info
.
UpstreamModelName
...
...
@@ -1643,4 +1673,3 @@ func convertToolChoiceToGeminiConfig(toolChoice any) *dto.ToolConfig {
// Unsupported type, return nil
return
nil
}
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