Agent Web Search and URL Fetch Tools
How Cloudflare Web Search API, Agents SDK web_search and web_fetch, Browser Run, and AI Gateway fit together—with provider choices and limits.
This page summarises Cloudflare documentation on giving Workers and Agents SDK applications live web context: the Cloudflare Web Search API (beta), SDK tools web_search and web_fetch, persistent browserTool, and—separately—AI Gateway proxying of model vendors’ native web search. It also contrasts the same discover-then-read pattern with Perplexity and Google URL context where those docs overlap.
Web Search API: live search through AI Gateway
Section titled “Web Search API: live search through AI Gateway”The Web Search API lets agents and apps search the public Internet instead of guessing URLs or relying on a model training cutoff.
Web Search API lets your AI agents and applications search the Internet and ground their responses in live information. Instead of guessing URLs or relying on a model’s training cutoff, your agent sends a search query and receives structured results — titles, URLs, and descriptions — that you can pass straight into a model’s context.
— Cloudflare, Cloudflare Web Search API
How Web Search API routes queries and bills
Section titled “How Web Search API routes queries and bills”When you send a search request, Web Search API: Routes the request through the AI Gateway you specify. Forwards the query to the search provider you choose — Ceramic.ai, Exa, or Linkup. If you do not set a provider, Web Search API uses Ceramic.ai as default. Normalizes the provider’s response into a consistent format, with a URL, title, and optional description, image, favicon, and last-modified date for each result. Records the request in your AI Gateway logs and bills it to your account. Because every provider returns the same result format, you can switch providers by changing a single parameter.
— Cloudflare, About Web Search API
Benefits called out in the docs: observability through AI Gateway logs, unified billing at provider list price with no markup (see Providers and pricing), BYOK (store the provider key on the gateway so the provider bills you directly), and access control over which providers callers may use.
At launch, Cloudflare announced three providers, all committed to Cloudflare verified bot crawling standards:
Web Search API is now available in beta. … At launch, you can choose between three search providers: Ceramic.ai, Exa, and Linkup. All three support Zero Data Retention for requests made through Cloudflare, and all have committed to Cloudflare’s verified bot crawling standards.
— Cloudflare, Introducing Web Search API
The dedicated Providers table is the place to verify per-provider facts. For zero data retention (ZDR), that table lists Ceramic.ai and Linkup as yes and Exa as no, which does not match the changelog line above for Exa—treat the providers table as authoritative for Exa ZDR when you choose a provider.
| Provider | provider value |
ZDR (providers page) | Price per 1k requests | Notes |
|---|---|---|---|---|
| Ceramic.ai | ceramic |
Yes | $0.25 | Default; large index; long descriptions |
| Exa | exa |
No | $7.00 | auto search; highlights as description |
| Linkup | linkup |
Yes | $5.00 | fast depth; raw results |
Every provider commits to Cloudflare’s verified bot requirements and returns a link to the source of every result.
— Cloudflare, Cloudflare Web Search API
Web Search API: REST call vs Worker websearch() binding
Section titled “Web Search API: REST call vs Worker websearch() binding”From How to use Web Search API:
- REST:
POST https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/websearch/withoptions.gateway.idrequired. API token needs Account > Workers AI > Read and Account > AI Gateway > Read. - Worker binding:
env.AI.websearch({ gatewayId, query, provider, limit, byokAlias? })with Wrangler[ai] binding = "AI"(see the same how-to page).
Request limits (API and binding): query required, 1–1024 characters; provider ceramic | exa | linkup (default ceramic); limit default 10, min 1, max 10; byokAlias must match ^[A-Za-z0-9_-]{1,64}$—if set and the gateway has no matching key, the call fails with no credit fallback.
Responses use items[] with required url and title, plus optional description, imageUrl, faviconUrl, lastModifiedDate, and metadata (query, requestId, latencyMs).
For manual tool-calling without the SDK helper, the how-to page describes defining a web_search function tool on env.AI.run, running env.AI.websearch on tool call, and returning JSON as role: "tool".
Agents SDK web_search: same API as a model tool
Section titled “Agents SDK web_search: same API as a model tool”The web_search tool calls the Web Search API through AI Gateway via the Workers AI binding. Requires Agents SDK ≥ 0.27.0 and a recent workerd (Wrangler 4.141.0 and related versions in the doc); older runtimes yield web_search_unsupported_runtime.
The web_search tool calls the Cloudflare Web Search API through AI Gateway, via the Workers AI binding.
— Cloudflare, Web search tool
The Cloudflare Agents SDK now provides a web_search tool that searches the public web through the Cloudflare Web Search API, powered by ceramic.ai, Exa, and Linkup. When you give the web_search tool to your agent, the model provides a query and max results, and receives back a short numbered list of titles, URLs, and trimmed descriptions. When you also provide the web_fetch tool to your agent, the model is told to use it to read the pages that the web_search tool returns.
— Cloudflare, New web search tool in the Agents SDK
Who chooses what: the model picks query and result count (capped by your limit, default 5, max 10). Your app sets gateway, provider, byokAlias, maxDescriptionChars (default 600), and timeouts—the model cannot change provider.
The Web Search API does not paginate. The tool description tells the model to search again with a rephrased query when it needs more or different results.
— Cloudflare, Web search tool
Search results are for finding pages. To let the model read the pages it finds, add the web_fetch tool next to web_search.
— Cloudflare, Web search tool
Pi, Vercel AI SDK, and TanStack AI adapters are documented on the same page; without a model harness, use createAIWebSearch() or createHTTPWebSearch() from agents/websearch. Wrangler needs "ai": { "binding": "AI", "remote": true }; local dev still bills the logged-in account.
Agents SDK web_fetch: read a known URL without a browser
Section titled “Agents SDK web_fetch: read a known URL without a browser”Use web_fetch when you already have a URL (including from web_search) and a single HTTP read is enough.
Give your agent a web_fetch tool to read a URL. The Agents SDK handles the work around the HTTP request: converting documents into readable text, splitting long pages into smaller results, and controlling which URLs the model can fetch.
— Cloudflare, Web fetch tool
The Cloudflare Agents SDK now provides a web_fetch tool that reads webpages, PDFs, and supported Office documents, using Workers AI Markdown Conversion to turn them into text the model can read. When you also provide the web_search tool to your agent, the model is told to use web_fetch to read the pages that web_search returns.
— Cloudflare, New web fetch tool
Long pages return a window (default 20,000 characters per call) and nextOffset for continuation. Each built-in tool call re-fetches the URL unless you cache with fetchWeb() and windowWebFetchPage(). Content is wrapped as untrusted data:
The wrapper marks external content as data, not instructions. It is not a guarantee against prompt injection.
— Cloudflare, Web fetch tool
Defaults include maxBytes 5_000_000, timeoutMs 30_000, maxRedirects 5, public hosts only (allowPrivateHosts: false). web_fetch is GET-only—no browser cookies, custom headers, or login flows; bot challenges may return web_fetch_blocked.
From the Browser tool doc:
To read a page or document at a known URL, use the web_fetch tool instead of a browser. It does not start a browser, so each read is a single HTTP request.
— Cloudflare, Browser
When to use browserTool instead of web_fetch
Section titled “When to use browserTool instead of web_fetch”Use Browser Run and browserTool (SDK ≥ 0.28.0 for persistence) when JavaScript rendering, login or multi-step flows, keeping tabs and cookies across turns, or screenshots matter.
The Cloudflare Agents SDK now provides a browserTool that gives your agent a Browser Run browser it can return to on later turns. Your agent can open a website, inspect a page, and come back to it with its tabs, cookies, and login session intact while the browser session remains alive. When you give browserTool to your agent, the model writes code that drives the browser through the Chrome DevTools Protocol (CDP).
— Cloudflare, New persistent browser tool
| Need | Prefer |
|---|---|
| Discover pages on the open web | web_search / Web Search API |
| Read static HTML, PDF, Office at a URL | web_fetch |
| JS-heavy sites, auth, interaction, screenshots | browserTool |
Internal hostnames: preview dev servers without a public URL
Section titled “Internal hostnames: preview dev servers without a public URL”Internal hostnames let the persistent browser open sites only your agent serves—for example a sandbox dev server on preview.internal.
Internal hostnames let your agent’s browser preview a dev server running in a container without exposing that server to the public Internet. With internal hostnames, the persistent browser in the Cloudflare Agents SDK can open sites that only your agent serves.
— Cloudflare, Agents SDK: Preview dev servers
Pass internalHosts to browserRun(), export InternalHostRouter from the Worker, and wire fetchInternalHost on the Durable Object (built-in on the Agent class when you omit custom routing). Examples in the Browser tool doc include preview.internal (sandbox port ≥ 1024), api.internal via a service binding, and assets.internal for R2—plus optional browser.assignHost({ host, target }) so targets persist across turns and restarts.
AI Search REST vs Web Search API (do not mix endpoints)
Section titled “AI Search REST vs Web Search API (do not mix endpoints)”AI Search REST adds OpenAI-style chat/completions and /search on your indexed AI Search instance—not the public web.
| Goal | Use |
|---|---|
| Search the Internet via Ceramic.ai, Exa, or Linkup | Web Search API /ai/websearch/ or SDK web_search |
| Q&A over your corpus instance | AI Search instance endpoints |
Workers AI changelog items about “Web Search (coming soon)” with BYO Exa on models are a separate track from the shipped Web Search API and SDK tools.
AI Gateway: vendor native web search (second path)
Section titled “AI Gateway: vendor native web search (second path)”This is not the same as SDK web_search. AI Gateway web search proxies native search tools from supported model providers:
AI Gateway proxies native web search tools from supported providers so models can answer questions about events after their training cutoff.
— Cloudflare, AI Gateway web search
Examples from that page: Anthropic web_search_20250305 on POST /ai/v1/messages; OpenAI web_search_preview on POST /ai/v1/responses (not chat completions); xAI web_search on Responses for a specific Grok model; Alibaba Qwen enable_search: true on chat completions. Search-first providers such as Perplexity or Parallel use provider-specific gateway paths rather than one unified tool.
AI Gateway does not provide a provider-agnostic web search abstraction
— Cloudflare, AI Gateway web search (for Parallel-style search-first APIs)
Google Gemini on the unified Gateway tool path is listed as unsupported—use Vertex native google_search on the provider endpoint. Many OpenAI and Grok chat models do not accept Gateway web search tools; the doc lists invalid combinations.
Billing: upstream provider web-search rates, unified with the model call, logged in AI Gateway—no separate Gateway fee for web search itself.
Perplexity and Google: analogous search-then-read tools
Section titled “Perplexity and Google: analogous search-then-read tools”Where vendors document the same split:
Use fetch_url when you need full page content from known URLs. Use web_search when the model first needs to discover relevant pages.
— Perplexity, Fetch URL Content
Legacy Sonar described fetch_url_content as retrieving full content from URLs beyond snippets (Built-in Tool Capabilities). Perplexity’s fetch_url allows 1–10 URLs per call, best-effort failures, no paywall bypass, http/https only.
Google’s URL context tool fetches public URLs (up to 20 per request, size and type limits; no localhost). It pairs with google_search for broad discovery then deep read. Deep Research safety notes warn about prompt injection and mixing internal data with web content—same class of risk as Cloudflare’s untrusted_web_content wrapper.
Common conclusion: search tools return pointers and short text; fetch/URL-context tools load known URLs. Agents should chain them unless snippets alone suffice.
VS Code MCP and platform docs (optional setup)
Section titled “VS Code MCP and platform docs (optional setup)”Agent setup pages such as Visual Studio Code + Cloudflare describe Skills (cloudflare/skills, including agents-sdk) and HTTP MCP servers—including Cloudflare API Code Mode and Browser Run MCP. For VS Code, .vscode/mcp.json must use the root key servers, not mcpServers (Cursor/Claude Desktop style). The detailed walkthrough shows OAuth, why three tools is expected (search-and-execute pattern from Build a Code Mode MCP server), and verifying DNS changes in the dashboard—not only in chat.
Append /index.md to Cloudflare doc URLs or load product llms.txt files when feeding docs to an agent (Vibe setup mirrors the same platform-access block).
Common mistakes
Section titled “Common mistakes”- Calling OpenAI web search on
/ai/v1/chat/completionsinstead of Responses (AI Gateway web search). - Using
web_fetchon SPAs or logged-in flows—use Browser. - Expecting Exa ZDR from the launch changelog without checking Providers.
- Forgetting
options.gateway.idon REST Web Search or missing Workers AI + AI Gateway token permissions. - Confusing AI Search instance URLs with
/ai/websearch/. *.example.cominallowedHostsdoes not include the apex domain (web_fetch).- Internal hosts without
InternalHostRouter/fetchInternalHostwiring.
How to check this on your site
Section titled “How to check this on your site”- Confirm Workers AI and AI Gateway are enabled; Wrangler has an
aibinding and, for SDK tools, a runtime version that supportsweb_search(see web search tool). - Send a test
websearchcall or registerwebSearchToolwith a knowngatewayandprovider; inspect AI Gateway logs forrequestIdand billing. - Register
web_fetchalongsideweb_search, run a query that needs a full page, and confirm chunked reads if the page exceedspageChars. - If you use BYOK, verify the gateway alias matches
byokAlias; a deliberate wrong alias should fail with 400, not charge credits. - 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 statement you are asking about.