BerriAI/litellm · error · ValueError

SEARXNG_API_BASE is not set. Please set the `SEARXNG_API_BAS

Error message

SEARXNG_API_BASE is not set. Please set the `SEARXNG_API_BASE` environment variable or pass `api_base` parameter. Example: os.environ['SEARXNG_API_BASE'] = 'https://your-searxng-instance.com'

What it means

Error "SEARXNG_API_BASE is not set. Please set the `SEARXNG_API_BASE` environment variable or pass `api_base` parameter. Example: os.environ['SEARXNG_API_BASE'] = 'https://your-searxng-instance.com'" thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/searxng/search/transformation.py:94

    def get_complete_url(
        self,
        api_base: str | None,
        optional_params: dict,
        data: dict | list[dict] | None = None,
        **kwargs,
    ) -> str:
        """
        Get complete URL for Search endpoint with query parameters.

        SearXNG uses GET requests, so we build the full URL with query params here.
        The transformed request body (data) contains the parameters needed for the URL.
        """
        from urllib.parse import urlencode

        api_base = api_base or get_secret_str("SEARXNG_API_BASE")

        if not api_base:
            raise ValueError(
                "SEARXNG_API_BASE is not set. Please set the `SEARXNG_API_BASE` environment variable "
                "or pass `api_base` parameter. Example: os.environ['SEARXNG_API_BASE'] = 'https://your-searxng-instance.com'"
            )

        # Append "/search" to the api base if it's not already there
        if not api_base.endswith("/search"):
            if api_base.endswith("/"):
                api_base = f"{api_base}search"
            else:
                api_base = f"{api_base}/search"

        # Build query parameters from the transformed request body
        if data and isinstance(data, dict) and "_searxng_params" in data:
            params: Final = data["_searxng_params"]
            query_string: Final = urlencode(params)
            return f"{api_base}?{query_string}"

        return api_base

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set SEARXNG_API_BASE to your SearXNG instance URL.
  2. Or pass api_base parameter to the search call.

Example fix

os.environ['SEARXNG_API_BASE'] = 'https://your-searxng-instance.com'
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when calling SearXNG search without SEARXNG_API_BASE set or api_base passed.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/b0fbfff95ed97ed6. Report an issue: GitHub.