Skip to content
Open
2 changes: 2 additions & 0 deletions common/api_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func ChannelType2APIType(channelType int) (int, bool) {
apiType = constant.APITypeSub2API
case constant.ChannelTypeNewAPI:
apiType = constant.APITypeNewAPI
case constant.ChannelTypeBaichuan:
apiType = constant.APITypeBaichuan
}
if apiType == -1 {
return constant.APITypeOpenAI, false
Expand Down
1 change: 1 addition & 0 deletions constant/api_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ const (
APITypeAdvancedCustom
APITypeSub2API
APITypeNewAPI
APITypeBaichuan
APITypeDummy // this one is only for count, do not add any channel after this
)
3 changes: 3 additions & 0 deletions constant/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
ChannelTypeAdvancedCustom = 58
ChannelTypeSub2API = 59
ChannelTypeNewAPI = 60
ChannelTypeBaichuan = 61
ChannelTypeDummy // this one is only for count, do not add any channel after this

)
Expand Down Expand Up @@ -124,6 +125,7 @@ var ChannelBaseURLs = []string{
"", //58
"", //59
"", //60
"https://api.baichuan-ai.com", //61
}

var ChannelTypeNames = map[int]string{
Expand Down Expand Up @@ -184,6 +186,7 @@ var ChannelTypeNames = map[int]string{
ChannelTypeAdvancedCustom: "Advanced Custom",
ChannelTypeSub2API: "Sub2API",
ChannelTypeNewAPI: "New API",
ChannelTypeBaichuan: "Baichuan",
}

func GetChannelTypeName(channelType int) string {
Expand Down
18 changes: 18 additions & 0 deletions controller/channel_upstream_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,24 @@ func fetchChannelUpstreamModelIDs(channel *model.Channel) ([]string, error) {
return nil, sanitizeFetchModelsError(err, key)
}

// Baichuan returns model names under data[].model instead of the OpenAI-standard data[].id
if channel.Type == constant.ChannelTypeBaichuan {
var baichuanResult struct {
Data []struct {
Model string `json:"model"`
} `json:"data"`
}
if err := common.Unmarshal(body, &baichuanResult); err != nil {
return nil, err
}
ids := lo.Map(baichuanResult.Data, func(item struct {
Model string `json:"model"`
}, _ int) string {
return item.Model
})
return normalizeModelNames(ids), nil
}

var result OpenAIModelsResponse
if err := common.Unmarshal(body, &result); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions relay/common/relay_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ var streamSupportedChannels = map[int]bool{
constant.ChannelTypeSub2API: true,
constant.ChannelTypeNewAPI: true,
constant.ChannelTypeTencent: true,
constant.ChannelTypeBaichuan: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Expect the StreamOptions clearing logic to honor SupportStreamOptions
# or explicitly allow ChannelTypeBaichuan.
rg -n -C 8 \
  'request\.StreamOptions = nil|SupportStreamOptions|ChannelTypeBaichuan' \
  --glob '*.go' .

Repository: QuantumNous/new-api

Length of output: 15042


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '== relay_info init/StreamOptions section ==\n'
sed -n '200,245p' relay/common/relay_info.go
printf '\n== streamSupportedChannels section ==\n'
sed -n '330,355p' relay/common/relay_info.go

printf '\n== relay adaptor routing around ChannelTypeBaichuan ==\n'
sed -n '110,150p' relay/relay_adaptor.go

printf '\n== relevant OpenAI adaptor snippets ==\n'
sed -n '60,95p' relay/channel/openai/adaptor.go
sed -n '244,252p' relay/channel/openai/adaptor.go

printf '\n== channel adapter ConvertStreamOpenAIRequest references ==\n'
rg -n -C 5 'ConvertStreamOpenAIRequest|ConvertOpenAIRequest|SupportStreamOptions|StreamOptions' relay/channel --glob '*.go'

Repository: QuantumNous/new-api

Length of output: 50375


Preserve stream_options through the OpenAI adaptor.

ChannelTypeBaichuan is routed to openai.Adaptor, and SupportStreamOptions is set to true, but openai.Adaptor.ConvertOpenAIRequest still clears request.StreamOptions for non-OpenAI/non-Azure channels. Baichuan streaming requests lose stream_options before the upstream call. Add ChannelTypeBaichuan to the OpenAI adaptor’s allow-list, or have ConvertOpenAIRequest preserve stream options when info.SupportStreamOptions == true. Add a conversion test that checks Baichuan streaming requests keep stream_options.include_usage.

Suggested fix in the OpenAI adaptor
-	if info.ChannelType != constant.ChannelTypeOpenAI && info.ChannelType != constant.ChannelTypeAzure {
+	if !info.SupportStreamOptions &&
+		info.ChannelType != constant.ChannelTypeOpenAI &&
+		info.ChannelType != constant.ChannelTypeAzure {
		request.StreamOptions = nil
	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/common/relay_info.go` at line 351, Update
openai.Adaptor.ConvertOpenAIRequest to preserve StreamOptions for
ChannelTypeBaichuan, matching its SupportStreamOptions configuration instead of
clearing the field for non-OpenAI/non-Azure channels. Add a conversion test
covering a Baichuan streaming request and verify stream_options.include_usage
remains present.

Source: Coding guidelines

}

func GenRelayInfoWs(c *gin.Context, ws *websocket.Conn) *RelayInfo {
Expand Down
2 changes: 2 additions & 0 deletions relay/relay_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func GetAdaptor(apiType int) channel.Adaptor {
return &sub2api.Adaptor{}
case constant.APITypeNewAPI:
return &newapi.Adaptor{}
case constant.APITypeBaichuan:
return &openai.Adaptor{}
}
return nil
}
Expand Down
10 changes: 6 additions & 4 deletions web/src/features/channels/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ For commercial licensing, please contact support@quantumnous.com
// ============================================================================

export const CHANNEL_TYPE_NEW_API = 60
export const CHANNEL_TYPE_BAICHUAN = 61

export const CHANNEL_TYPES = {
0: 'Unknown',
Expand Down Expand Up @@ -81,12 +82,13 @@ export const CHANNEL_TYPES = {
58: 'Advanced Custom',
59: 'Sub2API',
60: 'New API',
61: 'Baichuan',
} as const

const CHANNEL_TYPE_DISPLAY_ORDER: number[] = [
1, 14, 33, 24, 43, 3, 41, 48, 60, 58, 42, 34, 20, 4, 40, 27, 25, 17, 26, 15,
46, 23, 18, 45, 31, 35, 49, 19, 47, 37, 38, 39, 11, 8, 57, 59, 22, 21, 44, 2,
5, 36, 50, 51, 52, 53, 54, 55, 56,
1, 14, 33, 24, 43, 3, 41, 48, 60, 61, 58, 42, 34, 20, 4, 40, 27, 25, 17, 26,
15, 46, 23, 18, 45, 31, 35, 49, 19, 47, 37, 38, 39, 11, 8, 57, 59, 22, 21, 44,
2, 5, 36, 50, 51, 52, 53, 54, 55, 56,
]

export const CHANNEL_TYPE_OPTIONS: { value: number; label: string }[] = (() => {
Expand Down Expand Up @@ -389,7 +391,7 @@ export const FIELD_DESCRIPTIONS = {

export const MODEL_FETCHABLE_TYPES = new Set([
1, 4, 14, 17, 20, 23, 24, 25, 26, 27, 31, 34, 35, 40, 42, 43, 47, 48, 57, 58,
59, 60,
59, 60, 61,
])

export const TYPE_TO_KEY_PROMPT: Record<number, string> = {
Expand Down
1 change: 1 addition & 0 deletions web/src/features/channels/lib/channel-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function getChannelTypeIcon(type: number): string {
23: 'Hunyuan', // Tencent
19: 'Ai360', // 360
25: 'Moonshot', // Moonshot
61: 'Baichuan', // Baichuan
31: 'Yi', // LingYiWanWu
35: 'Minimax', // MiniMax
45: 'Volcengine', // VolcEngine
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "Badge Color",
"Baidu": "Baidu",
"Baidu V2": "Baidu V2",
"Baichuan": "Baichuan",
"Balance": "Balance",
"Balance and top-up management": "Balance and top-up management",
"Balance depleted": "Balance depleted",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "Couleur du badge",
"Baidu": "Baidu",
"Baidu V2": "Baidu V2",
"Baichuan": "Baichuan",
"Balance": "Solde",
"Balance and top-up management": "Gestion du solde et des recharges",
"Balance depleted": "Solde épuisé",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "バッジの色",
"Baidu": "Baidu",
"Baidu V2": "Baidu V 2",
"Baichuan": "Baichuan",
"Balance": "残高",
"Balance and top-up management": "残高とチャージ管理",
"Balance depleted": "残高なし",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "Цвет значка",
"Baidu": "Baidu",
"Baidu V2": "Baidu V2",
"Baichuan": "Baichuan",
"Balance": "Баланс",
"Balance and top-up management": "Управление балансом и пополнением",
"Balance depleted": "Баланс исчерпан",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "Màu huy hiệu",
"Baidu": "Baidu",
"Baidu V2": "Baidu V2",
"Baichuan": "Baichuan",
"Balance": "Cân bằng",
"Balance and top-up management": "Quản lý số dư và nạp tiền",
"Balance depleted": "Đã hết số dư",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "徽章顏色",
"Baidu": "百度",
"Baidu V2": "百度 V2",
"Baichuan": "百川",
"Balance": "餘額",
"Balance and top-up management": "餘額儲值管理",
"Balance depleted": "餘額已耗盡",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"Badge Color": "徽章颜色",
"Baidu": "百度",
"Baidu V2": "百度 V2",
"Baichuan": "百川",
"Balance": "余额",
"Balance and top-up management": "余额充值管理",
"Balance depleted": "余额已耗尽",
Expand Down