Skip to content

Commit 98a399c

Browse files
monadoidsamfinton
andauthored
STG-1808: Deprecate browserbase project ID (#87)
* Deprecate browserbase project ID * Fix Ruby project ID assertion --------- Co-authored-by: samfinton <samfinton@samLaptopm5.galaxus.box>
1 parent db24a9a commit 98a399c

11 files changed

Lines changed: 40 additions & 46 deletions

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ require "playwright"
9090

9191
client = Stagehand::Client.new(
9292
browserbase_api_key: ENV["BROWSERBASE_API_KEY"],
93-
browserbase_project_id: ENV["BROWSERBASE_PROJECT_ID"],
9493
model_api_key: ENV["MODEL_API_KEY"],
9594
server: "remote"
9695
)
@@ -162,10 +161,10 @@ client.sessions.end_(session_id)
162161

163162
Set your environment variables (from `examples/.env.example`):
164163

165-
- `STAGEHAND_API_URL`
166164
- `MODEL_API_KEY`
167165
- `BROWSERBASE_API_KEY`
168-
- `BROWSERBASE_PROJECT_ID`
166+
167+
`STAGEHAND_API_URL` is optional and defaults to the hosted Stagehand API. `STAGEHAND_BASE_URL` remains supported as a deprecated fallback when `STAGEHAND_API_URL` is unset.
169168

170169
```bash
171170
cp examples/.env.example examples/.env

examples/.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
STAGEHAND_API_URL=https://api.stagehand.browserbase.com
21
MODEL_API_KEY=sk-proj-your-llm-api-key-here
32
BROWSERBASE_API_KEY=bb_live_your_api_key_here
4-
BROWSERBASE_PROJECT_ID=your-bb-project-uuid-here

examples/env.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
module ExampleEnv
44
REQUIRED_KEYS = %w[
5-
STAGEHAND_API_URL
65
MODEL_API_KEY
76
BROWSERBASE_API_KEY
8-
BROWSERBASE_PROJECT_ID
97
].freeze
108

119
def self.load!

examples/local_browser_playwright_example.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
model_key = ENV["MODEL_API_KEY"]
1818
browserbase_api_key = ENV["BROWSERBASE_API_KEY"].to_s
19-
browserbase_project_id = ENV["BROWSERBASE_PROJECT_ID"].to_s
2019

2120
missing = []
2221
missing << "MODEL_API_KEY" if model_key.to_s.empty?
2322
missing << "BROWSERBASE_API_KEY" if browserbase_api_key.empty?
24-
missing << "BROWSERBASE_PROJECT_ID" if browserbase_project_id.empty?
2523

2624
unless missing.empty?
2725
warn("Set #{missing.join(', ')} to run the local Playwright example.")
@@ -60,7 +58,6 @@ def stream_with_result(label, stream)
6058

6159
client = Stagehand::Client.new(
6260
browserbase_api_key: browserbase_api_key,
63-
browserbase_project_id: browserbase_project_id,
6461
model_api_key: model_key,
6562
server: "local"
6663
)

examples/local_server_multiregion_browser_example.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
require_relative "env"
88
ExampleEnv.load!
99
browserbase_api_key = ENV["BROWSERBASE_API_KEY"].to_s
10-
browserbase_project_id = ENV["BROWSERBASE_PROJECT_ID"].to_s
1110
model_key = ENV["MODEL_API_KEY"].to_s
1211

1312
missing = []
1413
missing << "BROWSERBASE_API_KEY" if browserbase_api_key.empty?
15-
missing << "BROWSERBASE_PROJECT_ID" if browserbase_project_id.empty?
1614
missing << "MODEL_API_KEY" if model_key.empty?
1715

1816
unless missing.empty?
@@ -22,7 +20,6 @@
2220

2321
client = Stagehand::Client.new(
2422
browserbase_api_key: browserbase_api_key,
25-
browserbase_project_id: browserbase_project_id,
2623
model_api_key: model_key,
2724
server: "local"
2825
)

examples/remote_browser_example.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
require_relative "env"
88
ExampleEnv.load!
99
browserbase_api_key = ENV["BROWSERBASE_API_KEY"].to_s
10-
browserbase_project_id = ENV["BROWSERBASE_PROJECT_ID"].to_s
1110
model_key = ENV["MODEL_API_KEY"].to_s
1211

1312
missing = []
1413
missing << "BROWSERBASE_API_KEY" if browserbase_api_key.empty?
15-
missing << "BROWSERBASE_PROJECT_ID" if browserbase_project_id.empty?
1614
missing << "MODEL_API_KEY" if model_key.empty?
1715

1816
unless missing.empty?
@@ -22,7 +20,6 @@
2220

2321
client = Stagehand::Client.new(
2422
browserbase_api_key: browserbase_api_key,
25-
browserbase_project_id: browserbase_project_id,
2623
model_api_key: model_key
2724
)
2825

examples/remote_browser_playwright_example.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
model_key = ENV["MODEL_API_KEY"]
1818
browserbase_api_key = ENV["BROWSERBASE_API_KEY"].to_s
19-
browserbase_project_id = ENV["BROWSERBASE_PROJECT_ID"].to_s
2019

2120
missing = []
2221
missing << "MODEL_API_KEY" if model_key.to_s.empty?
2322
missing << "BROWSERBASE_API_KEY" if browserbase_api_key.empty?
24-
missing << "BROWSERBASE_PROJECT_ID" if browserbase_project_id.empty?
2523

2624
unless missing.empty?
2725
warn("Set #{missing.join(', ')} to run the remote Playwright example.")
@@ -83,7 +81,6 @@ def stream_with_result(label, stream)
8381

8482
client = Stagehand::Client.new(
8583
browserbase_api_key: browserbase_api_key,
86-
browserbase_project_id: browserbase_project_id,
8784
model_api_key: model_key,
8885
server: "remote"
8986
)

lib/stagehand/client.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Client < Stagehand::Internal::Transport::BaseClient
3434
#
3535
# @return [Hash{String=>String}]
3636
private def auth_headers
37-
{**bb_api_key_auth, **bb_project_id_auth, **llm_model_api_key_auth}
37+
{**bb_api_key_auth, **llm_model_api_key_auth}
3838
end
3939

4040
# @api private
@@ -48,7 +48,7 @@ class Client < Stagehand::Internal::Transport::BaseClient
4848
#
4949
# @return [Hash{String=>String}]
5050
private def bb_project_id_auth
51-
{"x-bb-project-id" => @browserbase_project_id}
51+
{}
5252
end
5353

5454
# @api private
@@ -63,16 +63,17 @@ class Client < Stagehand::Internal::Transport::BaseClient
6363
# @param browserbase_api_key [String, nil] Your [Browserbase API Key](https://www.browserbase.com/settings) Defaults to
6464
# `ENV["BROWSERBASE_API_KEY"]`
6565
#
66-
# @param browserbase_project_id [String, nil] Your [Browserbase Project ID](https://www.browserbase.com/settings) Defaults to
67-
# `ENV["BROWSERBASE_PROJECT_ID"]`
66+
# @param browserbase_project_id [String, nil] Deprecated. Browserbase API keys are now project-scoped, so
67+
# this value is accepted for backwards compatibility and ignored.
6868
#
6969
# @param model_api_key [String, nil] Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)
7070
# Defaults to `ENV["MODEL_API_KEY"]`
7171
#
7272
# @param server [String] Server mode to use ("remote" or "local"). Defaults to "remote"
7373
#
7474
# @param base_url [String, nil] Override the default base URL for the API, e.g.,
75-
# `"https://api.example.com/v2/"`. Defaults to `ENV["STAGEHAND_API_URL"]`
75+
# `"https://api.example.com/v2/"`. Defaults to `ENV["STAGEHAND_API_URL"]`,
76+
# then `ENV["STAGEHAND_BASE_URL"]`
7677
#
7778
# @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
7879
#
@@ -83,7 +84,7 @@ class Client < Stagehand::Internal::Transport::BaseClient
8384
# @param max_retry_delay [Float]
8485
def initialize(
8586
browserbase_api_key: ENV["BROWSERBASE_API_KEY"],
86-
browserbase_project_id: ENV["BROWSERBASE_PROJECT_ID"],
87+
browserbase_project_id: nil,
8788
model_api_key: ENV["MODEL_API_KEY"],
8889
server: "remote",
8990
base_url: ENV["STAGEHAND_API_URL"] || ENV["STAGEHAND_BASE_URL"],
@@ -99,10 +100,6 @@ def initialize(
99100
raise ArgumentError,
100101
"browserbase_api_key is required, and can be set via environ: \"BROWSERBASE_API_KEY\""
101102
end
102-
if browserbase_project_id.nil?
103-
raise ArgumentError,
104-
"browserbase_project_id is required, and can be set via environ: \"BROWSERBASE_PROJECT_ID\""
105-
end
106103
if model_api_key.nil?
107104
raise ArgumentError,
108105
"model_api_key is required, and can be set via environ: \"MODEL_API_KEY\""

lib/stagehand/local.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def self.ensure_browserbase_credentials!(client:, params:)
5050

5151
missing = []
5252
missing << "browserbase_api_key" if client.browserbase_api_key.to_s.empty?
53-
missing << "browserbase_project_id" if client.browserbase_project_id.to_s.empty?
5453
return if missing.empty?
5554

5655
message =
@@ -213,10 +212,9 @@ def ensure_executable(path)
213212
end
214213

215214
class ServerManager
216-
def initialize(model_api_key:, browserbase_api_key:, browserbase_project_id:)
215+
def initialize(model_api_key:, browserbase_api_key:)
217216
@model_api_key = model_api_key
218217
@browserbase_api_key = browserbase_api_key
219-
@browserbase_project_id = browserbase_project_id
220218
@host = DEFAULT_HOST
221219
@port = 0
222220
@mutex = Mutex.new
@@ -335,9 +333,6 @@ def build_env(host:, port:)
335333
if @browserbase_api_key.to_s != ""
336334
env["BROWSERBASE_API_KEY"] = @browserbase_api_key
337335
end
338-
if @browserbase_project_id.to_s != ""
339-
env["BROWSERBASE_PROJECT_ID"] = @browserbase_project_id
340-
end
341336
env
342337
end
343338

@@ -376,8 +371,6 @@ def initialize(server: "remote", **kwargs)
376371
kwargs[:base_url] = base_url.nil? ? "http://#{DEFAULT_HOST}" : base_url
377372
kwargs[:browserbase_api_key] =
378373
kwargs[:browserbase_api_key] || ENV["BROWSERBASE_API_KEY"] || ""
379-
kwargs[:browserbase_project_id] =
380-
kwargs[:browserbase_project_id] || ENV["BROWSERBASE_PROJECT_ID"] || ""
381374
end
382375

383376
super(**kwargs)
@@ -386,8 +379,7 @@ def initialize(server: "remote", **kwargs)
386379

387380
@local_server_manager = Stagehand::Local::ServerManager.new(
388381
model_api_key: @model_api_key,
389-
browserbase_api_key: @browserbase_api_key,
390-
browserbase_project_id: @browserbase_project_id
382+
browserbase_api_key: @browserbase_api_key
391383
)
392384
end
393385

@@ -421,8 +413,7 @@ def bb_api_key_auth
421413
end
422414

423415
def bb_project_id_auth
424-
return {} if @browserbase_project_id.to_s.empty?
425-
super
416+
{}
426417
end
427418
end
428419

rbi/stagehand/client.rbi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Stagehand
1414
sig { returns(String) }
1515
attr_reader :browserbase_api_key
1616

17-
# Your [Browserbase Project ID](https://www.browserbase.com/settings)
17+
# Deprecated. Browserbase API keys are now project-scoped, so this value is accepted for backwards compatibility and ignored.
1818
sig { returns(String) }
1919
attr_reader :browserbase_project_id
2020

@@ -63,16 +63,16 @@ module Stagehand
6363
# Your [Browserbase API Key](https://www.browserbase.com/settings) Defaults to
6464
# `ENV["BROWSERBASE_API_KEY"]`
6565
browserbase_api_key: ENV["BROWSERBASE_API_KEY"],
66-
# Your [Browserbase Project ID](https://www.browserbase.com/settings) Defaults to
67-
# `ENV["BROWSERBASE_PROJECT_ID"]`
68-
browserbase_project_id: ENV["BROWSERBASE_PROJECT_ID"],
66+
# Deprecated. Browserbase API keys are now project-scoped, so this value is accepted for backwards compatibility and ignored.
67+
browserbase_project_id: nil,
6968
# Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)
7069
# Defaults to `ENV["MODEL_API_KEY"]`
7170
model_api_key: ENV["MODEL_API_KEY"],
7271
# Server mode to use ("remote" or "local"). Defaults to "remote"
7372
server: "remote",
7473
# Override the default base URL for the API, e.g.,
75-
# `"https://api.example.com/v2/"`. Defaults to `ENV["STAGEHAND_API_URL"]`
74+
# `"https://api.example.com/v2/"`. Defaults to `ENV["STAGEHAND_API_URL"]`,
75+
# then `ENV["STAGEHAND_BASE_URL"]`
7676
base_url: ENV["STAGEHAND_API_URL"] || ENV["STAGEHAND_BASE_URL"],
7777
# Max number of retries to attempt after a failed retryable request.
7878
max_retries: Stagehand::Client::DEFAULT_MAX_RETRIES,

0 commit comments

Comments
 (0)