{"record":{"id":"597823b15105758f","repo":"microsoft/semantic-kernel","slug":"failed-to-get-search-results","errorCode":null,"errorMessage":"Failed to get search results.","messagePattern":"Failed to get search results\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/brave.py","lineNumber":235,"sourceCode":"        )\n\n        url = self._get_url()\n        params = self._build_request_parameters(query, options)\n\n        logger.info(f\"Sending GET request to {url}\")\n\n        headers = {\n            \"X-Subscription-Token\": self.settings.api_key.get_secret_value(),\n            \"user_agent\": SEMANTIC_KERNEL_USER_AGENT,\n        }\n        try:\n            async with AsyncClient(timeout=5) as client:\n                response = await client.get(url, headers=headers, params=params)\n                response.raise_for_status()\n                return BraveSearchResponse.model_validate_json(response.text)\n        except HTTPStatusError as ex:\n            logger.error(f\"Failed to get search results: {ex}\")\n            raise ServiceInvalidRequestError(\"Failed to get search results.\") from ex\n        except RequestError as ex:\n            logger.error(f\"Client error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"A client error occurred while getting search results.\") from ex\n        except Exception as ex:\n            logger.error(f\"An unexpected error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"An unexpected error occurred while getting search results.\") from ex\n\n    def _validate_options(self, options: SearchOptions) -> None:\n        if options.top <= 0:\n            raise ServiceInvalidRequestError(\"count value must be greater than 0.\")\n        if options.top >= 21:\n            raise ServiceInvalidRequestError(\"count value must be less than 21.\")\n\n        if options.skip < 0:\n            raise ServiceInvalidRequestError(\"offset must be greater than or equal to 0.\")\n        if options.skip > 9:\n            raise ServiceInvalidRequestError(\"offset must be less than 10.\")\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/brave.py#L217-L253","documentation":"Raised when the Brave API GET request returns an HTTP error status (response.raise_for_status() throws HTTPStatusError). This is a ServiceInvalidRequestError — the request reached Brave but was rejected (4xx/5xx). The underlying HTTPStatusError is chained.","triggerScenarios":"Calling search() and the Brave endpoint responds with a non-2xx status: 401 unauthorized (bad/expired API key), 403 forbidden (plan/quota), 429 rate limit, or 5xx server errors. The HTTPStatusError branch at brave.py:233-235 fires.","commonSituations":"Expired or wrong API key (401), exceeding the Brave subscription quota (429/402), endpoint URL change, or transient Brave-side outages (5xx).","solutions":["Inspect exc.__cause__ (HTTPStatusError) — its response.status_code identifies the problem: 401 → fix key, 429 → slow down / upgrade plan.","For 429, implement exponential backoff retry at the caller and respect Retry-After.","Confirm the API key is valid and the Brave plan covers the request volume."],"exampleFix":"// before\nresults = await connector.search(\"python tutorials\")\n// after\ntry:\n    results = await connector.search(\"python tutorials\")\nexcept ServiceInvalidRequestError as e:\n    code = getattr(e.__cause__, \"response\", None) and e.__cause__.response.status_code\n    raise RuntimeError(f\"Brave HTTP error {code}: {e.__cause__}\") from e\n","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidRequestError\n\nfor attempt in range(4):\n    try:\n        results = await connector.search(query, top=top)\n        break\n    except ServiceInvalidRequestError as e:\n        resp = getattr(e.__cause__, \"response\", None)\n        code = getattr(resp, \"status_code\", None)\n        if code == 429:\n            import asyncio\n            await asyncio.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Inspect __cause__.response.status_code to distinguish auth (401), quota (429), and server (5xx).","Implement backoff for 429 with Retry-After.","Keep API key valid and within plan quota."],"tags":["brave","network","http","authentication"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}