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
bb234ff4
authored
Aug 11, 2026
by
Seefs
Committed by
GitHub
Aug 11, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(responses): remove compact model suffix handling (#6770)
parent
253a74dd
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
133 deletions
+21
-133
common/api_type.go
+1
-1
controller/channel-test.go
+3
-23
controller/channel_test_internal_test.go
+13
-11
middleware/distributor.go
+0
-3
relay/channel/codex/constants.go
+1
-14
relay/helper/model_mapped.go
+1
-19
relay/responses_handler.go
+1
-1
service/codex_channel_models.go
+1
-10
setting/ratio_setting/compact_suffix.go
+0
-34
setting/ratio_setting/model_ratio.go
+0
-17
No files found.
common/api_type.go
View file @
bb234ff4
...
...
@@ -88,7 +88,7 @@ func ChannelType2APIType(channelType int) (int, bool) {
return
apiType
,
true
}
func
IsResponsesCompactAPIType
(
apiType
int
)
bool
{
func
SupportsResponsesCompact
(
channelType
,
apiType
int
)
bool
{
switch
apiType
{
case
constant
.
APITypeOpenAI
,
constant
.
APITypeCodex
,
...
...
controller/channel-test.go
View file @
bb234ff4
...
...
@@ -27,7 +27,6 @@ import (
"github.com/QuantumNous/new-api/relaykit/types"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/operation_setting"
"github.com/QuantumNous/new-api/setting/ratio_setting"
hosttypes
"github.com/QuantumNous/new-api/types"
"github.com/samber/lo"
...
...
@@ -42,14 +41,11 @@ type testResult struct {
newAPIError
*
types
.
NewAPIError
}
func
normalizeChannelTestEndpoint
(
channel
*
model
.
Channel
,
modelName
,
endpointType
string
)
string
{
func
normalizeChannelTestEndpoint
(
channel
*
model
.
Channel
,
endpointType
string
)
string
{
normalized
:=
strings
.
TrimSpace
(
endpointType
)
if
normalized
!=
""
{
return
normalized
}
if
strings
.
HasSuffix
(
modelName
,
ratio_setting
.
CompactModelSuffix
)
{
return
string
(
constant
.
EndpointTypeOpenAIResponseCompact
)
}
if
channel
!=
nil
&&
channel
.
Type
==
constant
.
ChannelTypeCodex
{
return
string
(
constant
.
EndpointTypeOpenAIResponse
)
}
...
...
@@ -111,7 +107,7 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
}
}
endpointType
=
normalizeChannelTestEndpoint
(
channel
,
testModel
,
endpointType
)
endpointType
=
normalizeChannelTestEndpoint
(
channel
,
endpointType
)
requestPath
:=
"/v1/chat/completions"
...
...
@@ -146,20 +142,12 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
requestPath
=
"/v1/responses"
}
// responses compaction models (must use /v1/responses/compact)
if
strings
.
HasSuffix
(
testModel
,
ratio_setting
.
CompactModelSuffix
)
{
requestPath
=
"/v1/responses/compact"
}
}
// Gemini 原生流式通过 URL action(:streamGenerateContent)表达而非请求体字段,
// GeminiChatRequest.IsStream 依据请求 URL 判定,合成请求路径需与生产入口保持一致
if
isStream
&&
constant
.
EndpointType
(
endpointType
)
==
constant
.
EndpointTypeGemini
{
requestPath
=
strings
.
Replace
(
requestPath
,
":generateContent"
,
":streamGenerateContent"
,
1
)
}
if
strings
.
HasPrefix
(
requestPath
,
"/v1/responses/compact"
)
{
testModel
=
ratio_setting
.
WithCompactModelSuffix
(
testModel
)
}
c
.
Request
=
httptest
.
NewRequestWithContext
(
ctx
,
http
.
MethodPost
,
requestPath
,
nil
)
cache
,
err
:=
model
.
GetUserCache
(
testUserID
)
...
...
@@ -277,7 +265,7 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
apiType
,
_
:=
common
.
ChannelType2APIType
(
channel
.
Type
)
if
info
.
RelayMode
==
relayconstant
.
RelayModeResponsesCompact
&&
!
common
.
IsResponsesCompactAPIType
(
apiType
)
{
!
common
.
SupportsResponsesCompact
(
channel
.
Type
,
apiType
)
{
return
testResult
{
context
:
c
,
localErr
:
fmt
.
Errorf
(
"responses compaction test is not supported for api type %d"
,
apiType
),
...
...
@@ -806,14 +794,6 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
}
}
// Responses compaction models (must use /v1/responses/compact)
if
strings
.
HasSuffix
(
model
,
ratio_setting
.
CompactModelSuffix
)
{
return
&
dto
.
OpenAIResponsesCompactionRequest
{
Model
:
model
,
Input
:
testResponsesInput
,
}
}
// Responses-only models (e.g. codex series)
if
strings
.
Contains
(
strings
.
ToLower
(
model
),
"codex"
)
{
return
&
dto
.
OpenAIResponsesRequest
{
...
...
controller/channel_test_internal_test.go
View file @
bb234ff4
...
...
@@ -95,23 +95,25 @@ func TestNewAPIChannelRegistration(t *testing.T) {
assert
.
Empty
(
t
,
constant
.
ChannelBaseURLs
[
constant
.
ChannelTypeNewAPI
])
}
func
TestResponsesCompact
APIType
Support
(
t
*
testing
.
T
)
{
func
TestResponsesCompact
Channel
Support
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
apiType
int
want
bool
name
string
channelType
int
apiType
int
want
bool
}{
{
name
:
"OpenAI"
,
apiType
:
constant
.
APITypeOpenAI
,
want
:
true
},
{
name
:
"Codex"
,
apiType
:
constant
.
APITypeCodex
,
want
:
true
},
{
name
:
"Advanced Custom"
,
apiType
:
constant
.
APITypeAdvancedCustom
,
want
:
true
},
{
name
:
"Sub2API"
,
apiType
:
constant
.
APITypeSub2API
,
want
:
true
},
{
name
:
"New API"
,
apiType
:
constant
.
APITypeNewAPI
,
want
:
true
},
{
name
:
"Anthropic"
,
apiType
:
constant
.
APITypeAnthropic
,
want
:
false
},
{
name
:
"OpenAI"
,
channelType
:
constant
.
ChannelTypeOpenAI
,
apiType
:
constant
.
APITypeOpenAI
,
want
:
true
},
{
name
:
"Azure"
,
channelType
:
constant
.
ChannelTypeAzure
,
apiType
:
constant
.
APITypeOpenAI
,
want
:
true
},
{
name
:
"Codex"
,
channelType
:
constant
.
ChannelTypeCodex
,
apiType
:
constant
.
APITypeCodex
,
want
:
true
},
{
name
:
"Advanced Custom"
,
channelType
:
constant
.
ChannelTypeAdvancedCustom
,
apiType
:
constant
.
APITypeAdvancedCustom
,
want
:
true
},
{
name
:
"Sub2API"
,
channelType
:
constant
.
ChannelTypeSub2API
,
apiType
:
constant
.
APITypeSub2API
,
want
:
true
},
{
name
:
"New API"
,
channelType
:
constant
.
ChannelTypeNewAPI
,
apiType
:
constant
.
APITypeNewAPI
,
want
:
true
},
{
name
:
"Anthropic"
,
channelType
:
constant
.
ChannelTypeAnthropic
,
apiType
:
constant
.
APITypeAnthropic
,
want
:
false
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
test
.
want
,
common
.
IsResponsesCompactAPIType
(
test
.
apiType
))
assert
.
Equal
(
t
,
test
.
want
,
common
.
SupportsResponsesCompact
(
test
.
channelType
,
test
.
apiType
))
})
}
}
...
...
middleware/distributor.go
View file @
bb234ff4
...
...
@@ -410,9 +410,6 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
common
.
SetContextKey
(
c
,
constant
.
ContextKeyTokenGroup
,
modelRequest
.
Group
)
}
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/v1/responses/compact"
)
&&
modelRequest
.
Model
!=
""
{
modelRequest
.
Model
=
ratio_setting
.
WithCompactModelSuffix
(
modelRequest
.
Model
)
}
return
&
modelRequest
,
shouldSelectChannel
,
nil
}
...
...
relay/channel/codex/constants.go
View file @
bb234ff4
package
codex
import
(
"slices"
"github.com/QuantumNous/new-api/setting/ratio_setting"
)
var
baseModelList
=
[]
string
{
var
ModelList
=
[]
string
{
"gpt-5.6-sol"
,
"gpt-5.6-terra"
,
"gpt-5.6-luna"
,
...
...
@@ -17,11 +11,4 @@ var baseModelList = []string{
"codex-auto-review"
,
}
var
ModelList
=
slices
.
DeleteFunc
(
ratio_setting
.
WithCompactModelVariants
(
baseModelList
),
func
(
modelName
string
)
bool
{
return
modelName
==
ratio_setting
.
WithCompactModelSuffix
(
"codex-auto-review"
)
},
)
const
ChannelName
=
"codex"
relay/helper/model_mapped.go
View file @
bb234ff4
...
...
@@ -4,12 +4,9 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"github.com/QuantumNous/new-api/relay/common"
relayconstant
"github.com/QuantumNous/new-api/relay/constant"
"github.com/QuantumNous/new-api/relaykit/dto"
"github.com/QuantumNous/new-api/setting/ratio_setting"
"github.com/gin-gonic/gin"
)
...
...
@@ -18,13 +15,6 @@ func ModelMappedHelper(c *gin.Context, info *common.RelayInfo, request dto.Reque
info
.
ChannelMeta
=
&
common
.
ChannelMeta
{}
}
isResponsesCompact
:=
info
.
RelayMode
==
relayconstant
.
RelayModeResponsesCompact
originModelName
:=
info
.
OriginModelName
mappingModelName
:=
originModelName
if
isResponsesCompact
&&
strings
.
HasSuffix
(
originModelName
,
ratio_setting
.
CompactModelSuffix
)
{
mappingModelName
=
strings
.
TrimSuffix
(
originModelName
,
ratio_setting
.
CompactModelSuffix
)
}
// map model name
modelMapping
:=
c
.
GetString
(
"model_mapping"
)
if
modelMapping
!=
""
&&
modelMapping
!=
"{}"
{
...
...
@@ -35,7 +25,7 @@ func ModelMappedHelper(c *gin.Context, info *common.RelayInfo, request dto.Reque
}
// 支持链式模型重定向,最终使用链尾的模型
currentModel
:=
mapping
ModelName
currentModel
:=
info
.
Origin
ModelName
visitedModels
:=
map
[
string
]
bool
{
currentModel
:
true
,
}
...
...
@@ -66,14 +56,6 @@ func ModelMappedHelper(c *gin.Context, info *common.RelayInfo, request dto.Reque
}
}
if
isResponsesCompact
{
finalUpstreamModelName
:=
mappingModelName
if
info
.
IsModelMapped
&&
info
.
UpstreamModelName
!=
""
{
finalUpstreamModelName
=
info
.
UpstreamModelName
}
info
.
UpstreamModelName
=
finalUpstreamModelName
info
.
OriginModelName
=
ratio_setting
.
WithCompactModelSuffix
(
finalUpstreamModelName
)
}
if
request
!=
nil
{
request
.
SetModelName
(
info
.
UpstreamModelName
)
}
...
...
relay/responses_handler.go
View file @
bb234ff4
...
...
@@ -22,7 +22,7 @@ import (
func
ResponsesHelper
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
newAPIError
*
types
.
NewAPIError
)
{
info
.
InitChannelMeta
(
c
)
if
info
.
RelayMode
==
relayconstant
.
RelayModeResponsesCompact
&&
!
common
.
IsResponsesCompactAPIType
(
info
.
ApiType
)
{
!
common
.
SupportsResponsesCompact
(
info
.
ChannelType
,
info
.
ApiType
)
{
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"unsupported endpoint %q for api type %d"
,
"/v1/responses/compact"
,
info
.
ApiType
),
types
.
ErrorCodeInvalidRequest
,
...
...
service/codex_channel_models.go
View file @
bb234ff4
...
...
@@ -9,7 +9,6 @@ import (
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/setting/ratio_setting"
)
func
FetchCodexChannelModels
(
channel
*
model
.
Channel
)
([]
string
,
error
)
{
...
...
@@ -78,13 +77,5 @@ func fetchCodexChannelModels(
if
statusCode
<
http
.
StatusOK
||
statusCode
>=
http
.
StatusMultipleChoices
{
return
nil
,
fmt
.
Errorf
(
"upstream status: %d"
,
statusCode
)
}
modelVariants
:=
make
([]
string
,
0
,
len
(
models
)
*
2
)
modelVariants
=
append
(
modelVariants
,
models
...
)
for
_
,
modelName
:=
range
models
{
if
modelName
==
"codex-auto-review"
{
continue
}
modelVariants
=
append
(
modelVariants
,
ratio_setting
.
WithCompactModelSuffix
(
modelName
))
}
return
modelVariants
,
nil
return
models
,
nil
}
setting/ratio_setting/compact_suffix.go
deleted
100644 → 0
View file @
253a74dd
package
ratio_setting
import
"strings"
const
CompactModelSuffix
=
"-openai-compact"
const
CompactWildcardModelKey
=
"*"
+
CompactModelSuffix
func
WithCompactModelSuffix
(
modelName
string
)
string
{
if
strings
.
HasSuffix
(
modelName
,
CompactModelSuffix
)
{
return
modelName
}
return
modelName
+
CompactModelSuffix
}
func
WithCompactModelVariants
(
models
[]
string
)
[]
string
{
variants
:=
make
([]
string
,
0
,
len
(
models
)
*
2
)
seen
:=
make
(
map
[
string
]
struct
{},
len
(
models
)
*
2
)
for
_
,
model
:=
range
models
{
if
_
,
ok
:=
seen
[
model
];
ok
{
continue
}
seen
[
model
]
=
struct
{}{}
variants
=
append
(
variants
,
model
)
}
for
_
,
model
:=
range
models
{
compactModel
:=
WithCompactModelSuffix
(
model
)
if
_
,
ok
:=
seen
[
compactModel
];
ok
{
continue
}
seen
[
compactModel
]
=
struct
{}{}
variants
=
append
(
variants
,
compactModel
)
}
return
variants
}
setting/ratio_setting/model_ratio.go
View file @
bb234ff4
...
...
@@ -364,17 +364,6 @@ func GetModelPrice(name string, printErr bool) (float64, bool) {
return
price
,
true
}
if
strings
.
HasSuffix
(
name
,
CompactModelSuffix
)
{
price
,
ok
:=
modelPriceMap
.
Get
(
CompactWildcardModelKey
)
if
!
ok
{
if
printErr
{
common
.
SysError
(
"model price not found: "
+
name
)
}
return
-
1
,
false
}
return
price
,
true
}
if
printErr
{
common
.
SysError
(
"model price not found: "
+
name
)
}
...
...
@@ -398,12 +387,6 @@ func GetModelRatio(name string) (float64, bool, string) {
ratio
,
ok
:=
modelRatioMap
.
Get
(
name
)
if
!
ok
{
if
strings
.
HasSuffix
(
name
,
CompactModelSuffix
)
{
if
wildcardRatio
,
ok
:=
modelRatioMap
.
Get
(
CompactWildcardModelKey
);
ok
{
return
wildcardRatio
,
true
,
name
}
//return 0, true, name
}
return
37.5
,
operation_setting
.
SelfUseModeEnabled
,
name
}
return
ratio
,
true
,
name
...
...
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