Skip to main content
Version: 3.5

WebRouter

haystack_integrations.components.fetchers.webrouter.webrouter_fetcher​

WebRouterFetcher​

Fetches web pages with WebRouter and returns their main content as Haystack Documents.

WebRouter is an open-source library that puts one interface in front of several page extraction providers. Each call goes to one provider and falls back to the next one if it fails.

No API key is required. By default only keyless providers are used; credentials in the process environment are not discovered automatically. To use a keyed provider, pass its key explicitly through provider_keys, for example provider_keys={"tavily": Secret.from_env_var("TAVILY_API_KEY")}. Only the named Secrets are resolved. This component accepts only keyless or API-key-only provider configuration. Each provider_keys entry is forwarded as api_key; other constructor credentials and settings are not exposed. With WebRouter 0.17, API-key configuration is available for nimble, tavily, exa, linkup, firecrawl, webiq, keenable, deepseek, specstream, apify and browserbase; keyless routing and keyless providers such as jina are also available. oxylabs (username/password or web_api_key) and brightdata (token plus zone) cannot be configured through this component.

See the WebRouter documentation for the providers.

Usage example​

python
from haystack_integrations.components.fetchers.webrouter import WebRouterFetcher

fetcher = WebRouterFetcher()
result = fetcher.run(urls=["https://haystack.deepset.ai"])
documents = result["documents"]
failures = result["meta"]["failures"]

init​

python
__init__(
provider: str | None = None,
*,
content_format: Literal["markdown", "html", "text"] = "markdown",
extract_params: dict[str, Any] | None = None,
provider_keys: dict[str, Secret] | None = None
) -> None

Initialize the WebRouterFetcher component.

Parameters:

  • provider (str | None) – Name of the provider to send every fetch to, for example "firecrawl" or "tavily". If not set, WebRouter picks one among the providers available and falls back to the next one if a call fails.
  • content_format (Literal['markdown', 'html', 'text']) – Representation of each page in the Document content: "markdown", "html" or "text". A provider that cannot return the requested format is skipped, or raises an error when set as provider.
  • extract_params (dict[str, Any] | None) – Additional keyword arguments passed to WebRouter.extract, such as timeout or provider_options. A format key here takes precedence over content_format. See the WebRouter extract reference for the full list.
  • provider_keys (dict[str, Secret] | None) – Explicit mapping of provider names to API key Secrets. Resolved during warm-up and passed as WebRouter's provider_config; omitted providers receive no credentials from the environment.

to_dict​

python
to_dict() -> dict[str, Any]

Serialize the component, retaining Secret references rather than resolved keys.

from_dict​

python
from_dict(data: dict[str, Any]) -> WebRouterFetcher

Deserialize the component and its nested provider key Secrets.

warm_up​

python
warm_up() -> None

Initialize the WebRouter sync client.

Called automatically on first use. Can be called explicitly to avoid cold-start latency.

warm_up_async​

python
warm_up_async() -> None

Initialize the WebRouter async client.

close​

python
close() -> None

Close the WebRouter sync client.

close_async​

python
close_async() -> None

Close the WebRouter async client.

run​

python
run(
urls: list[str], extract_params: dict[str, Any] | None = None
) -> dict[str, Any]

Fetch the given URLs with WebRouter and return their content as Documents.

Fetching several URLs can partly succeed: the pages that could not be read are logged as warnings and listed in meta["failures"].

Parameters:

  • urls (list[str]) – URLs to fetch.
  • extract_params (dict[str, Any] | None) – Optional per-run override of the extract parameters. If provided, fully replaces the init-time extract_params.

Returns:

  • dict[str, Any] – A dictionary with:
  • documents: One Document per page that was read, with url, title, provider and, when known, published_date in meta.
  • meta: Request-level metadata: provider, the provider that served the call, and failures, a list of {"url": ..., "error": ...} for the URLs that could not be read.

Raises:

  • web_router.ConfigurationError – The selected provider cannot be configured; supported API keys are supplied through provider_keys.
  • web_router.WebRouterError – If no URL could be read, or no provider could serve the call.

run_async​

python
run_async(
urls: list[str], extract_params: dict[str, Any] | None = None
) -> dict[str, Any]

Asynchronously fetch the given URLs with WebRouter and return their content as Documents.

Fetching several URLs can partly succeed: the pages that could not be read are logged as warnings and listed in meta["failures"].

Parameters:

  • urls (list[str]) – URLs to fetch.
  • extract_params (dict[str, Any] | None) – Optional per-run override of the extract parameters. If provided, fully replaces the init-time extract_params.

Returns:

  • dict[str, Any] – A dictionary with:
  • documents: One Document per page that was read, with url, title, provider and, when known, published_date in meta.
  • meta: Request-level metadata: provider, the provider that served the call, and failures, a list of {"url": ..., "error": ...} for the URLs that could not be read.

Raises:

  • web_router.ConfigurationError – The selected provider cannot be configured; supported API keys are supplied through provider_keys.
  • web_router.WebRouterError – If no URL could be read, or no provider could serve the call.

haystack_integrations.components.websearch.webrouter.webrouter_websearch​

WebRouterWebSearch​

Searches the web with WebRouter and returns the results as Haystack Documents.

WebRouter is an open-source library that puts one interface in front of several web search providers. Each call goes to one provider and falls back to the next one if it fails.

No API key is required. By default only keyless providers are used; credentials in the process environment are not discovered automatically. To use a keyed provider, pass its key explicitly through provider_keys, for example provider_keys={"tavily": Secret.from_env_var("TAVILY_API_KEY")}. Only the named Secrets are resolved. This component accepts only keyless or API-key-only provider configuration. Each provider_keys entry is forwarded as api_key; other constructor credentials and settings are not exposed. With WebRouter 0.17, API-key configuration is available for nimble, tavily, you, brave, exa, parallel, perplexity, linkup, seltz, webiq, octen, keirolabs, keenable, deepseek, valyu, specstream, firecrawl and apify; you-mcp, exa-mcp and parallel-mcp work keylessly. agentcore and the LiteLLM proxy providers need additional credentials or endpoint settings and cannot be configured through this component.

See the WebRouter documentation for the providers.

Usage example​

python
from haystack_integrations.components.websearch.webrouter import WebRouterWebSearch

websearch = WebRouterWebSearch(top_k=5)
result = websearch.run(query="What is Haystack by deepset?")
documents = result["documents"]
links = result["links"]

init​

python
__init__(
top_k: int | None = 10,
provider: str | None = None,
search_params: dict[str, Any] | None = None,
*,
provider_keys: dict[str, Secret] | None = None
) -> None

Initialize the WebRouterWebSearch component.

Parameters:

  • top_k (int | None) – Maximum number of results to return. None leaves the number to the provider.
  • provider (str | None) – Name of the provider to send every search to, for example "tavily" or "exa". If not set, WebRouter picks one among the providers available and falls back to the next one if a call fails.
  • search_params (dict[str, Any] | None) – Additional keyword arguments passed to WebRouter.search, such as include_domains, exclude_domains, recency, country, search_depth or timeout. A max_results key here takes precedence over top_k. See the WebRouter search reference for the full list.
  • provider_keys (dict[str, Secret] | None) – Explicit mapping of provider names to API key Secrets. Resolved during warm-up and passed as WebRouter's provider_config; omitted providers receive no credentials from the environment.

to_dict​

python
to_dict() -> dict[str, Any]

Serialize the component, retaining Secret references rather than resolved keys.

from_dict​

python
from_dict(data: dict[str, Any]) -> WebRouterWebSearch

Deserialize the component and its nested provider key Secrets.

warm_up​

python
warm_up() -> None

Initialize the WebRouter sync client.

Called automatically on first use. Can be called explicitly to avoid cold-start latency.

warm_up_async​

python
warm_up_async() -> None

Initialize the WebRouter async client.

close​

python
close() -> None

Close the WebRouter sync client.

close_async​

python
close_async() -> None

Close the WebRouter async client.

run​

python
run(
query: str, search_params: dict[str, Any] | None = None
) -> dict[str, list[Document] | list[str]]

Search the web with WebRouter and return the results as Documents.

Parameters:

  • query (str) – Search query.
  • search_params (dict[str, Any] | None) – Optional per-run override of the search parameters. If provided, fully replaces the init-time search_params.

Returns:

  • dict[str, list[Document] | list[str]] – A dictionary with:
  • documents: One Document per result. content holds the fullest text the provider returned for the result, and meta holds title, url, provider and, when known, published_date.
  • links: The URLs of the results.

Raises:

  • web_router.ConfigurationError – The selected provider cannot be configured; supported API keys are supplied through provider_keys.
  • web_router.WebRouterError – No provider can serve the search or the backend request fails.

run_async​

python
run_async(
query: str, search_params: dict[str, Any] | None = None
) -> dict[str, list[Document] | list[str]]

Asynchronously search the web with WebRouter and return the results as Documents.

Parameters:

  • query (str) – Search query.
  • search_params (dict[str, Any] | None) – Optional per-run override of the search parameters. If provided, fully replaces the init-time search_params.

Returns:

  • dict[str, list[Document] | list[str]] – A dictionary with:
  • documents: One Document per result. content holds the fullest text the provider returned for the result, and meta holds title, url, provider and, when known, published_date.
  • links: The URLs of the results.

Raises:

  • web_router.ConfigurationError – The selected provider cannot be configured; supported API keys are supplied through provider_keys.
  • web_router.WebRouterError – No provider can serve the search or the backend request fails.