openclaw - 💡(How to fix) Fix web_search tool fails with 'fetch failed' despite valid Brave API key [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52177Fetched 2026-04-08 01:14:43
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Error Message

The web_search tool consistently fails with fetch failed error, even though: 3. Observe fetch failed error in logs Actual: fetch failed with no detailed error message

Fix Action

Fix / Workaround

Workaround: Direct curl calls work:

curl --proxy $OPENCLAW_WEB_PROXY \
  -H "X-Subscription-Token: $API_KEY" \
  "https://api.search.brave.com/res/v1/web/search?q=test&count=1"

Code Example

2026-03-22T17:35:39.521+08:00 [tools] web_search failed: fetch failed

---

curl --proxy $OPENCLAW_WEB_PROXY \
  -H "X-Subscription-Token: $API_KEY" \
  "https://api.search.brave.com/res/v1/web/search?q=test&count=1"
RAW_BUFFERClick to expand / collapse

Bug Report

Environment:

  • OpenClaw version: 2026.3.13
  • OS: macOS (Darwin 25.2.0)
  • Node: v24.4.1

Issue: The web_search tool consistently fails with fetch failed error, even though:

  • Brave API key is valid and configured in openclaw.json
  • Direct curl calls to Brave API work perfectly
  • OPENCLAW_WEB_PROXY is set correctly (http://127.0.0.1:7890)

Reproduction:

  1. Configure tools.web.search.apiKey in config
  2. Call web_search tool from agent
  3. Observe fetch failed error in logs

Expected: Search results returned Actual: fetch failed with no detailed error message

Logs:

2026-03-22T17:35:39.521+08:00 [tools] web_search failed: fetch failed

Workaround: Direct curl calls work:

curl --proxy $OPENCLAW_WEB_PROXY \
  -H "X-Subscription-Token: $API_KEY" \
  "https://api.search.brave.com/res/v1/web/search?q=test&count=1"

Suspected cause: The tool implementation may not be respecting OPENCLAW_WEB_PROXY or has an issue with the internal fetch implementation.

extent analysis

Fix Plan

The fix involves modifying the web_search tool to properly use the OPENCLAW_WEB_PROXY environment variable for making requests to the Brave API.

Step-by-Step Solution:

  1. Update web_search Tool: Modify the web_search tool to use a proxy agent when making requests.
  2. Use https-proxy-agent Package: Install the https-proxy-agent package to handle proxying requests.
  3. Implement Proxy in Code: Update the code to use the proxy agent when making requests to the Brave API.

Example Code:

const { HttpsProxyAgent } = require('https-proxy-agent');
const proxyUrl = process.env.OPENCLAW_WEB_PROXY;

// Create a new proxy agent
const agent = new HttpsProxyAgent(proxyUrl);

// Use the proxy agent when making requests
fetch('https://api.search.brave.com/res/v1/web/search?q=test&count=1', {
  headers: {
    'X-Subscription-Token': process.env.API_KEY
  },
  agent
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('fetch failed:', error));

Verification

To verify the fix, run the web_search tool again and check the logs for successful search results. You can also add additional logging to confirm that the proxy is being used correctly.

Extra Tips

  • Ensure the OPENCLAW_WEB_PROXY environment variable is set correctly before running the web_search tool.
  • If issues persist, try logging the proxyUrl variable to confirm it is being set correctly.
  • Consider adding error handling to provide more detailed error messages in case of failures.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix web_search tool fails with 'fetch failed' despite valid Brave API key [1 participants]