mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 23:21:44 -05:00
[GH-ISSUE #24120] feat: Support Brave Search LLM Context API as web_search provider option #123508
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Fade78 on GitHub (Apr 25, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/24120
Check Existing Issues
Verify Feature Scope
Problem Description
Open WebUI uses Brave Search to retrieve web results that are injected into the LLM's context for grounding. The current implementation calls
/res/v1/web/search, which returns a list of URLs with titles and short text snippets (typically 1–3 sentences per result).This creates a fundamental quality problem: the LLM receives almost nothing it can actually reason over. The pipeline then attempts to compensate by scraping each result URL individually — adding seconds of latency, failing on JavaScript-rendered pages, and getting blocked by anti-bot protections. Even when scraping succeeds, the extraction quality is inconsistent.
Since February 6, 2026, Brave provides the
/res/v1/llm/contextendpoint designed specifically for this use case. It returns pre-extracted, relevance-scored page content — text passages, tables, code blocks, structured data — ready for LLM consumption in a single API call. No scraping needed. Same API key. Same pricing. Open WebUI can't use it because the endpoint URL is hardcoded inbackend/open_webui/retrieval/web/brave.py.Desired Solution you'd like
Replace the
/res/v1/web/searchcall with/res/v1/llm/contextin the Brave Search integration.What changes
1. Endpoint and authentication — Identical. Same
X-Subscription-Tokenheader, same API key, same pricing tier. Only the URL path changes:2. Request parameters — The LLM Context endpoint accepts the same
qandcountparameters, plus context-size parameters that developers should be aware of:maximum_number_of_tokensmaximum_number_of_urlsWEB_SEARCH_RESULT_COUNTsetting.maximum_number_of_tokens_per_urlmaximum_number_of_snippets_per_urlcontext_threshold_modebalancedstrict/balanced/lenient/disabledbalancedis a good default.strictreduces noise for factual queries.lenientmaximizes coverage for research queries.freshnesspd/pw/pm/py/ date rangeThe
maximum_number_of_tokensparameter is the most critical one to get right. At the default of 8192 tokens, a search returning 10 results sends roughly 800 tokens per source — far richer than current snippets (~50 tokens each) but well within the context window of most models. For models with small context windows (≤4K), this should be reduced to 1024–2048.3. Response format — Structurally different. The web search response wraps results under
web.resultswith flatdescriptionstrings. The LLM Context response nests them undergrounding.genericwithsnippetsarrays:The
snippetsfield contains full extracted passages (not 1-sentence summaries). Thesourcesobject provides metadata (hostname, page age) that could enrich citations. Bothgrounding.genericandsourcesuse the URL as the linking key.4. Mapping to existing
SearchResult— The existing model has three fields:The simplest mapping is to join the snippets array:
This preserves backward compatibility — downstream code that reads
SearchResult.snippetgets richer content without any changes. Thesourcesmetadata (hostname, age) could be appended to the snippet or ignored in a first implementation.5. Rate limiting — The existing 429 retry logic (1 second sleep, one retry) works unchanged. Same rate limits apply.
6. POST method — The LLM Context endpoint also supports
POSTwith the same parameters as a JSON body, which is useful for complex queries that exceed URL length limits. This could be adopted as a quality-of-life improvement but is not required for the initial implementation.Alternatives Considered
Post-search scraping pipeline — Use the existing
/res/v1/web/searchendpoint, then scrape each URL with the built-inget_web_loaderto extract full page content. This is the current default behavior when "Web Search" + "RAG" is enabled in Open WebUI. Drawback: requires one extra HTTP request per result (latency × N), is fragile (sites block scrapers, JS-rendered pages fail), and the extraction quality is inconsistent. The LLM Context endpoint eliminates this entire extra step.Brave MCP Server — Brave publishes an official MCP Server that exposes both
web_searchandllm_contextas tools. It could be configured as a separate tool in Open WebUI. Drawback: this requires the user to set up and maintain a separate MCP server process, configure it in Open WebUI's MCP integration, and it doesn't integrate with the native web search pipeline (no result count setting, no domain filter, no admin toggle). The experience is fragmented compared to a built-in option.Brave Answers API — Brave also offers an
/res/v1/answersendpoint that returns a grounded AI-generated answer with citations, using an OpenAI-compatible interface. Drawback: this delegates answer generation to Brave's own model, which conflicts with Open WebUI's architecture where the user's chosen LLM generates the answer. It doesn't return raw extractable context for RAG.Forking the container image — Modify
brave.pyin a custom build. Drawback: defeats the purpose of using the official container; breaks on every update; doesn't benefit the community.Additional Context
Launch date: The LLM Context API was launched on February 6, 2026 (per Brave's changelog). It is now a stable, production-ready endpoint.
Same API key, same pricing: The LLM Context endpoint uses the exact same
X-Subscription-Tokenauthentication and the same per-request pricing as the existing Web Search endpoint. No additional account setup or cost is required — only the URL and response parsing need to change. Pricing is $5 per 1,000 requests for both endpoints (Search includes LLM Context, Web, Images, News).Community demand: The openclaw project has already received two feature requests for this same capability (#14992, #15028), confirming that other AI tool integrations see value in this endpoint.
SearchResultmodel impact: The currentSearchResultmodel inbackend/open_webui/retrieval/web/main.pyhas only three fields:link,title, andsnippet. The LLM Context response provides richer data (multiple snippets per URL, hostname, page age). A minimal implementation could join thesnippetsarray into a singlesnippetstring, but extendingSearchResultwith an optionalsnippets: list[str]field would preserve the richer structure for downstream use.Rate limiting: The current
brave.pyincludes a 429 retry mechanism (1 second sleep, one retry). This should be preserved for the LLM Context endpoint, which follows the same rate limits. The existing pattern is adequate.Token budget parameter: The LLM Context endpoint accepts a
maximum_number_of_tokensparameter (default 8192, range 1024–32768). This could be exposed as an admin setting (e.g.,BRAVE_SEARCH_CONTEXT_TOKENS) to let users control how much context is retrieved per query, balancing grounding quality against latency and cost.@tjbck commented on GitHub (May 8, 2026):
Added.