{"record":{"id":"f22a10237ffc5129","repo":"zylon-ai/private-gpt","slug":"brave-search-api-rate-limit-exceeded-error-messa","errorCode":null,"errorMessage":"Brave Search API rate limit exceeded: {error_message}","messagePattern":"Brave Search API rate limit exceeded: (.+?)","errorType":"exception","errorClass":"RateLimitExceeded","httpStatus":null,"severity":"error","filePath":"private_gpt/components/web/web_search/providers/brave.py","lineNumber":240,"sourceCode":"\n    def _check_response(\n        self, response: ClientResponse, response_data: dict[str, Any]\n    ) -> None:\n        quota_header = response.headers.get(\"x-ratelimit-remaining\")\n        if quota_header is not None and quota_header.strip() == \"0\":\n            raise QuotaConsumed(\n                \"Brave Search API quota exhausted (x-ratelimit-remaining=0)\"\n            )\n\n        status_code = response.status\n        if status_code < 400:\n            return\n\n        error = response_data.get(\"error\", \"Unknown error\")\n        error_message = self._extract_error_message(error)\n        if status_code == 429:\n            logger.debug(f\"Brave Search API rate limit exceeded: {error_message}\")\n            raise RateLimitExceeded(\n                f\"Brave Search API rate limit exceeded: {error_message}\"\n            )\n        elif status_code == 400:\n            raise ValueError(f\"Brave Search API invalid token ({error_message})\")\n        elif status_code >= 500:\n            raise Exception(f\"Brave Search API server error: {error_message}\")\n        else:\n            raise Exception(f\"Brave Search API error ({status_code}): {error_message}\")\n\n    def _build_request_params(\n        self,\n        query: str,\n        num_links: int,\n        offset: int,\n        result_filter: str,\n        safesearch: bool,\n        freshness: str | None,\n        spellcheck: bool,","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/web/web_search/providers/brave.py#L222-L258","documentation":"RateLimitExceeded raised when the Brave Search API responds HTTP 429. The provider extracts the error detail from the JSON body (response_data['error']) and raises this typed exception so callers can distinguish transient throttling from auth or quota problems. Logged at debug level before raising.","triggerScenarios":"Exceeding requests-per-second on the key; retry storms where a slow request is re-fired immediately; parallel consumers each holding their own Brave session bypassing the rate_limit spacing.","commonSituations":"Load tests against the search endpoint; multiple private-gpt replicas sharing one key without coordination; free-tier key under bursty chat traffic.","solutions":["Retry with exponential backoff honoring Retry-After if present.","Increase brave.rate_limit (minimum seconds between requests) to match the plan's allowance.","Reduce concurrency (web_search.num_concurrent_consumers) and enable web_search.cached.","Upgrade the Brave plan if sustained traffic needs more throughput."],"exampleFix":"# before\nresp = await provider.make_query(q, n)\n\n# after\nfor attempt in range(3):\n    try:\n        resp = await provider.make_query(q, n)\n        break\n    except RateLimitExceeded:\n        await asyncio.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_rate_limited(exc: BaseException) -> bool:\n    return type(exc).__name__ == 'RateLimitExceeded'","tryCatchPattern":"from private_gpt.components.web.web_search.providers.brave import RateLimitExceeded\n\nfor delay in (1, 2, 4):\n    try:\n        results = await provider.make_query(q, num_links)\n        break\n    except RateLimitExceeded:\n        await asyncio.sleep(delay)\nelse:\n    raise","preventionTips":["Space requests at least brave.rate_limit seconds apart via a shared limiter.","Cap web_search.num_concurrent_consumers to your plan's throughput.","Retry only 429/QuotaConsumed with backoff; never hammer through auth errors."],"tags":["brave","rate-limit","retry","api"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}