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
7d2a9469
authored
Aug 14, 2025
by
yyhhyyyyyy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: prevent OpenRouter cache calculation with custommodel ratios
parent
f1afe914
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
service/quota.go
+11
-2
No files found.
service/quota.go
View file @
7d2a9469
...
@@ -37,6 +37,14 @@ type QuotaInfo struct {
...
@@ -37,6 +37,14 @@ type QuotaInfo struct {
GroupRatio
float64
GroupRatio
float64
}
}
func
hasCustomModelRatio
(
modelName
string
,
currentRatio
float64
)
bool
{
defaultRatio
,
exists
:=
ratio_setting
.
GetDefaultModelRatioMap
()[
modelName
]
if
!
exists
{
return
true
}
return
currentRatio
!=
defaultRatio
}
func
calculateAudioQuota
(
info
QuotaInfo
)
int
{
func
calculateAudioQuota
(
info
QuotaInfo
)
int
{
if
info
.
UsePrice
{
if
info
.
UsePrice
{
modelPrice
:=
decimal
.
NewFromFloat
(
info
.
ModelPrice
)
modelPrice
:=
decimal
.
NewFromFloat
(
info
.
ModelPrice
)
...
@@ -247,9 +255,10 @@ func PostClaudeConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -247,9 +255,10 @@ func PostClaudeConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
if
relayInfo
.
ChannelType
==
constant
.
ChannelTypeOpenRouter
{
if
relayInfo
.
ChannelType
==
constant
.
ChannelTypeOpenRouter
{
promptTokens
-=
cacheTokens
promptTokens
-=
cacheTokens
if
cacheCreationTokens
==
0
&&
priceData
.
CacheCreationRatio
!=
1
&&
usage
.
Cost
!=
0
{
isUsingCustomSettings
:=
priceData
.
UsePrice
||
hasCustomModelRatio
(
modelName
,
priceData
.
ModelRatio
)
if
cacheCreationTokens
==
0
&&
priceData
.
CacheCreationRatio
!=
1
&&
usage
.
Cost
!=
0
&&
!
isUsingCustomSettings
{
maybeCacheCreationTokens
:=
CalcOpenRouterCacheCreateTokens
(
*
usage
,
priceData
)
maybeCacheCreationTokens
:=
CalcOpenRouterCacheCreateTokens
(
*
usage
,
priceData
)
if
promptTokens
>=
maybeCacheCreationTokens
{
if
maybeCacheCreationTokens
>=
0
&&
promptTokens
>=
maybeCacheCreationTokens
{
cacheCreationTokens
=
maybeCacheCreationTokens
cacheCreationTokens
=
maybeCacheCreationTokens
}
}
}
}
...
...
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