WebRouterFetcher
| Most common position in a pipeline | After a web search component, or before a document splitter in an indexing pipeline |
| Mandatory init variables | None |
| Mandatory run variables | urls: A list of page URLs |
| Output variables | documents: Fetched page content as Haystack Documents. meta: Request metadata with the serving provider and failed URLs. |
| API reference | WebRouter |
| GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/webrouter |
| Package name | webrouter-haystack |
Overview
WebRouterFetcher uses WebRouter to retrieve page content from URLs you already have. To discover URLs from a query first, use WebRouterWebSearch.
With the default configuration, it uses providers that need no API key and falls back when a provider fails. Each fetched page becomes a Haystack Document with page content in content. Document metadata contains url, title and provider, plus published_date when available.
The request-level meta output contains provider and failures. Each failure has url and error fields and is also logged as a warning. A partial failure returns the successful documents with the failed URLs in meta["failures"]. If no page can be fetched, the call raises web_router.WebRouterError. An empty URL list returns no documents or failures and makes no backend request.
Configuration
providerselects a specific backend; omit it to use automatic routing.content_formatselects"markdown"(default),"html"or"text". Support depends on the backend. Automatic routing skips backends that cannot serve the format; a named unsupported backend raises an error.extract_paramsforwards options such astimeoutandprovider_optionsto WebRouter. Itsformatentry overridescontent_format. A dictionary passed torun()replaces the initialization dictionary for that call.
See the component API reference for supported providers and parameters, and the WebRouter documentation for backend behavior.
Credentials
The component uses API keys explicitly supplied through provider_keys. For example, to use Tavily, set TAVILY_API_KEY and reference it with a Haystack Secret:
from haystack.utils import Secret
from haystack_integrations.components.fetchers.webrouter import WebRouterFetcher
fetcher = WebRouterFetcher(
provider="tavily",
provider_keys={"tavily": Secret.from_env_var("TAVILY_API_KEY")},
)
Secrets are resolved during warm-up. provider_keys supports providers that can be configured with an API key alone. See the API reference for supported providers.
Usage
Install the integration:
On its own
This example needs no API key:
from haystack_integrations.components.fetchers.webrouter import WebRouterFetcher
fetcher = WebRouterFetcher()
result = fetcher.run(urls=["https://haystack.deepset.ai"])
for document in result["documents"]:
print(document.meta["url"])
print(document.content)
print(result["meta"]["failures"])
Use await fetcher.run_async(urls=...) to fetch URLs from async code.
In a pipeline
To fetch pages found by a search, connect the links output of WebRouterWebSearch to the urls input of WebRouterFetcher.
from haystack import Pipeline
from haystack_integrations.components.fetchers.webrouter import WebRouterFetcher
from haystack_integrations.components.websearch.webrouter import WebRouterWebSearch
search = WebRouterWebSearch(top_k=1)
fetcher = WebRouterFetcher()
pipeline = Pipeline()
pipeline.add_component("search", search)
pipeline.add_component("fetcher", fetcher)
pipeline.connect("search.links", "fetcher.urls")
result = pipeline.run(data={"search": {"query": "What is Haystack by deepset?"}})
for document in result["fetcher"]["documents"]:
print(document.content)
print(result["fetcher"]["meta"]["failures"])