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
89fe99f3
authored
Apr 02, 2026
by
Calcium-Ion
Committed by
GitHub
Apr 02, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3512 from imlhb/patch-2
fix: prevent double-counting of image count n in billing
parents
5b47011e
ab99c308
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
10 deletions
+16
-10
dto/openai_image.go
+5
-6
relay/channel/ali/image.go
+0
-2
relay/image_handler.go
+11
-2
No files found.
dto/openai_image.go
View file @
89fe99f3
...
...
@@ -148,15 +148,14 @@ func (i *ImageRequest) GetTokenCountMeta() *types.TokenCountMeta {
}
}
// not support token count for dalle
n
:=
uint
(
1
)
if
i
.
N
!=
nil
{
n
=
*
i
.
N
}
// n is NOT included here; it is handled via OtherRatio("n") in
// image_handler.go (default) or channel adaptors (actual count).
// Including n here caused double-counting for channels that also
// set OtherRatio("n") (e.g. Ali/Bailian).
return
&
types
.
TokenCountMeta
{
CombineText
:
i
.
Prompt
,
MaxTokens
:
1584
,
ImagePriceRatio
:
sizeRatio
*
qualityRatio
*
float64
(
n
)
,
ImagePriceRatio
:
sizeRatio
*
qualityRatio
,
}
}
...
...
relay/channel/ali/image.go
View file @
89fe99f3
...
...
@@ -54,7 +54,6 @@ func oaiImage2AliImageRequest(info *relaycommon.RelayInfo, request dto.ImageRequ
}
}
// 检查n参数
if
imageRequest
.
Parameters
.
N
!=
0
{
info
.
PriceData
.
AddOtherRatio
(
"n"
,
float64
(
imageRequest
.
Parameters
.
N
))
}
...
...
@@ -328,7 +327,6 @@ func aliImageHandler(a *Adaptor, c *gin.Context, resp *http.Response, info *rela
}
imageResponses
:=
responseAli2OpenAIImage
(
c
,
aliResponse
,
originRespBody
,
info
,
responseFormat
)
// 可能生成多张图片,修正计费数量n
if
aliResponse
.
Usage
.
ImageCount
!=
0
{
info
.
PriceData
.
AddOtherRatio
(
"n"
,
float64
(
aliResponse
.
Usage
.
ImageCount
))
}
else
if
len
(
imageResponses
.
Data
)
!=
0
{
...
...
relay/image_handler.go
View file @
89fe99f3
...
...
@@ -117,11 +117,20 @@ func ImageHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *type
if
request
.
N
!=
nil
{
imageN
=
*
request
.
N
}
// n is handled via OtherRatio so it is applied exactly once in quota
// calculation (both price-based and ratio-based paths).
// Adaptors may have already set a more accurate count from the
// upstream response; only set the default when they haven't.
if
_
,
hasN
:=
info
.
PriceData
.
OtherRatios
[
"n"
];
!
hasN
{
info
.
PriceData
.
AddOtherRatio
(
"n"
,
float64
(
imageN
))
}
if
usage
.
(
*
dto
.
Usage
)
.
TotalTokens
==
0
{
usage
.
(
*
dto
.
Usage
)
.
TotalTokens
=
int
(
imageN
)
usage
.
(
*
dto
.
Usage
)
.
TotalTokens
=
1
}
if
usage
.
(
*
dto
.
Usage
)
.
PromptTokens
==
0
{
usage
.
(
*
dto
.
Usage
)
.
PromptTokens
=
int
(
imageN
)
usage
.
(
*
dto
.
Usage
)
.
PromptTokens
=
1
}
quality
:=
"standard"
...
...
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