Skip to content

Commit 7cf4107

Browse files
authored
Migrate templates to Model Gateway — remove separate model API keys, bump SDKs (#76)
* Migrate templates to Browserbase Model Gateway * Fix Model Gateway naming and remove CUA notes from READMEs * using correct package version * updated stagehand package version to use latest * Remove BROWSERBASE_PROJECT_ID from Stagehand templates * bumped bb sdk versons
1 parent 6876a3f commit 7cf4107

172 files changed

Lines changed: 309 additions & 542 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ A comprehensive collection of ready-to-use automation templates demonstrating th
2020

2121
> **💡 Pro Tip**: Each template's README contains detailed installation steps, environment variable requirements, and troubleshooting guides specific to that template.
2222
23+
## Model Gateway
24+
25+
Templates use the Model Gateway to route LLM requests — you only need your `BROWSERBASE_API_KEY`. No separate OpenAI, Anthropic, or Google API keys required. Supported models include OpenAI, Anthropic, and Google (Gemini).
26+
27+
> **Note**: CUA (Computer Use Agent) models are not yet supported through the Model Gateway. Templates using CUA models still require a separate model provider API key.
28+
2329
## 📚 Resources
2430

2531
### Documentation

go/hackernews/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
2. Set required environment variables:
2727
```bash
2828
export BROWSERBASE_API_KEY="your-api-key"
29-
export BROWSERBASE_PROJECT_ID="your-project-id"
3029
export MODEL_API_KEY="your-model-api-key"
3130
```
3231
3. Run the example:
@@ -48,10 +47,10 @@
4847
## COMMON PITFALLS
4948

5049
- Missing Go installation: Ensure Go 1.22+ is installed (`go version`)
51-
- Missing environment variables: Verify BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, and MODEL_API_KEY are set
50+
- Missing environment variables: Verify BROWSERBASE_API_KEY and MODEL_API_KEY are set
5251
- Module not found: Run `go mod download` if dependencies aren't resolved
5352
- Network issues: Check internet connection and website accessibility
54-
- Session errors: Verify API keys are valid and project ID exists in Browserbase dashboard
53+
- Session errors: Verify API keys are valid in Browserbase dashboard
5554
- Find more information on your Browserbase dashboard -> https://www.browserbase.com/sign-in
5655

5756
## USE CASES

go/hackernews/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func main() {
1515
// Create client using environment variables
1616
client := stagehand.NewClient(
1717
option.WithBrowserbaseAPIKey(os.Getenv("BROWSERBASE_API_KEY")),
18-
option.WithBrowserbaseProjectID(os.Getenv("BROWSERBASE_PROJECT_ID")),
1918
option.WithModelAPIKey(os.Getenv("MODEL_API_KEY")),
2019
)
2120

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# Browserbase credentials - get these from https://www.browserbase.com/settings
22
BROWSERBASE_API_KEY=your_browserbase_api_key
3-
BROWSERBASE_PROJECT_ID=your_browserbase_project_id
4-
5-
# Model API key for Stagehand AI capabilities
6-
# Use Google API key for Gemini models, or OpenAI API key for GPT models
7-
MODEL_API_KEY=your_model_api_key

python/amazon-global-price-comparison/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
1. cd python/amazon-global-price-comparison
2626
2. cp .env.example .env
2727
3. Add required API keys to .env:
28-
- `BROWSERBASE_PROJECT_ID`
2928
- `BROWSERBASE_API_KEY`
30-
- `MODEL_API_KEY` (Google API key for Gemini, or OpenAI API key)
3129
4. Run the script:
3230
```bash
3331
uv run python main.py
@@ -45,7 +43,7 @@
4543

4644
- **Browserbase Developer plan or higher is required to use proxies**
4745
- "ModuleNotFoundError": ensure you're running with `uv run python main.py` (uv automatically installs dependencies from pyproject.toml)
48-
- Missing credentials: verify .env contains `BROWSERBASE_PROJECT_ID`, `BROWSERBASE_API_KEY`, and `MODEL_API_KEY`
46+
- Missing credentials: verify .env contains `BROWSERBASE_API_KEY`
4947
- Geolocation fields are case-insensitive (city, country can be any case)
5048
- Amazon may show different products in different regions - comparison works best for globally available products
5149
- ERR_TUNNEL_CONNECTION_FAILED: indicates either a temporary proxy hiccup or a site unsupported by built-in proxies

python/amazon-global-price-comparison/main.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from browserbase import Browserbase
99
from dotenv import load_dotenv
1010
from pydantic import BaseModel, Field
11-
1211
from stagehand import AsyncStagehand
1312

1413
# Load environment variables from .env file
15-
# Required: BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, MODEL_API_KEY
14+
# Required: BROWSERBASE_API_KEY
1615
load_dotenv()
1716

1817

@@ -34,7 +33,9 @@ class Product(BaseModel):
3433
)
3534
product_url: str = Field(
3635
default="N/A",
37-
description="The full href URL link to the product detail page (starting with https:// or /dp/)",
36+
description=(
37+
"The full href URL link to the product detail page (starting with https:// or /dp/)"
38+
),
3839
)
3940

4041

@@ -58,7 +59,8 @@ class CountryConfig:
5859

5960

6061
# Supported countries for price comparison
61-
# Add or remove countries as needed - see https://docs.browserbase.com/features/proxies for available geolocations
62+
# Add or remove countries as needed - see
63+
# https://docs.browserbase.com/features/proxies for available geolocations
6264
COUNTRIES: list[CountryConfig] = [
6365
CountryConfig(name="United States", code="US", city=None, currency="USD"),
6466
CountryConfig(name="United Kingdom", code="GB", city="LONDON", currency="GBP"),
@@ -127,8 +129,6 @@ async def get_products_for_country(
127129
# Initialize AsyncStagehand client (v3 API)
128130
client = AsyncStagehand(
129131
browserbase_api_key=os.environ.get("BROWSERBASE_API_KEY"),
130-
browserbase_project_id=os.environ.get("BROWSERBASE_PROJECT_ID"),
131-
model_api_key=os.environ.get("MODEL_API_KEY"),
132132
)
133133

134134
try:
@@ -170,7 +170,11 @@ async def get_products_for_country(
170170
},
171171
"price": {
172172
"type": "string",
173-
"description": "The product price including currency symbol (e.g., '$29.99'). If no price is visible, return 'N/A'",
173+
"description": (
174+
"The product price including currency"
175+
" symbol (e.g., '$29.99'). If no"
176+
" price is visible, return 'N/A'"
177+
),
174178
},
175179
"rating": {
176180
"type": "string",
@@ -193,14 +197,19 @@ async def get_products_for_country(
193197
}
194198

195199
extract_response = await stagehand_session.extract(
196-
instruction=f"""Extract the first {results_count} product search results from this Amazon page. For each product, extract:
197-
1. name: the full product title
198-
2. price: the displayed price WITH currency symbol (like $599.99 or 599,99 EUR). If no price shown, use "N/A"
199-
3. rating: the star rating text (like "4.5 out of 5 stars")
200-
4. reviews_count: the number of reviews (like "2,508")
201-
5. product_url: the href link to the product page (starts with /dp/ or https://)
202-
203-
Only extract actual product listings, skip sponsored ads or recommendations.""",
200+
instruction=(
201+
f"Extract the first {results_count} product search results"
202+
" from this Amazon page. For each product, extract:"
203+
" 1. name: the full product title"
204+
" 2. price: the displayed price WITH currency symbol"
205+
' (like $599.99 or 599,99 EUR). If no price shown, use "N/A"'
206+
' 3. rating: the star rating text (like "4.5 out of 5 stars")'
207+
' 4. reviews_count: the number of reviews (like "2,508")'
208+
" 5. product_url: the href link to the product page"
209+
" (starts with /dp/ or https://)"
210+
" Only extract actual product listings, skip sponsored"
211+
" ads or recommendations."
212+
),
204213
schema=products_schema,
205214
)
206215

@@ -368,9 +377,7 @@ async def main():
368377
except Exception as err:
369378
print(f"Application error: {err}")
370379
print("\nCommon issues:")
371-
print(
372-
" - Check .env file has BROWSERBASE_PROJECT_ID, BROWSERBASE_API_KEY, and MODEL_API_KEY"
373-
)
380+
print(" - Check .env file has BROWSERBASE_API_KEY")
374381
print(
375382
" - Verify geolocation proxy locations are valid "
376383
"(see https://docs.browserbase.com/features/proxies)"

python/amazon-global-price-comparison/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description = "Compare Amazon product prices across multiple countries using geo
55
readme = "README.md"
66
requires-python = ">=3.9"
77
dependencies = [
8-
"browserbase>=1.5.0",
8+
"browserbase>=1.7.0",
99
"python-dotenv",
1010
"pydantic>=2.0.0",
11-
"stagehand",
11+
"stagehand>=3.19.0",
1212
]
1313

1414
[project.optional-dependencies]
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
# Browserbase credentials (required)
22
# Get these from https://www.browserbase.com/settings
3-
BROWSERBASE_PROJECT_ID=your-browserbase-project-id
43
BROWSERBASE_API_KEY=your-browserbase-api-key
5-
6-
# Model API key (required - use one of these)
7-
# For Google Gemini models
8-
MODEL_API_KEY=your-google-api-key
9-
# Or alternatively:
10-
# GOOGLE_API_KEY=your-google-api-key

python/amazon-product-scraping/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
1. cd python/amazon-product-scraping
2121
2. cp .env.example .env (or create .env with required keys)
22-
3. Add `BROWSERBASE_PROJECT_ID`, `BROWSERBASE_API_KEY`, and `MODEL_API_KEY` (or `GOOGLE_API_KEY`) to .env
22+
3. Add `BROWSERBASE_API_KEY` to .env
2323
4. Optionally edit `SEARCH_QUERY` in main.py
2424
5. Run the script:
2525
```bash
@@ -38,8 +38,7 @@
3838
## COMMON PITFALLS
3939

4040
- **Import errors**: Ensure you're running with `uv run python main.py` so dependencies are installed
41-
- **Missing credentials**: Verify .env contains `BROWSERBASE_PROJECT_ID`, `BROWSERBASE_API_KEY`, and `MODEL_API_KEY` (or `GOOGLE_API_KEY`)
42-
- **Google API access**: Ensure you have access to the gemini-2.5-flash model
41+
- **Missing credentials**: Verify .env contains `BROWSERBASE_API_KEY`
4342
- **Amazon layout changes**: Extraction may need prompt/schema updates if Amazon changes their search results UI
4443
- Find more information on your Browserbase dashboard → https://www.browserbase.com/sign-in
4544

python/amazon-product-scraping/main.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from dotenv import load_dotenv
99
from pydantic import BaseModel, Field
10-
1110
from stagehand import AsyncStagehand
1211

1312

@@ -45,7 +44,7 @@ def resolve_refs(obj):
4544

4645

4746
# Load environment variables from .env file
48-
# Required: BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, MODEL_API_KEY (or GOOGLE_API_KEY)
47+
# Required: BROWSERBASE_API_KEY
4948
load_dotenv()
5049

5150
# ============= CONFIGURATION =============
@@ -67,11 +66,9 @@ async def main():
6766
print("Starting Amazon Product Scraping...")
6867

6968
# Initialize AsyncStagehand client (v3 BYOB architecture)
70-
# Uses environment variables: BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, MODEL_API_KEY
69+
# Uses environment variable: BROWSERBASE_API_KEY
7170
client = AsyncStagehand(
7271
browserbase_api_key=os.environ.get("BROWSERBASE_API_KEY"),
73-
browserbase_project_id=os.environ.get("BROWSERBASE_PROJECT_ID"),
74-
model_api_key=os.environ.get("MODEL_API_KEY") or os.environ.get("GOOGLE_API_KEY"),
7572
)
7673

7774
# Start a Stagehand session with the specified model
@@ -131,8 +128,7 @@ async def main():
131128
except Exception as err:
132129
print(f"Error in Amazon product scraping: {err}")
133130
print("Common issues:")
134-
print(" - Check .env file has BROWSERBASE_PROJECT_ID and BROWSERBASE_API_KEY")
135-
print(" - Verify MODEL_API_KEY or GOOGLE_API_KEY is set for the model")
131+
print(" - Check .env file has BROWSERBASE_API_KEY")
136132
print(" - Verify network connectivity")
137133
print("Docs: https://docs.stagehand.dev")
138134
exit(1)

0 commit comments

Comments
 (0)