Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

fix(handleTools.js): refactor loading of openAIApiKey to handle user_provided value (#603)

Danny Avilaa64342f5153b
diff --git a/api/app/clients/tools/util/handleTools.js b/api/app/clients/tools/util/handleTools.js
index 9ab0d2d47e..ed4f9ab347 100644
--- a/api/app/clients/tools/util/handleTools.js
+++ b/api/app/clients/tools/util/handleTools.js
@@ -84,10 +84,9 @@ const loadTools = async ({ user, model, functions = null, tools = [], options =
const customConstructors = {
browser: async () => {
- let openAIApiKey = process.env.OPENAI_API_KEY;
- if (!openAIApiKey) {
- openAIApiKey = await getUserPluginAuthValue(user, 'OPENAI_API_KEY');
- }
+ let openAIApiKey = options.openAIApiKey ?? process.env.OPENAI_API_KEY;
+ openAIApiKey = openAIApiKey === 'user_provided' ? null : openAIApiKey;
+ openAIApiKey = openAIApiKey || await getUserPluginAuthValue(user, 'OPENAI_API_KEY');
return new WebBrowser({ model, embeddings: new OpenAIEmbeddings({ openAIApiKey }) });
},
serpapi: async () => {
diff --git a/api/server/controllers/PluginController.js b/api/server/controllers/PluginController.js
index eca94d29cd..49843554c6 100644
--- a/api/server/controllers/PluginController.js
+++ b/api/server/controllers/PluginController.js
@@ -18,6 +18,9 @@ const isPluginAuthenticated = (plugin) => {
return plugin.authConfig.every((authFieldObj) => {
const envValue = process.env[authFieldObj.authField];
+ if (envValue === 'user_provided') {
+ return false;
+ }
return envValue && envValue.trim() !== '';
});
};
diff --git a/api/server/services/PluginService.js b/api/server/services/PluginService.js
index 7e49ad0ebf..1be98638d6 100644
--- a/api/server/services/PluginService.js
+++ b/api/server/services/PluginService.js
@@ -40,7 +40,6 @@ const getUserPluginAuthValue = async (user, authField) => {
// }
// };
-
const updateUserPluginAuth = async (userId, authField, pluginKey, value) => {
try {
const encryptedValue = encrypt(value);