fix: retry Brave Search on HTTP 429 rate limit with 1s delay (#20255)

* Update brave.py

* Update brave.py
This commit is contained in:
Classic298
2025-12-30 17:37:44 +04:00
committed by GitHub
parent 95ce70c4fd
commit 464846d4a3
@@ -1,4 +1,5 @@
import logging
import time
from typing import Optional
import requests
@@ -25,6 +26,14 @@ def search_brave(
params = {"q": query, "count": count}
response = requests.get(url, headers=headers, params=params)
# Handle 429 rate limiting - Brave free tier allows 1 request/second
# If rate limited, wait 1 second and retry once before failing
if response.status_code == 429:
log.info("Brave Search API rate limited (429), retrying after 1 second...")
time.sleep(1)
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
json_response = response.json()