Skip to content

web_search ignores proxy env vars, fails with fetch failed behind proxyΒ #8534

@lvo-Y

Description

@lvo-Y

πŸ› GitHub Issue Report for OpenClaw (Privacy-Safe Version)

Title

web_search tool fails with "fetch failed" error in proxy environments

Labels

bug, tools, network, web_search

Description

Summary

The web_search tool consistently fails with a "fetch failed" error when OpenClaw is running in an environment that
requires HTTP/HTTPS proxy to access external networks. The tool does not respect standard proxy environment variables
(http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY).

Environment

  • OpenClaw Version: 2026.2.1 (ed4529e)
  • Node.js Version: v22.22.0
  • Operating System: WSL2 (Ubuntu on Windows)
    • Kernel: Linux 6.6.x-microsoft-standard-WSL2
  • Platform: Windows with WSL2
  • Network Setup: Behind HTTP proxy (local proxy server)

Configuration

{
"tools": {
"web": {
"search": {
"enabled": true,
"provider": "brave",
"apiKey": "<BRAVE_API_KEY>",
"timeoutSeconds": 10
}
}
}
}

Steps to Reproduce

  1. Set up OpenClaw in an environment requiring HTTP proxy
  2. Configure proxy environment variables:
    export http_proxy=http://PROXY_HOST:PROXY_PORT
    export https_proxy=http://PROXY_HOST:PROXY_PORT
    export HTTP_PROXY=http://PROXY_HOST:PROXY_PORT
    export HTTPS_PROXY=http://PROXY_HOST:PROXY_PORT
  3. Configure Brave Search API key in OpenClaw config
  4. Start OpenClaw gateway with proxy environment variables
  5. Run agent command with web search:
    openclaw agent --session-id test --message "use web_search to find: test query"

Expected Behavior

The web_search tool should use the configured proxy settings to access the Brave Search API and return search results.

Actual Behavior

The web_search tool fails with error: [tools] web_search failed: fetch failed

Error Log:
{
"0": "[tools] web_search failed: fetch failed",
"_meta": {
"runtime": "node",
"runtimeVersion": "22.22.0",
"logLevelName": "ERROR",
"filePath": "/usr/lib/node_modules/openclaw/dist/logging/console.js",
"filePathWithLine": "/usr/lib/node_modules/openclaw/dist/logging/console.js:195"
}
}

Verification Tests

βœ… Proxy is working correctly:

Direct curl test with proxy works fine

curl -x http://PROXY_HOST:PROXY_PORT -I https://api.search.brave.com/res/v1/web/search?q=test
-H "X-Subscription-Token: <API_KEY>"

Returns: HTTP/2 200 (or 405 for HEAD request)

βœ… Brave API key is valid:

GET request works with proxy

curl -x http://PROXY_HOST:PROXY_PORT
'https://api.search.brave.com/res/v1/web/search?q=test&count=1'
-H 'X-Subscription-Token: <API_KEY>'

Returns: Valid JSON search results

❌ OpenClaw web_search fails:

  • The tool fails even when all proxy environment variables are set
  • Other OpenClaw tools that don't require external network access work fine

Attempted Workarounds (All Failed)

  1. Environment Variables: Set http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY in shell before starting gateway
  2. Root User Configuration: Added proxy settings to /root/.bashrc
  3. Node.js Options: Set NODE_OPTIONS with proxy flags
  4. proxychains4: Attempted to wrap gateway with proxychains4
  5. global-agent: Installed and configured global-agent npm package with NODE_OPTIONS="-r global-agent/bootstrap"

None of these standard proxy configuration methods worked.

Root Cause Analysis

The issue appears to be that OpenClaw's web_search tool uses Node.js's native fetch API (introduced in Node.js 18+),
which does not respect proxy environment variables by default. This is a known limitation of the native fetch
implementation.

Proposed Solutions

Option 1: Add Proxy Configuration to OpenClaw Config
Add proxy settings to the OpenClaw configuration file:
{
"tools": {
"web": {
"search": {
"enabled": true,
"provider": "brave",
"apiKey": "...",
"proxy": {
"http": "http://proxy-host:port",
"https": "http://proxy-host:port"
}
}
}
}
}

Option 2: Use Proxy-Aware HTTP Client
Replace native fetch with a proxy-aware HTTP client like:

  • undici with ProxyAgent
  • axios with proxy configuration
  • node-fetch v2 with https-proxy-agent

Example implementation:
import { ProxyAgent } from 'undici';

const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY;
const agent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;

fetch(url, { dispatcher: agent });

Option 3: Respect Environment Variables
Implement proxy detection from environment variables and configure the HTTP client accordingly.

Impact

This issue affects users in:

  • Corporate environments with mandatory proxies
  • Regions requiring VPN/proxy for external access
  • Development environments with network restrictions
  • Any setup where direct internet access is not available

The web_search tool is completely unusable in these environments, which significantly limits OpenClaw's functionality.

Additional Context

  • The web_fetch tool may have the same issue (not tested extensively)
  • Other OpenClaw features that don't require external network work perfectly
  • The gateway itself can be reached and responds correctly
  • This is specifically a network/HTTP client configuration issue

Workaround for Users

Until this is fixed, users in proxy environments can:

  1. Use alternative methods to fetch web content
  2. Set up transparent proxy at system level (if possible)
  3. Use OpenClaw's other tools that don't require external network access

Feature Request

Please add proxy support to OpenClaw's web tools, either through:

  1. Configuration file options (preferred)
  2. Automatic detection of proxy environment variables
  3. Documentation on how to configure proxy for web tools

This would make OpenClaw usable in a much wider range of network environments.

Thank you for considering this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions