BerriAI/litellm · error · ValueError

SEARCHAPI_API_KEY is not set. Set `SEARCHAPI_API_KEY` enviro

Error message

SEARCHAPI_API_KEY is not set. Set `SEARCHAPI_API_KEY` environment variable.

What it means

Validation guard in validate_environment: after resolve_server_api_key finds no caller api_key, no SEARCHAPI_API_KEY env var, and no server-side key config, the request cannot be authenticated to SearchApi and is rejected before any HTTP call.

Source

Thrown at litellm/llms/searchapi/search/transformation.py:86

        self,
        headers: dict,
        api_key: str | None = None,
        api_base: str | None = None,
        **kwargs,
    ) -> dict:
        """
        Validate environment and return headers.
        """
        api_key = self.resolve_server_api_key(
            caller_api_key=api_key,
            caller_api_base=api_base,
            key_env_vars=("SEARCHAPI_API_KEY",),
            base_env_var="SEARCHAPI_API_BASE",
            default_api_base=self.SEARCHAPI_API_BASE,
        )

        if not api_key:
            raise ValueError("SEARCHAPI_API_KEY is not set. Set `SEARCHAPI_API_KEY` environment variable.")

        headers["Content-Type"] = "application/json"

        return headers

    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.

        SearchAPI.io uses GET requests and includes api_key in query params.
        """
        api_base = api_base or get_secret_str("SEARCHAPI_API_BASE") or self.SEARCHAPI_API_BASE

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set the SEARCHAPI_API_KEY environment variable.

Example fix

os.environ["SEARCHAPI_API_KEY"] = "<key>"
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when calling SearchAPI search without SEARCHAPI_API_KEY set.

Common situations: See trigger scenarios.


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