microsoft/semantic-kernel · error · ServiceInvalidRequestError

A client error occurred while getting search results.

Error message

A client error occurred while getting search results.

What it means

Raised when httpx raises a RequestError — a client-side/network error before a response is received (connection failure, DNS resolution error, timeout, TLS error). The connector wraps it as ServiceInvalidRequestError. Unlike the HTTP-status error, this means the request never successfully reached or returned from Brave.

Solutions

  1. Verify outbound network connectivity and DNS resolution for the Brave API host from the runtime environment.
  2. Increase resilience with a retry/backoff wrapper for transient RequestErrors, and check whether a proxy is required.
  3. If timeouts recur, investigate latency or raise the client timeout (requires subclassing/overriding, since 5s is hardcoded).

Example fix

// before
results = await connector.search(query)
// after
for attempt in range(3):
    try:
        results = await connector.search(query)
        break
    except ServiceInvalidRequestError as e:
        if not isinstance(e.__cause__, RequestError):
            raise
        await asyncio.sleep(2 ** attempt)
Defensive patterns

Strategy: retry

Try / catch

from semantic_kernel.exceptions import ServiceInvalidRequestError
from httpx import RequestError

for attempt in range(3):
    try:
        results = await connector.search(query)
        break
    except ServiceInvalidRequestError as e:
        if isinstance(e.__cause__, RequestError):
            import asyncio
            await asyncio.sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: The async GET to the Brave URL fails at the transport layer: no network connectivity, DNS failure for the Brave host, the 5-second timeout (AsyncClient(timeout=5)) expires, or a proxy/TLS configuration problem.

Common situations: Running in an environment without outbound internet, behind a restrictive proxy/firewall, DNS misconfiguration, or the Brave endpoint being slow enough to exceed the 5s timeout.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/714caecc4244a083. Report an issue: GitHub.

Appendix: source

Thrown at python/semantic_kernel/connectors/brave.py:238

        params = self._build_request_parameters(query, options)

        logger.info(f"Sending GET request to {url}")

        headers = {
            "X-Subscription-Token": self.settings.api_key.get_secret_value(),
            "user_agent": SEMANTIC_KERNEL_USER_AGENT,
        }
        try:
            async with AsyncClient(timeout=5) as client:
                response = await client.get(url, headers=headers, params=params)
                response.raise_for_status()
                return BraveSearchResponse.model_validate_json(response.text)
        except HTTPStatusError as ex:
            logger.error(f"Failed to get search results: {ex}")
            raise ServiceInvalidRequestError("Failed to get search results.") from ex
        except RequestError as ex:
            logger.error(f"Client error occurred: {ex}")
            raise ServiceInvalidRequestError("A client error occurred while getting search results.") from ex
        except Exception as ex:
            logger.error(f"An unexpected error occurred: {ex}")
            raise ServiceInvalidRequestError("An unexpected error occurred while getting search results.") from ex

    def _validate_options(self, options: SearchOptions) -> None:
        if options.top <= 0:
            raise ServiceInvalidRequestError("count value must be greater than 0.")
        if options.top >= 21:
            raise ServiceInvalidRequestError("count value must be less than 21.")

        if options.skip < 0:
            raise ServiceInvalidRequestError("offset must be greater than or equal to 0.")
        if options.skip > 9:
            raise ServiceInvalidRequestError("offset must be less than 10.")

    def _get_url(self) -> str:
        return DEFAULT_URL

View on GitHub (pinned to c028a0c7dc)