diff --git a/app/clients/OpenAIClient.js b/app/clients/OpenAIClient.js index f832b3ca134..7d0baa40d79 100644 --- a/app/clients/OpenAIClient.js +++ b/app/clients/OpenAIClient.js @@ -954,6 +954,10 @@ ${convo} opts.defaultHeaders = { ...opts.defaultHeaders, 'api-key': this.apiKey }; } + if (process.env.OPENAI_ORGANIZATION) { + opts.organization = process.env.OPENAI_ORGANIZATION; + } + let chatCompletion; const openai = new OpenAI({ apiKey: this.apiKey, diff --git a/server/services/ModelService.js b/server/services/ModelService.js index 2e433dbd14e..76ac061546d 100644 --- a/server/services/ModelService.js +++ b/server/services/ModelService.js @@ -53,6 +53,10 @@ const fetchModels = async ({ apiKey, baseURL, name = 'OpenAI', azure = false }) payload.httpsAgent = new HttpsProxyAgent(PROXY); } + if (process.env.OPENAI_ORGANIZATION && baseURL.includes('openai')) { + payload.headers['OpenAI-Organization'] = process.env.OPENAI_ORGANIZATION; + } + const res = await axios.get(`${baseURL}${azure ? '' : '/models'}`, payload); models = res.data.data.map((item) => item.id); } catch (err) {