#19126: feat(web-search): add baseUrl option for Brave Search provider
agents
size: XS
Cluster:
Web Search Provider Enhancements
## Summary
Adds a `baseUrl` config option to the Brave Search provider, allowing users to route requests through a local proxy or custom endpoint.
Closes #19075
## Motivation
The Brave Search provider had a hardcoded API endpoint (`https://api.search.brave.com/res/v1/web/search`). Users who want to route through a proxy or a compatible local server have no way to override it. The Perplexity provider already supports `baseUrl` — this PR brings the same feature to Brave.
## Changes
- **`src/agents/tools/web-search.ts`**: Split `BRAVE_SEARCH_ENDPOINT` into `BRAVE_SEARCH_BASE_URL` + `BRAVE_SEARCH_PATH`. Added `resolveBraveBaseUrl()` helper and wired `braveBaseUrl` through `runWebSearch`. Cache key updated to include the base URL so different endpoints don't share cached results.
- **`src/config/zod-schema.agent-runtime.ts`**: Added `baseUrl: z.string().optional()` to `ToolsWebSearchSchema`.
- **`src/config/types.tools.ts`**: Added `baseUrl?: string` to the search config type with JSDoc.
- **`src/config/schema.help.ts`**: Added help text for `tools.web.search.baseUrl`.
## Config example
```json
{
"tools": {
"web": {
"search": {
"provider": "brave",
"baseUrl": "http://localhost:9100/brave",
"apiKey": "BSA..."
}
}
}
}
```
## Backwards compatibility
The default value is `https://api.search.brave.com`, so existing configs are unaffected.
## Related
- Issue #19075
- PR #19084 bundles this with an unrelated "Inter-session Message Role" change — this PR is the focused, standalone fix.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added `baseUrl` configuration option to the Brave Search provider, enabling users to route requests through proxies or custom endpoints. Implementation follows similar pattern to existing Perplexity `baseUrl` support.
**Key changes:**
- Split `BRAVE_SEARCH_ENDPOINT` constant into `BRAVE_SEARCH_BASE_URL` + `BRAVE_SEARCH_PATH` for flexibility
- Added `resolveBraveBaseUrl()` helper function to extract and normalize the base URL from config
- Updated cache key generation to include `braveBaseUrl` to prevent cross-contamination between different endpoints
- Added config schema support across TypeScript types, Zod validation, and help text
- Maintains backward compatibility with default value of `https://api.search.brave.com`
**Minor architectural note:**
The `baseUrl` field is placed at the top level of `tools.web.search` (Brave-specific), while Perplexity uses nested `tools.web.search.perplexity.baseUrl`. This works functionally but creates a slight inconsistency in config structure. Future work could consider moving to `brave.baseUrl` for better symmetry.
<h3>Confidence Score: 4/5</h3>
- Safe to merge with low risk - straightforward feature addition with backward compatibility maintained
- Implementation is clean and follows existing patterns from Perplexity provider. Cache key properly includes baseUrl to prevent cross-contamination. URL construction correctly strips trailing slashes. Default value ensures backward compatibility. Only minor architectural inconsistency noted (top-level vs nested config), which doesn't affect functionality.
- No files require special attention - all changes are straightforward
<sub>Last reviewed commit: 338b0b3</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18167: feat(web-search): add baseUrl support for Brave Search provider
by jkoprax · 2026-02-16
94.5%
#13843: feat(web-search): allow overriding Brave Search base URL
by strelov1 · 2026-02-11
92.7%
#19314: feat: add Brave web_search baseUrl override (AI-assisted)
by mrutunjay-kinagi · 2026-02-17
86.9%
#19084: fix: Brave Search baseUrl and Inter-session Message Role
by jackjin1997 · 2026-02-17
83.0%
#22505: Feature/clean grok search base url
by vacuityv · 2026-02-21
82.5%
#8715: fix(web-search): safer provider resolution & Perplexity auto-detection
by abhijeet117 · 2026-02-04
79.3%
#15923: feat: add proxy support for web_search tool
by Shuai-DaiDai · 2026-02-14
77.6%
#13814: feat(web-search): add ZAI Search (zsearch) provider
by strelov1 · 2026-02-11
76.0%
#12304: feat: add DeSearch as web_search provider
by tatjr13 · 2026-02-09
75.9%
#19042: Security: add URL allowlist for web_search and web_fetch
by smartprogrammer93 · 2026-02-17
75.6%