Skip to content

Conversation

@Ameyanagi
Copy link

Summary

Adds comprehensive proxy support to LibreChat, including NO_PROXY environment variable support to bypass proxy for internal services and specified hosts.

Features:

  • PROXY support on the js and ts based api. (for example mcp connection)
  • NO_PROXY environment variable support across entire codebase
  • Supports patterns: exact hostname, wildcard (*), suffix (.example.com), port-specific (host:8080)
  • Shared proxy utility (packages/api/src/utils/proxy.ts) for consistent NO_PROXY behavior
  • Docker containers receive proxy environment variables

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  1. Set proxy configuration in .env: (please change the proxy name)
    PROXY=http://proxy.example.com:8080
    NO_PROXY=localhost,127.0.0.1,mongodb,meilisearch,vectordb,rag_api,host.docker.internal

  2. Start with docker compose up -d

  3. Verify external API calls (OpenAI, Anthropic) go through proxy

  4. Verify internal services (mongodb, rag_api) bypass proxy

Test Configuration:

  • Docker Compose environment
  • Corporate proxy with NO_PROXY for internal services

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings

- Use undici's EnvHttpProxyAgent for native NO_PROXY support
- Automatically respects NO_PROXY/no_proxy environment variable
- Supports exact match, wildcard (*), and suffix (.domain.com) patterns
- Apply to MCP connections (SSE transport) and LLM endpoints (Anthropic/OpenAI)
- Respects PROXY env var with automatic NO_PROXY bypass
- Create shared proxy utility in packages/api/src/utils/proxy.ts
- Use undici EnvHttpProxyAgent for native NO_PROXY in fetch-based code
- Add shouldBypassProxy() for axios-based code with HttpsProxyAgent
- Support patterns: exact match, wildcard (*), suffix (.domain), port-specific
- Update 16 files to respect NO_PROXY environment variable
- Document NO_PROXY with common patterns in .env.example

Files using EnvHttpProxyAgent (native NO_PROXY):
- DALLE3, TavilySearch, TavilySearchResults, OpenAIImageTools (undici)
- Azure/OpenAI Assistants, OpenID strategy

Files using shared utility (manual NO_PROXY):
- Mistral file operations, Model fetching, Bedrock
- FluxAPI, Audio services (STT/TTS)
- OpenID JWT strategy
Ensures consistent timeout behavior whether proxy is used or not.
Without this fix, proxy connections had no timeout while non-proxy
connections used bodyTimeout and headersTimeout defaults.
The api service was only mounting .env file but not passing PROXY/NO_PROXY
as actual container environment variables. This ensures the proxy settings
are available both to the Node.js app (via dotenv) and the container
environment (for any child processes).
Added HTTP_PROXY, HTTPS_PROXY, and NO_PROXY to meilisearch for
corporate environments that require all outbound traffic through proxy.
Maps LibreChat's PROXY env var to standard Linux proxy env vars.
Many applications check for both uppercase (HTTP_PROXY) and lowercase
(http_proxy) variants. Added lowercase versions for better compatibility.
Added HTTP_PROXY, HTTPS_PROXY and lowercase variants (http_proxy,
https_proxy, no_proxy) to ensure proxy settings are available as
actual container environment variables, not just via dotenv.
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.

1 participant