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
d6942dfe
authored
May 09, 2025
by
tbphp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update OpenRouter balance
parent
4d0b438f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
controller/channel-billing.go
+25
-0
No files found.
controller/channel-billing.go
View file @
d6942dfe
...
...
@@ -108,6 +108,13 @@ type DeepSeekUsageResponse struct {
}
`json:"balance_infos"`
}
type
OpenRouterResponse
struct
{
Data
struct
{
TotalCredits
float64
`json:"total_credits"`
TotalUsage
float64
`json:"total_usage"`
}
`json:"data"`
}
// GetAuthHeader get auth header
func
GetAuthHeader
(
token
string
)
http
.
Header
{
h
:=
http
.
Header
{}
...
...
@@ -281,6 +288,22 @@ func updateChannelAIGC2DBalance(channel *model.Channel) (float64, error) {
return
response
.
TotalAvailable
,
nil
}
func
updateChannelOpenRouterBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
url
:=
"https://openrouter.ai/api/v1/credits"
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
channel
.
Key
))
if
err
!=
nil
{
return
0
,
err
}
response
:=
OpenRouterResponse
{}
err
=
json
.
Unmarshal
(
body
,
&
response
)
if
err
!=
nil
{
return
0
,
err
}
balance
:=
response
.
Data
.
TotalCredits
-
response
.
Data
.
TotalUsage
channel
.
UpdateBalance
(
balance
)
return
balance
,
nil
}
func
updateChannelBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
baseURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
if
channel
.
GetBaseURL
()
==
""
{
...
...
@@ -307,6 +330,8 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
return
updateChannelSiliconFlowBalance
(
channel
)
case
common
.
ChannelTypeDeepSeek
:
return
updateChannelDeepSeekBalance
(
channel
)
case
common
.
ChannelTypeOpenRouter
:
return
updateChannelOpenRouterBalance
(
channel
)
default
:
return
0
,
errors
.
New
(
"尚未实现"
)
}
...
...
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