11# Browserbase Search API Examples
22
3- Common patterns for using the Browserbase Search API. The SDK does not yet have a search method, so all examples use cURL.
3+ Common patterns for using the Browserbase Search API. Examples show CLI and cURL usage .
44
55## Safety Notes
66
@@ -10,6 +10,12 @@ Common patterns for using the Browserbase Search API. The SDK does not yet have
1010
1111** User request** : "Find pages about browser automation"
1212
13+ ### CLI
14+ ``` bash
15+ bb search " browser automation"
16+ ```
17+
18+ ### cURL
1319``` bash
1420curl -s -X POST " https://api.browserbase.com/v1/search" \
1521 -H " Content-Type: application/json" \
@@ -21,17 +27,29 @@ curl -s -X POST "https://api.browserbase.com/v1/search" \
2127
2228** User request** : "Find the top 3 results for web scraping tools"
2329
30+ ### CLI
31+ ``` bash
32+ bb search " web scraping tools" --num-results 3
33+ ```
34+
35+ ### cURL
2436``` bash
2537curl -s -X POST " https://api.browserbase.com/v1/search" \
2638 -H " Content-Type: application/json" \
2739 -H " X-BB-API-Key: $BROWSERBASE_API_KEY " \
2840 -d ' {"query": "web scraping tools", "numResults": 3}' | jq ' .results[] | {title, url}'
2941```
3042
31- ## Example 3: Search and Extract URLs
43+ ## Example 3: Search and Save Results
3244
3345** User request** : "Get me a list of URLs about AI agents"
3446
47+ ### CLI
48+ ``` bash
49+ bb search " AI agents" --output ai-agents.json
50+ ```
51+
52+ ### cURL
3553``` bash
3654curl -s -X POST " https://api.browserbase.com/v1/search" \
3755 -H " Content-Type: application/json" \
@@ -43,6 +61,17 @@ curl -s -X POST "https://api.browserbase.com/v1/search" \
4361
4462** User request** : "Find articles about web scraping and get the content of the first result"
4563
64+ ### CLI
65+ ``` bash
66+ # Step 1: Search and save results
67+ bb search " web scraping tutorial" --num-results 1 --output results.json
68+
69+ # Step 2: Extract URL and fetch it
70+ URL=$( jq -r ' .results[0].url' results.json)
71+ bb fetch " $URL " --output page.html
72+ ```
73+
74+ ### cURL
4675``` bash
4776# Step 1: Search
4877URL=$( curl -s -X POST " https://api.browserbase.com/v1/search" \
@@ -61,6 +90,20 @@ curl -s -X POST "https://api.browserbase.com/v1/fetch" \
6190
6291** User request** : "Search for the top 5 results about headless browsers and save each page"
6392
93+ ### CLI
94+ ``` bash
95+ # Search and save results
96+ bb search " headless browser comparison" --num-results 5 --output results.json
97+
98+ # Fetch each result
99+ jq -r ' .results[].url' results.json | while read -r url; do
100+ filename=$( echo " $url " | sed ' s|https\?://||;s|/|_|g' ) .html
101+ bb fetch " $url " --output " $filename "
102+ echo " Saved: $filename "
103+ done
104+ ```
105+
106+ ### cURL
64107``` bash
65108# Search and iterate over results
66109curl -s -X POST " https://api.browserbase.com/v1/search" \
@@ -79,8 +122,7 @@ curl -s -X POST "https://api.browserbase.com/v1/search" \
79122
80123## Tips
81124
82- - ** Use Search to discover URLs** before fetching or browsing them
83- - ** Pipe through ` jq ` ** to extract specific fields from the JSON response
84- - ** Chain Search + Fetch** for a two-step research workflow: find URLs, then get content
85- - ** Limit results** with ` numResults ` when you only need a few top hits
125+ - ** Chain ` bb search ` + ` bb fetch ` ** for a simple search-then-read workflow
126+ - ** Use ` --output ` ** to save results to a file for further processing
127+ - ** Limit results** with ` --num-results ` when you only need a few top hits
86128- ** Fall back to Browser skill** when you need to interact with pages or render JavaScript
0 commit comments