diff --git a/middleware/distributor.go b/middleware/distributor.go index ed457a3..0cb9658 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -155,6 +155,9 @@ func Distribute() func(c *gin.Context) { if channel.AutoBan != nil && *channel.AutoBan == 0 { ban = false } + if nil != channel.OpenAIOrganization { + c.Request.Header.Set("OpenAI-Organization", *channel.OpenAIOrganization) + } c.Set("auto_ban", ban) c.Set("model_mapping", channel.GetModelMapping()) c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key)) diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index 188ff4c..b27b98d 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -49,6 +49,12 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *re req.Header.Set("api-key", info.ApiKey) return nil } + if info.ChannelType == common.ChannelTypeOpenAI { + orgId := c.GetHeader("OpenAI-Organization") + if "" != orgId { + req.Header.Set("OpenAI-Organization", orgId) + } + } req.Header.Set("Authorization", "Bearer "+info.ApiKey) //if info.ChannelType == common.ChannelTypeOpenRouter { // req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api")