Web Search API for LLM Grounding, RAG, and Agent Citations
How provider web search APIs supply live context for agents: LLM Context vs raw results vs cited answers, filters, and grounding rules.
Frozen model weights make large language models unreliable for recent events, changing APIs, and fast-moving news. Without a proper search step, an agent often guesses URLs and fetches pages directly; a wrong guess returns 404 Not Found and forces retries. This page brings together how Brave Search API, Perplexity, and Cloudflare document web search for AI: what to call, what you get back, and how to keep answers tied to verifiable sources.
Why agents need a web search API instead of URL guessing
Section titled “Why agents need a web search API instead of URL guessing”Models are trained once and retain only knowledge up to a cutoff, which makes live facts hard to trust from weights alone.
AI models are only as good as the context you give them. Models are trained and then frozen at a point in time, so they only know about information that existed before their knowledge cutoff date. This makes it difficult to work with models on recent events, changing APIs, or fast-moving news.
— Cloudflare, About Web Search API
Without web search, an agent that needs live information usually guesses the URL of a page and fetches it directly. When the guess is wrong, the request returns a 404 Not Found and the agent has to try again.
— Cloudflare, About Web Search API
Web Search API gives your agents a better option. Like a person starting with a search engine, your agent sends a query and receives a list of relevant, up-to-date results. You can inject those results into the model’s context so its response is grounded in live information.
— Cloudflare, About Web Search API
Common conclusion: Treat web search as the first step for “current web” questions—query in, ranked or extracted evidence out—then let your own model or a provider’s answer layer consume that evidence.
Horizontal web search vs vertical search (scope of the index)
Section titled “Horizontal web search vs vertical search (scope of the index)”Provider docs for consumer search engines index the broad web (horizontal search). That matches agent use cases that need discoverability across topics. Vertical search narrows to one dataset or app (tabs in a browser, industry sites). Agent APIs discussed here are overwhelmingly horizontal general-web retrieval unless you add filters such as domain allowlists or Brave Goggles.
A web search provider experience, also referred to as horizontal search, refers to search engines or systems designed to index and provide results from a broad, general scope, covering a wide range of topics and content types across the internet.
— Chrome Web Store, Extensions quality guidelines FAQ
Brave Search API: LLM Context, Web Search, and Answers
Section titled “Brave Search API: LLM Context, Web Search, and Answers”Brave Search API splits who consumes the response—the model, the end user, or a chat UI expecting a finished reply.
| API | Intended consumer | What you get | Typical use |
|---|---|---|---|
| LLM Context | Model / agent | Pre-extracted chunks + source metadata, token-budgeted | RAG, autonomous web_search tools, fact checking |
| Web Search | Human | Ranked title, URL, snippet (+ enrichments) | Custom search UIs, aggregation |
| Answers | Chat product | AI answer with citations; OpenAI-compatible chat endpoint | Bots that want an end-to-end cited reply |
Search for information — Classic web search in two flavors, for agents and humans.
— Brave, Brave Search API
LLM Context — Search for AI agents. Pre-extracted page content for your LLM — no scraping, token-budgeted. This is the default for RAG, tools, and chatbots.
— Brave, Brave Search API
Web Search — Search for humans. Ranked titles, URLs, and short snippets for a results page, plus local and rich enrichments.
— Brave, Brave Search API
LLM Context vs Answers: when to use which
Section titled “LLM Context vs Answers: when to use which”Need extracted web content for your model? Use LLM Context which is the search for AI agents. Answers writes the cited reply for you.
— Brave, Answers
When to use LLM Context (from Brave):
- Giving your AI agent a web search tool it can call autonomously
- Building RAG pipelines with your own LLM
- Need full control over how context is processed and presented
- Want raw extracted content without AI-generated summaries
- Optimizing for speed with single-search retrieval
- Need fine-grained control over token budgets and source filtering
When to use Answers:
- Want end-to-end AI answers with citations
- Need OpenAI SDK compatibility
- Building conversational AI agents or chatbots with built-in search
- Require research mode for thorough, multi-search answers
See LLM Context vs Answers on the LLM Context page for the same split with extra detail on token control.
How LLM Context differs from classic Web Search
Section titled “How LLM Context differs from classic Web Search”The LLM Context API expands on traditional Web Search, offering a data-first ranking where the most relevant smart chunks are ranked and compiled in a compact format, optimized directly for LLM consumption.
Traditional Web Search returns titles and short snippets for a results page. LLM Context returns extracted page chunks and source metadata in a shape and length that satisfies the needs of an LLM without need for further scraping.
A successful call exposes grounding (extracted content) and sources (metadata keyed by URL), as shown in Understanding the Response.
Answers: cited replies and research mode
Section titled “Answers: cited replies and research mode”API for AI-generated answers backed by real-time web search and verifiable sources
— Brave, Answers
Direct AI answers using OpenAI-compatible endpoint. Best for chat interfaces that need instant, grounded AI responses.
— Brave, Answers
Enable multi-search for thorough, research-grade answers
— Brave, Answers
Perplexity: Search API vs Agent API and the web_search tool
Section titled “Perplexity: Search API vs Agent API and the web_search tool”Perplexity offers two layers: raw ranked results (Search API) and web-grounded answers with citations (Agent API), plus a first-class web_search tool on agent runs.
Search API — ranked JSON, no generated answer
Section titled “Search API — ranked JSON, no generated answer”The Search API returns a ranked results[] array. Each result includes title, url, snippet, and optional date and last_updated fields
— Perplexity, Search the Web
The Search API returns ranked web results as JSON, not a generated answer.
— Perplexity, Search API Overview
Get raw, ranked web search results with advanced filtering and real-time data.
— Perplexity, Quickstart
Use Search when you own the LLM, need domain or recency filters in structured form, or pipe results into monitoring jobs—patterns in Search News Monitor (search_domain_filter, search_recency_filter, fields title, url, snippet, date).
The MCP server documents perplexity search for direct web search with optional search_type: "fast" for lower latency and cost (Perplexity API MCP Server).
Agent API — web-grounded answers in one call
Section titled “Agent API — web-grounded answers in one call”Get accurate, up-to-date answers grounded in real-time web search, with inline citations in a single call, and conversation context across turns.
— Perplexity, Agent API quickstart
Web-grounded answers with citations, tools, and structured output.
— Perplexity, Decisions API quickstart
Equip the model with search via tools such as Web Search (Search the web from the Agent API with filters, search configurations, pricing, parameters, and response fields).
Legacy Sonar Pro tooling shows what an autonomous search step returns—keywords, result titles, URLs, snippets, dates (Built-in Tool Capabilities):
{ "type": "web_search", "web_search": { "search_keywords": [ "EV Statistics 2023-2024", "electric vehicle sales data", "global EV market trends" ], "search_results": [ { "title": "Trends in electric cars", "url": "https://www.iea.org/reports/global-ev-outlook-2024/trends-in-electric-cars", "snippet": "Electric car sales neared 14 million in 2023..." } ] }}Common conclusion across Brave and Perplexity: Search / LLM Context = evidence you process; Agent API / Answers = provider-generated natural language plus citations. Pick Search or LLM Context for control and cost attribution on your model; pick Agent API or Answers when the product is conversational Q&A with sources attached.
Cloudflare Web Search API for agents
Section titled “Cloudflare Web Search API for agents”Cloudflare’s Web Search API targets the same agent pattern: send a query, receive fresh results, inject into context. Cloudflare’s AI Gateway also lists third-party search providers (for example Parallel as a web API built for AIs); the first-party About Web Search API page states the core agent motivation quoted in the introduction.
Token budgets and relevance filtering (Brave LLM Context)
Section titled “Token budgets and relevance filtering (Brave LLM Context)”maximum_number_of_tokens and defaults
Section titled “maximum_number_of_tokens and defaults”Brave recommends leaving count, maximum_number_of_urls, and maximum_number_of_tokens_per_url unset unless you have a reason to change them; tune maximum_number_of_tokens to fit your context window (Context Size Guidelines):
| Task type | maximum_number_of_tokens |
Example query |
|---|---|---|
| Simple factual | 2048 | “What year was Python created?” |
| Standard queries | 8192 (default) | “Best practices for React hooks” |
| Complex research | 16384 | “Compare AI frameworks for production” |
Larger budgets add information but increase cost of downstream inference (Token Budget Tuning).
context_threshold_mode
Section titled “context_threshold_mode”| Mode | Behavior |
|---|---|
strict |
Higher threshold — fewer but more relevant results |
balanced |
Balance between coverage and relevance |
lenient |
Lower threshold — more results, may include less relevant content |
disabled |
No threshold filtering — return all extracted content |
Unset mode uses the API’s calibrated default (Threshold Modes). For precision over recall, Brave also suggests context_threshold_mode=strict and trusted-source Goggles (Source Quality).
Goggles: custom source ranking for LLM Context and Web Search
Section titled “Goggles: custom source ranking for LLM Context and Web Search”Goggles re-rank or filter Brave results with a small DSL—boost domains, demote noise, or build vertical-style experiences on top of horizontal index.
Goggles are a powerful feature that allows you to customize how search results are ranked. Using a simple domain-specific language, you can create instructions to boost, downrank, or completely filter results based on URL patterns, domains, and other criteria.
— Brave, Goggles
Supported APIs: LLM Context, Web Search, and News Search accept goggles as a query/body field (Using Goggles with the API).
Ways to pass Goggles:
- Hosted URL (GitHub, GitLab, Gist)—register at
search.brave.com/goggles/createbefore API use - Inline specification (e.g.
$boost=3,site=dev.to) - Mixed: up to 3
gogglesvalues per request (hosted, inline, or combined)
Limits (Limitations): max 2MB per file, 100,000 instructions, 500 characters per instruction, max 2 * and 2 ^ wildcards per instruction. Complex rule sets should use hosted files, not long inline strings (Use Hosted Goggles for Complex Rules).
Required metadata at the top of a .goggle file includes ! name, ! description, ! public, and ! author (Required Metadata).
Perplexity web_search filters and grounding the agent run
Section titled “Perplexity web_search filters and grounding the agent run”Hard constraints belong in tool parameters, not only in prose. Perplexity enforces filters on the tool definition (Prompt the agent):
[{ "type": "web_search", "filters": { "search_domain_filter": ["sec.gov"], "search_after_date_filter": "01/01/2026" }}]Grounding practices:
- Split system instructions from the user question and ground each run (Define the run).
- Prefer specific queries (“Apple FY2025 10-K revenue by operating segment”) over vague ones (“how is Apple doing”) (Prompt the agent).
- Enable
web_search(and related tools like fetch URL content, which notes “Search the web before fetching source content”) when answers must cite live pages.
Reduce hallucinations when search is thin or a near-miss
Section titled “Reduce hallucinations when search is thin or a near-miss”LLMs are tuned to be helpful, which can occasionally lead them to provide an answer when search results are thin or off-target rather than flagging the gap.
— Perplexity, Prompt Guide
Add explicit outs and near-miss disclosure in instructions that are re-read each agent loop turn:
If searches do not return relevant results after trying alternative phrasings, say so explicitly rather than providing speculative information.
— Perplexity, Prompt Guide
If you find related but non-matching results (for example, a different year, a parent company, or a subsidiary), state the mismatch explicitly before answering.
— Perplexity, Prompt Guide
Hallucination risk rises for paywalled or authenticated content, repeated “related but wrong” hits, or pages not yet indexed (Reduce Hallucinations).
Specialized search endpoints (news, images, video)
Section titled “Specialized search endpoints (news, images, video)”When the task is not generic web text, Brave exposes dedicated indexes (Brave Search API):
| Skill | Endpoint | Best for |
|---|---|---|
news-search |
/res/v1/news/search |
Current events, freshness filters |
images-search |
/res/v1/images/search |
Visual discovery (up to 200 results) |
videos-search |
/res/v1/videos/search |
Tutorials, clips, metadata |
Perplexity mirrors this with agent tools such as Image Search and cookbook flows like Vision + web search for context-enriched analysis.
Common mistakes
Section titled “Common mistakes”- Using human Web Search for RAG — snippets are for UI cards, not token-efficient grounding; Brave directs agents to LLM Context.
- Scraping after classic search — duplicates work LLM Context already does (pre-extracted chunks).
- Oversized context “just in case” — raises inference cost without gains; size
maximum_number_of_tokensto the task (Token Budget Tuning). - Only prompt-level domain rules — use enforced
search_domain_filter/ Brave Goggles instead of hoping the model obeys prose (Prompt the agent). - Unregistered hosted Goggles — hosted files must be submitted at
search.brave.com/goggles/createbefore API use (Creating and Hosting Goggles). - Treating Search API output as an answer — Perplexity’s Search API Overview returns JSON results, not a composed reply; you still need an LLM step or switch to Agent API / Brave Answers.
How to check this on your site
Section titled “How to check this on your site”-
Call Brave LLM Context quickstart with a fixed query and confirm the response includes
groundingchunks and matchingsourcesURLs. -
Repeat the same query against Brave Web Search and verify you receive short snippets only—confirm your pipeline uses the agent-oriented endpoint.
-
Post the same question to Perplexity Search the Web and to an Agent API run with
web_searchenabled; confirm Search returnsresults[]while Agent returns cited natural language. -
If you use Goggles, run A/B queries with and without the
gogglesparameter on LLM Context and inspect whether boosted domains appear insources. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will look into it.