diff --git a/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx
index 5871e288f47864f7407c5fd3bcf4a0cd5e527d52..2b976e1428b2ea995f527843e16bf8a00129f8ab 100644
--- a/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx
+++ b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx
@@ -91,7 +91,11 @@ function LocalAIModelSelection({ settings, apiKey = null, basePath = null }) {
         return;
       }
       setLoading(true);
-      const { models } = await System.customModels("localai", apiKey, basePath);
+      const { models } = await System.customModels(
+        "localai",
+        typeof apiKey === "boolean" ? null : apiKey,
+        basePath
+      );
       setCustomModels(models || []);
       setLoading(false);
     }
diff --git a/frontend/src/components/LLMSelection/LocalAiOptions/index.jsx b/frontend/src/components/LLMSelection/LocalAiOptions/index.jsx
index 846c378374edd3effbf3ca9534db0af8320cc5a5..7a38527860928556db2c167aeafde114f03b8d48 100644
--- a/frontend/src/components/LLMSelection/LocalAiOptions/index.jsx
+++ b/frontend/src/components/LLMSelection/LocalAiOptions/index.jsx
@@ -108,7 +108,11 @@ function LocalAIModelSelection({ settings, basePath = null, apiKey = null }) {
         return;
       }
       setLoading(true);
-      const { models } = await System.customModels("localai", apiKey, basePath);
+      const { models } = await System.customModels(
+        "localai",
+        typeof apiKey === "boolean" ? null : apiKey,
+        basePath
+      );
       setCustomModels(models || []);
       setLoading(false);
     }
diff --git a/frontend/src/components/LLMSelection/OpenAiOptions/index.jsx b/frontend/src/components/LLMSelection/OpenAiOptions/index.jsx
index d9ca3f29708fca47fe6eefa0a78b165c95339627..fd2f876651b505f647966f5c2331166a1734ac84 100644
--- a/frontend/src/components/LLMSelection/OpenAiOptions/index.jsx
+++ b/frontend/src/components/LLMSelection/OpenAiOptions/index.jsx
@@ -4,9 +4,6 @@ import System from "@/models/system";
 export default function OpenAiOptions({ settings }) {
   const [inputValue, setInputValue] = useState(settings?.OpenAiKey);
   const [openAIKey, setOpenAIKey] = useState(settings?.OpenAiKey);
-  function updateOpenAiKey() {
-    setOpenAIKey(inputValue);
-  }
 
   return (
     <>
@@ -24,7 +21,7 @@ export default function OpenAiOptions({ settings }) {
           autoComplete="off"
           spellCheck={false}
           onChange={(e) => setInputValue(e.target.value)}
-          onBlur={updateOpenAiKey}
+          onBlur={() => setOpenAIKey(inputValue)}
         />
       </div>
       <OpenAIModelSelection settings={settings} apiKey={openAIKey} />
diff --git a/server/utils/helpers/customModels.js b/server/utils/helpers/customModels.js
index 03e373774c716971fc351025dbbe9b552fea9925..3b4397c3117e0cec182936d3c4882720d2d25696 100644
--- a/server/utils/helpers/customModels.js
+++ b/server/utils/helpers/customModels.js
@@ -34,6 +34,8 @@ async function openAiModels(apiKey = null) {
     (model) => !model.owned_by.includes("openai") && model.owned_by !== "system"
   );
 
+  // Api Key was successful so lets save it for future uses
+  if (models.length > 0 && !!apiKey) process.env.OPEN_AI_KEY = apiKey;
   return { models, error: null };
 }
 
@@ -41,7 +43,7 @@ async function localAIModels(basePath = null, apiKey = null) {
   const { Configuration, OpenAIApi } = require("openai");
   const config = new Configuration({
     basePath,
-    ...(!!apiKey ? { apiKey } : {}),
+    apiKey: apiKey || process.env.LOCAL_AI_API_KEY,
   });
   const openai = new OpenAIApi(config);
   const models = await openai
@@ -52,6 +54,8 @@ async function localAIModels(basePath = null, apiKey = null) {
       return [];
     });
 
+  // Api Key was successful so lets save it for future uses
+  if (models.length > 0 && !!apiKey) process.env.LOCAL_AI_API_KEY = apiKey;
   return { models, error: null };
 }