Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

improve examples

mertunsallb14b8d0f28a7
diff --git a/examples/search/search_url.py b/examples/search/search_url.py
index 2eb3687ab..c9687124c 100644
--- a/examples/search/search_url.py
+++ b/examples/search/search_url.py
@@ -20,9 +20,16 @@ load_dotenv()
async def search_url(url: str, query: str, depth: int = 2):
+ # Validate API key exists
+ api_key = os.getenv('BROWSER_USE_API_KEY')
+ if not api_key:
+ print('❌ Error: BROWSER_USE_API_KEY environment variable is not set.')
+ print('Please set your API key: export BROWSER_USE_API_KEY="your_api_key_here"')
+ return None
+
payload = {'url': url, 'query': query, 'depth': depth}
- headers = {'Authorization': f'Bearer {os.getenv("BROWSER_USE_API_KEY")}', 'Content-Type': 'application/json'}
+ headers = {'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}
print('Testing Search URL API...')
print(f'URL: {url}')
diff --git a/examples/search/simple_search.py b/examples/search/simple_search.py
index 487429ab8..8b5ac619d 100644
--- a/examples/search/simple_search.py
+++ b/examples/search/simple_search.py
@@ -20,9 +20,16 @@ load_dotenv()
async def simple_search(query: str, max_websites: int = 5, depth: int = 2):
+ # Validate API key exists
+ api_key = os.getenv('BROWSER_USE_API_KEY')
+ if not api_key:
+ print('❌ Error: BROWSER_USE_API_KEY environment variable is not set.')
+ print('Please set your API key: export BROWSER_USE_API_KEY="your_api_key_here"')
+ return None
+
payload = {'query': query, 'max_websites': max_websites, 'depth': depth}
- headers = {'Authorization': f'Bearer {os.getenv("BROWSER_USE_API_KEY")}', 'Content-Type': 'application/json'}
+ headers = {'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}
print('Testing Simple Search API...')
print(f'Query: {query}')