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

feat(OpenAIClient): Add HttpsProxyAgent to initializeLLM (#1119)

Danny Avila5c1e44eff722
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index 1450a08d7e..7d078bdcf5 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -1,4 +1,5 @@
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
+const { HttpsProxyAgent } = require('https-proxy-agent');
const ChatGPTClient = require('./ChatGPTClient');
const BaseClient = require('./BaseClient');
const { getModelMaxTokens, genAzureChatCompletion } = require('../../utils');
@@ -461,6 +462,11 @@ If your reverse proxy is compatible to OpenAI specs in every other way, it may s
};
}
+ if (this.options.proxy) {
+ configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy);
+ configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy);
+ }
+
const { req, res, debug } = this.options;
const runManager = new RunManager({ req, res, debug, abortController: this.abortController });
this.runManager = runManager;
diff --git a/api/server/services/ModelService.js b/api/server/services/ModelService.js
index f8857bb5c5..cb8bb5b1f1 100644
--- a/api/server/services/ModelService.js
+++ b/api/server/services/ModelService.js
@@ -29,7 +29,7 @@ const fetchOpenAIModels = async (opts = { azure: false, plugins: false }, _model
if (OPENROUTER_API_KEY) {
reverseProxyUrl = 'https://openrouter.ai/api/v1';
- apiKey = OPENROUTER_API_KEY
+ apiKey = OPENROUTER_API_KEY;
}
if (reverseProxyUrl) {