Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
2c31bf46
Unverified
Commit
2c31bf46
authored
Jan 28, 2026
by
Wesley Liddick
Committed by
GitHub
Jan 28, 2026
Browse files
Merge pull request #401 from slovx2/heihuzi_main
feat(gemini): 为 Gemini 原生平台添加图片计费支持
parents
56a1e29c
0059a232
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gemini_messages_compat_service.go
View file @
2c31bf46
...
...
@@ -931,6 +931,13 @@ func (s *GeminiMessagesCompatService) Forward(ctx context.Context, c *gin.Contex
}
}
// 图片生成计费
imageCount
:=
0
imageSize
:=
s
.
extractImageSize
(
body
)
if
isImageGenerationModel
(
originalModel
)
{
imageCount
=
1
}
return
&
ForwardResult
{
RequestID
:
requestID
,
Usage
:
*
usage
,
...
...
@@ -938,6 +945,8 @@ func (s *GeminiMessagesCompatService) Forward(ctx context.Context, c *gin.Contex
Stream
:
req
.
Stream
,
Duration
:
time
.
Since
(
startTime
),
FirstTokenMs
:
firstTokenMs
,
ImageCount
:
imageCount
,
ImageSize
:
imageSize
,
},
nil
}
...
...
@@ -1371,6 +1380,13 @@ func (s *GeminiMessagesCompatService) ForwardNative(ctx context.Context, c *gin.
usage
=
&
ClaudeUsage
{}
}
// 图片生成计费
imageCount
:=
0
imageSize
:=
s
.
extractImageSize
(
body
)
if
isImageGenerationModel
(
originalModel
)
{
imageCount
=
1
}
return
&
ForwardResult
{
RequestID
:
requestID
,
Usage
:
*
usage
,
...
...
@@ -1378,6 +1394,8 @@ func (s *GeminiMessagesCompatService) ForwardNative(ctx context.Context, c *gin.
Stream
:
stream
,
Duration
:
time
.
Since
(
startTime
),
FirstTokenMs
:
firstTokenMs
,
ImageCount
:
imageCount
,
ImageSize
:
imageSize
,
},
nil
}
...
...
@@ -3031,3 +3049,26 @@ func convertClaudeGenerationConfig(req map[string]any) map[string]any {
}
return
out
}
// extractImageSize 从 Gemini 请求中提取 image_size 参数
func
(
s
*
GeminiMessagesCompatService
)
extractImageSize
(
body
[]
byte
)
string
{
var
req
struct
{
GenerationConfig
*
struct
{
ImageConfig
*
struct
{
ImageSize
string
`json:"imageSize"`
}
`json:"imageConfig"`
}
`json:"generationConfig"`
}
if
err
:=
json
.
Unmarshal
(
body
,
&
req
);
err
!=
nil
{
return
"2K"
}
if
req
.
GenerationConfig
!=
nil
&&
req
.
GenerationConfig
.
ImageConfig
!=
nil
{
size
:=
strings
.
ToUpper
(
strings
.
TrimSpace
(
req
.
GenerationConfig
.
ImageConfig
.
ImageSize
))
if
size
==
"1K"
||
size
==
"2K"
||
size
==
"4K"
{
return
size
}
}
return
"2K"
}
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