Skip to content

Commit ef06472

Browse files
authored
Merge pull request #2260 from seefs001/fix/multi-key-fetch-models
fix: When retrieving the model list with multiple keys, select the first enabled one.
2 parents b899122 + 33b1fad commit ef06472

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

controller/channel.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,19 @@ func FetchUpstreamModels(c *gin.Context) {
203203
url = fmt.Sprintf("%s/v1/models", baseURL)
204204
}
205205

206+
// 获取用于请求的可用密钥(多密钥渠道优先使用启用状态的密钥)
207+
key, _, apiErr := channel.GetNextEnabledKey()
208+
if apiErr != nil {
209+
c.JSON(http.StatusOK, gin.H{
210+
"success": false,
211+
"message": fmt.Sprintf("获取渠道密钥失败: %s", apiErr.Error()),
212+
})
213+
return
214+
}
215+
key = strings.TrimSpace(key)
216+
206217
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
207218
var body []byte
208-
key := strings.Split(channel.Key, "\n")[0]
209219
switch channel.Type {
210220
case constant.ChannelTypeAnthropic:
211221
body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key))

0 commit comments

Comments
 (0)