Skip to content

ChatOpenAI node ignores proxy configuration when using OpenAI API #5276

@Sohorev

Description

@Sohorev

Describe the bug

Problem Description
The ChatOpenAI node in Flowise does not respect proxy configuration when making requests to OpenAI API, resulting in connection failures when using corporate proxy environments.

Environment
Flowise Version: 3.0.7
OpenAI Package Version: 4.96.0
Node.js Version: 22.18.0
Environment: Kubernetes deployment with proxy variables configured

To Reproduce

  1. Deploy Flowise in a corporate environment that requires all external traffic to go through a proxy server
  2. Configure proxy environment variables:
    GLOBAL_AGENT_HTTP_PROXY: http://corporate-proxy.example.com:3128
    GLOBAL_AGENT_HTTPS_PROXY: http://corporate-proxy.example.com:3128
    HTTP_PROXY: http://corporate-proxy.example.com:3128
    HTTPS_PROXY: http://corporate-proxy.example.com:3128
  3. Set up a ChatOpenAI node with a valid OpenAI API key
  4. In the ChatOpenAI node configuration, set the Proxy Url field to the corporate proxy (e.g., http://corporate-proxy.example.com:3128)
  5. Try to make a request through the chatflow

Expected behavior

The ChatOpenAI node should use the configured corporate proxy for all OpenAI API requests, allowing the application to work in corporate network environments that require proxy usage.

Use Method

Docker

Flowise Version

3.0.7

Operating System

Linux

Browser

None

Additional context

Actual Behavior

The ChatOpenAI node ignores the proxy configuration and attempts to make direct requests to OpenAI API, resulting in connection failures or network errors.

Current Implementation (Not Working)

if (proxyUrl) {
    obj.configuration = {
        ...obj?.configuration,
        httpAgent: new HttpsProxyAgent(proxyUrl)  // ❌ Deprecated approach
    }
}

Proposed Solution
Following the official OpenAI migration guide, update the implementation to use
undici.ProxyAgent with fetchOptions:

import * as undici from 'undici'

if (proxyUrl) {
    const proxyAgent = new undici.ProxyAgent(proxyUrl)
    obj.configuration = {
        ...obj?.configuration,
        fetchOptions: {
            dispatcher: proxyAgent
        }
    } as any
}

Technical Details

  • The error occurs in LangChain's OpenAI client: /usr/local/lib/node_modules/flowise/node_modules/@langchain/openai/dist/chat_models.cjs:1933:28
  • The global-agent library works correctly for other HTTP requests but is ignored by LangChain's OpenAI implementation
  • Manual testing with curl -x http://corporate-proxy.example.com:3128 https://api.openai.com/v1/models returns 401 Missing bearer authentication, confirming the corporate proxy works correctly

Files to Modify
packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts
packages/components/nodImpactes/llms/OpenAI/OpenAI.ts (if it has similar proxy configuration)

Additional Context
This is a critical issue for enterprise users who need to use Flowise with OpenAI models through corporate proxy infrastructure. The workaround of using global-agent environment variables doesn't work because LangChain's OpenAI client doesn't respect global proxy settings.

Priority: High (blocks enterprise deployments with proxy requirements)
Complexity: Low (simple API change following official migration guide)
Impact: High (affects all corporate users with proxy requirements)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions