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
a4a026e8
Unverified
Commit
a4a026e8
authored
Mar 14, 2026
by
Wesley Liddick
Committed by
GitHub
Mar 14, 2026
Browse files
Merge pull request #990 from LvyuanW/admin-openai-available-models-fix
fix: respect OpenAI OAuth model mapping in admin available models
parents
342fd03e
1d3d7a30
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/account_handler.go
View file @
a4a026e8
...
@@ -1718,13 +1718,12 @@ func (h *AccountHandler) GetAvailableModels(c *gin.Context) {
...
@@ -1718,13 +1718,12 @@ func (h *AccountHandler) GetAvailableModels(c *gin.Context) {
// Handle OpenAI accounts
// Handle OpenAI accounts
if
account
.
IsOpenAI
()
{
if
account
.
IsOpenAI
()
{
//
For OAuth accounts: return default OpenAI models
//
OpenAI 自动透传会绕过常规模型改写,测试/模型列表也应回落到默认模型集。
if
account
.
IsO
Auth
()
{
if
account
.
IsO
penAIPassthroughEnabled
()
{
response
.
Success
(
c
,
openai
.
DefaultModels
)
response
.
Success
(
c
,
openai
.
DefaultModels
)
return
return
}
}
// For API Key accounts: check model_mapping
mapping
:=
account
.
GetModelMapping
()
mapping
:=
account
.
GetModelMapping
()
if
len
(
mapping
)
==
0
{
if
len
(
mapping
)
==
0
{
response
.
Success
(
c
,
openai
.
DefaultModels
)
response
.
Success
(
c
,
openai
.
DefaultModels
)
...
...
backend/internal/handler/admin/account_handler_available_models_test.go
0 → 100644
View file @
a4a026e8
package
admin
import
(
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
type
availableModelsAdminService
struct
{
*
stubAdminService
account
service
.
Account
}
func
(
s
*
availableModelsAdminService
)
GetAccount
(
_
context
.
Context
,
id
int64
)
(
*
service
.
Account
,
error
)
{
if
s
.
account
.
ID
==
id
{
acc
:=
s
.
account
return
&
acc
,
nil
}
return
s
.
stubAdminService
.
GetAccount
(
context
.
Background
(),
id
)
}
func
setupAvailableModelsRouter
(
adminSvc
service
.
AdminService
)
*
gin
.
Engine
{
gin
.
SetMode
(
gin
.
TestMode
)
router
:=
gin
.
New
()
handler
:=
NewAccountHandler
(
adminSvc
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
nil
)
router
.
GET
(
"/api/v1/admin/accounts/:id/models"
,
handler
.
GetAvailableModels
)
return
router
}
func
TestAccountHandlerGetAvailableModels_OpenAIOAuthUsesExplicitModelMapping
(
t
*
testing
.
T
)
{
svc
:=
&
availableModelsAdminService
{
stubAdminService
:
newStubAdminService
(),
account
:
service
.
Account
{
ID
:
42
,
Name
:
"openai-oauth"
,
Platform
:
service
.
PlatformOpenAI
,
Type
:
service
.
AccountTypeOAuth
,
Status
:
service
.
StatusActive
,
Credentials
:
map
[
string
]
any
{
"model_mapping"
:
map
[
string
]
any
{
"gpt-5"
:
"gpt-5.1"
,
},
},
},
}
router
:=
setupAvailableModelsRouter
(
svc
)
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/accounts/42/models"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
var
resp
struct
{
Data
[]
struct
{
ID
string
`json:"id"`
}
`json:"data"`
}
require
.
NoError
(
t
,
json
.
Unmarshal
(
rec
.
Body
.
Bytes
(),
&
resp
))
require
.
Len
(
t
,
resp
.
Data
,
1
)
require
.
Equal
(
t
,
"gpt-5"
,
resp
.
Data
[
0
]
.
ID
)
}
func
TestAccountHandlerGetAvailableModels_OpenAIOAuthPassthroughFallsBackToDefaults
(
t
*
testing
.
T
)
{
svc
:=
&
availableModelsAdminService
{
stubAdminService
:
newStubAdminService
(),
account
:
service
.
Account
{
ID
:
43
,
Name
:
"openai-oauth-passthrough"
,
Platform
:
service
.
PlatformOpenAI
,
Type
:
service
.
AccountTypeOAuth
,
Status
:
service
.
StatusActive
,
Credentials
:
map
[
string
]
any
{
"model_mapping"
:
map
[
string
]
any
{
"gpt-5"
:
"gpt-5.1"
,
},
},
Extra
:
map
[
string
]
any
{
"openai_passthrough"
:
true
,
},
},
}
router
:=
setupAvailableModelsRouter
(
svc
)
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/accounts/43/models"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
var
resp
struct
{
Data
[]
struct
{
ID
string
`json:"id"`
}
`json:"data"`
}
require
.
NoError
(
t
,
json
.
Unmarshal
(
rec
.
Body
.
Bytes
(),
&
resp
))
require
.
NotEmpty
(
t
,
resp
.
Data
)
require
.
NotEqual
(
t
,
"gpt-5"
,
resp
.
Data
[
0
]
.
ID
)
}
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