Skip to content

Commit 17a73ec

Browse files
authored
🚀 feat: Add OPENAI_ORGANIZATION for all OpenAI Requests (danny-avila#1590)
1 parent a20342a commit 17a73ec

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ DEBUG_OPENAI=false
115115

116116
# OPENAI_REVERSE_PROXY=
117117

118+
# OPENAI_ORGANIZATION=
119+
118120
#============#
119121
# OpenRouter #
120122
#============#

api/app/clients/OpenAIClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,10 @@ ${convo}
954954
opts.defaultHeaders = { ...opts.defaultHeaders, 'api-key': this.apiKey };
955955
}
956956

957+
if (process.env.OPENAI_ORGANIZATION) {
958+
opts.organization = process.env.OPENAI_ORGANIZATION;
959+
}
960+
957961
let chatCompletion;
958962
const openai = new OpenAI({
959963
apiKey: this.apiKey,

api/server/services/ModelService.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const fetchModels = async ({ apiKey, baseURL, name = 'OpenAI', azure = false })
5353
payload.httpsAgent = new HttpsProxyAgent(PROXY);
5454
}
5555

56+
if (process.env.OPENAI_ORGANIZATION && baseURL.includes('openai')) {
57+
payload.headers['OpenAI-Organization'] = process.env.OPENAI_ORGANIZATION;
58+
}
59+
5660
const res = await axios.get(`${baseURL}${azure ? '' : '/models'}`, payload);
5761
models = res.data.data.map((item) => item.id);
5862
} catch (err) {

docs/install/configuration/dotenv.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ GOOGLE_MODELS=gemini-pro,gemini-pro-vision,chat-bison,chat-bison-32k,codechat-bi
285285
OPENAI_API_KEY=user_provided
286286
```
287287

288+
- You can specify which organization to use for each API request to OpenAI. However, it is not required if you are only part of a single organization or intend to use your default organization. You can check your [default organization here](https://platform.openai.com/account/api-keys). This can also help you limit your LibreChat instance from allowing API keys outside of your organization to be used, as a mismatch between key and organization will throw an API error.
289+
290+
```bash
291+
# Optional
292+
OPENAI_ORGANIZATION=org-Y6rfake63IhVorgqfPQmGmgtId
293+
```
294+
288295
- Set to true to enable debug mode for the OpenAI endpoint
289296

290297
```bash

0 commit comments

Comments
 (0)