Setting the file. One moment.
Subchapter 16.1
EXAMPLES.mdMarkdown3 KBView on GitHub
Common patterns for using the Browserbase Search API. The SDK does not yet have a search method, so all examples use cURL.
User request: “Find pages about browser automation”
curl -s -X POST "https://api.browserbase.com/v1/search" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"query": "browser automation"}' | jq '.results[] | {title, url}'User request: “Find the top 3 results for web scraping tools”
curl -s -X POST "https://api.browserbase.com/v1/search" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"query": "web scraping tools", "numResults": 3}' | jq '.results[] | {title, url}'User request: “Get me a list of URLs about AI agents”
curl -s -X POST "https://api.browserbase.com/v1/search" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"query": "AI agents"}' | jq -r '.results[].url'User request: “Find articles about web scraping and get the content of the first result”
# Step 1: Search
URL=$(curl -s -X POST "https://api.browserbase.com/v1/search" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"query": "web scraping tutorial", "numResults": 1}' | jq -r '.results[0].url')
# Step 2: Fetch the top result
curl -s -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d "{\"url\": \"$URL\"}" | jq -r '.content'User request: “Search for the top 5 results about headless browsers and save each page”
# Search and iterate over results
curl -s -X POST "https://api.browserbase.com/v1/search" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"query": "headless browser comparison", "numResults": 5}' | \
jq -r '.results[].url' | while read -r url; do
filename=$(echo "$url" | sed 's|https\?://||;s|/|_|g').html
curl -s -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d "{\"url\": \"$url\"}" | jq -r '.content' > "$filename"
echo "Saved: $filename"
donejq to extract specific fields from the JSON responsenumResults when you only need a few top hits