diff --git a/controller/channel.go b/controller/channel.go index 7756e18f..9f46ca35 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -1107,6 +1107,10 @@ func ManageMultiKeys(c *gin.Context) { return } + lock := model.GetChannelPollingLock(channel.Id) + lock.Lock() + defer lock.Unlock() + switch request.Action { case "get_key_status": keys := channel.GetKeys() diff --git a/model/channel.go b/model/channel.go index 280781f1..a5fb463e 100644 --- a/model/channel.go +++ b/model/channel.go @@ -141,7 +141,7 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) { return keys[selectedIdx], selectedIdx, nil case constant.MultiKeyModePolling: // Use channel-specific lock to ensure thread-safe polling - lock := getChannelPollingLock(channel.Id) + lock := GetChannelPollingLock(channel.Id) lock.Lock() defer lock.Unlock() @@ -500,8 +500,8 @@ var channelStatusLock sync.Mutex // channelPollingLocks stores locks for each channel.id to ensure thread-safe polling var channelPollingLocks sync.Map -// getChannelPollingLock returns or creates a mutex for the given channel ID -func getChannelPollingLock(channelId int) *sync.Mutex { +// GetChannelPollingLock returns or creates a mutex for the given channel ID +func GetChannelPollingLock(channelId int) *sync.Mutex { if lock, exists := channelPollingLocks.Load(channelId); exists { return lock.(*sync.Mutex) } diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index df858ea2..f46af710 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -73,9 +73,6 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) { } func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { - if info.RelayFormat == relaycommon.RelayFormatClaude || info.RelayFormat == relaycommon.RelayFormatGemini { - return fmt.Sprintf("%s/v1/chat/completions", info.BaseUrl), nil - } if info.RelayMode == relayconstant.RelayModeRealtime { if strings.HasPrefix(info.BaseUrl, "https://") { baseUrl := strings.TrimPrefix(info.BaseUrl, "https://") @@ -122,6 +119,9 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { url = strings.Replace(url, "{model}", info.UpstreamModelName, -1) return url, nil default: + if info.RelayFormat == relaycommon.RelayFormatClaude || info.RelayFormat == relaycommon.RelayFormatGemini { + return fmt.Sprintf("%s/v1/chat/completions", info.BaseUrl), nil + } return relaycommon.GetFullRequestURL(info.BaseUrl, info.RequestURLPath, info.ChannelType), nil } }