Skip to content

fix(chatopenai): honor proxy URL#6504

Open
luochen211 wants to merge 1 commit into
FlowiseAI:mainfrom
luochen211:fix-chatopenai-proxy-url
Open

fix(chatopenai): honor proxy URL#6504
luochen211 wants to merge 1 commit into
FlowiseAI:mainfrom
luochen211:fix-chatopenai-proxy-url

Conversation

@luochen211

Copy link
Copy Markdown

Summary

  • restore the ChatOpenAI Proxy Url field and pass it to the OpenAI client via undici ProxyAgent fetchOptions
  • keep existing base path and default header options intact when proxying
  • add a regression test for proxy dispatcher wiring

Fixes #5276

Tests

  • corepack pnpm@10.26.0 --filter flowise-components test -- ChatOpenAI.test.ts --runInBand
  • corepack pnpm@10.26.0 exec eslint packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.test.ts --ext ts --report-unused-disable-directives --max-warnings 0
  • corepack pnpm@10.26.0 exec prettier --check packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.test.ts packages/components/package.json pnpm-lock.yaml
  • corepack pnpm@10.26.0 --filter flowise-components run build
  • git diff --check

Note: full flowise-components lint currently fails on unrelated unused eslint-disable directives in existing files.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for a proxy URL in the ChatOpenAI node by integrating ProxyAgent from undici. It adds a new proxyUrl input field, configures the OpenAI client fetch dispatcher with the proxy agent, and includes corresponding unit tests. The feedback suggests caching and reusing ProxyAgent instances using a module-level cache map to prevent socket leaks and enable connection pooling across multiple executions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +8 to 9
import { ProxyAgent } from 'undici'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent socket leaks and enable connection reuse (keep-alive) across multiple executions, we should cache and reuse ProxyAgent instances instead of creating a new one on every initialization. Let's declare a module-level cache map for the proxy agents.

import { ProxyAgent } from 'undici'

const proxyAgentCache = new Map<string, ProxyAgent>()

Comment on lines +299 to 311
if (basePath || parsedBaseOptions || proxyUrl) {
obj.configuration = {
baseURL: basePath,
defaultHeaders: parsedBaseOptions
defaultHeaders: parsedBaseOptions,
...(proxyUrl
? {
fetchOptions: {
dispatcher: new ProxyAgent(proxyUrl)
}
}
: {})
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Retrieve the cached ProxyAgent instance for the given proxyUrl to benefit from connection pooling and avoid resource exhaustion.

        if (basePath || parsedBaseOptions || proxyUrl) {
            let dispatcher: ProxyAgent | undefined = undefined
            if (proxyUrl) {
                let agent = proxyAgentCache.get(proxyUrl)
                if (!agent) {
                    agent = new ProxyAgent(proxyUrl)
                    proxyAgentCache.set(proxyUrl, agent)
                }
                dispatcher = agent
            }

            obj.configuration = {
                baseURL: basePath,
                defaultHeaders: parsedBaseOptions,
                ...(dispatcher
                    ? {
                          fetchOptions: {
                              dispatcher
                          }
                      }
                    : {})
            }
        }

@luochen211 luochen211 force-pushed the fix-chatopenai-proxy-url branch from 18bc438 to 32fdc8b Compare June 11, 2026 10:19
@luochen211

Copy link
Copy Markdown
Author

Addressed the review suggestion by caching ProxyAgent instances per proxy URL and extending the regression test to verify repeated init calls reuse the dispatcher. Re-verified with the targeted ChatOpenAI test, eslint, prettier, flowise-components build, and git diff check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatOpenAI node ignores proxy configuration when using OpenAI API

1 participant