Skip to content

Commit 1bb5d8a

Browse files
monadoidsamfinton
andauthored
STG-1808: Deprecate browserbase project ID (#38)
* Deprecate browserbase project ID * Fix CI formatting --------- Co-authored-by: samfinton <samfinton@samLaptopm5.galaxus.box>
1 parent 1a0a44c commit 1bb5d8a

9 files changed

Lines changed: 39 additions & 47 deletions

File tree

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ Multiregion support: see `stagehand-java-example/src/main/java/com/stagehand/api
115115

116116
Set your environment variables (from `examples/.env.example`):
117117

118-
- `STAGEHAND_API_URL`
119118
- `MODEL_API_KEY`
120119
- `BROWSERBASE_API_KEY`
121-
- `BROWSERBASE_PROJECT_ID`
122120

123121
```bash
124122
cp examples/.env.example examples/.env
@@ -258,8 +256,8 @@ Configure the client using system properties or environment variables:
258256
import com.browserbase.api.client.StagehandClient;
259257
import com.browserbase.api.client.okhttp.StagehandOkHttpClient;
260258

261-
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.browserbaseProjectId`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
262-
// Or configures using the `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
259+
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
260+
// Or configures using the `BROWSERBASE_API_KEY`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
263261
StagehandClient client = StagehandOkHttpClient.fromEnv();
264262
```
265263

@@ -271,7 +269,6 @@ import com.browserbase.api.client.okhttp.StagehandOkHttpClient;
271269

272270
StagehandClient client = StagehandOkHttpClient.builder()
273271
.browserbaseApiKey("My Browserbase API Key")
274-
.browserbaseProjectId("My Browserbase Project ID")
275272
.modelApiKey("My Model API Key")
276273
.build();
277274
```
@@ -283,8 +280,8 @@ import com.browserbase.api.client.StagehandClient;
283280
import com.browserbase.api.client.okhttp.StagehandOkHttpClient;
284281

285282
StagehandClient client = StagehandOkHttpClient.builder()
286-
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.browserbaseProjectId`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
287-
// Or configures using the `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
283+
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
284+
// Or configures using the `BROWSERBASE_API_KEY`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
288285
.fromEnv()
289286
.browserbaseApiKey("My Browserbase API Key")
290287
.build();
@@ -295,9 +292,10 @@ See this table for the available options:
295292
| Setter | System property | Environment variable | Required | Default value |
296293
| ---------------------- | -------------------------------- | ------------------------ | -------- | ----------------------------------------- |
297294
| `browserbaseApiKey` | `stagehand.browserbaseApiKey` | `BROWSERBASE_API_KEY` | true | - |
298-
| `browserbaseProjectId` | `stagehand.browserbaseProjectId` | `BROWSERBASE_PROJECT_ID` | false | - |
299295
| `modelApiKey` | `stagehand.modelApiKey` | `MODEL_API_KEY` | true | - |
300-
| `baseUrl` | `stagehand.baseUrl` | `STAGEHAND_API_URL` | true | `"https://api.stagehand.browserbase.com"` |
296+
| `baseUrl` | `stagehand.baseUrl` | `STAGEHAND_API_URL` | false | `"https://api.stagehand.browserbase.com"` |
297+
298+
`browserbaseProjectId` is deprecated, accepted for backwards compatibility, and ignored. `STAGEHAND_BASE_URL` remains supported as a deprecated fallback when `STAGEHAND_API_URL` is unset.
301299

302300
System properties take precedence over environment variables.
303301

@@ -345,8 +343,8 @@ import com.browserbase.api.models.sessions.SessionActParams;
345343
import com.browserbase.api.models.sessions.SessionActResponse;
346344
import java.util.concurrent.CompletableFuture;
347345

348-
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.browserbaseProjectId`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
349-
// Or configures using the `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
346+
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
347+
// Or configures using the `BROWSERBASE_API_KEY`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
350348
StagehandClient client = StagehandOkHttpClient.fromEnv();
351349

352350
SessionActParams params = SessionActParams.builder()
@@ -365,8 +363,8 @@ import com.browserbase.api.models.sessions.SessionActParams;
365363
import com.browserbase.api.models.sessions.SessionActResponse;
366364
import java.util.concurrent.CompletableFuture;
367365

368-
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.browserbaseProjectId`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
369-
// Or configures using the `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
366+
// Configures using the `stagehand.browserbaseApiKey`, `stagehand.modelApiKey` and `stagehand.baseUrl` system properties
367+
// Or configures using the `BROWSERBASE_API_KEY`, `MODEL_API_KEY` and `STAGEHAND_API_URL` environment variables
370368
StagehandClientAsync client = StagehandOkHttpClientAsync.fromEnv();
371369

372370
SessionActParams params = SessionActParams.builder()

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

stagehand-java-client-okhttp/src/main/kotlin/com/browserbase/api/client/okhttp/OkHttpClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClie
103103
clientBuilder.addNetworkInterceptor(
104104
HttpLoggingInterceptor().setLevel(logLevel).apply {
105105
redactHeader("x-bb-api-key")
106-
redactHeader("x-bb-project-id")
107106
redactHeader("x-model-api-key")
108107
}
109108
)

stagehand-java-core/src/main/kotlin/com/browserbase/api/core/ClientOptions.kt

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private constructor(
327327

328328
/**
329329
* Deprecated. Browserbase API keys are now project-scoped, so this value is no longer
330-
* required.
330+
* required. Accepted for backwards compatibility; it is ignored.
331331
*/
332332
fun browserbaseProjectId(browserbaseProjectId: String?) = apply {
333333
this.browserbaseProjectId = browserbaseProjectId
@@ -430,12 +430,11 @@ private constructor(
430430
*
431431
* See this table for the available options:
432432
*
433-
* |Setter |System property |Environment variable |Required|Default value |
434-
* |----------------------|--------------------------------|------------------------|--------|-----------------------------------------|
435-
* |`browserbaseApiKey` |`stagehand.browserbaseApiKey` |`BROWSERBASE_API_KEY` |true |- |
436-
* |`browserbaseProjectId`|`stagehand.browserbaseProjectId`|`BROWSERBASE_PROJECT_ID`|false |- |
437-
* |`modelApiKey` |`stagehand.modelApiKey` |`MODEL_API_KEY` |true |- |
438-
* |`baseUrl` |`stagehand.baseUrl` |`STAGEHAND_API_URL` |true |`"https://api.stagehand.browserbase.com"`|
433+
* |Setter |System property |Environment variable |Required|Default value |
434+
* |-------------------|-----------------------------|---------------------|--------|-----------------------------------------|
435+
* |`browserbaseApiKey`|`stagehand.browserbaseApiKey`|`BROWSERBASE_API_KEY`|true |- |
436+
* |`modelApiKey` |`stagehand.modelApiKey` |`MODEL_API_KEY` |true |- |
437+
* |`baseUrl` |`stagehand.baseUrl` |`STAGEHAND_API_URL` |false |`"https://api.stagehand.browserbase.com"`|
439438
*
440439
* System properties take precedence over environment variables.
441440
*/
@@ -448,9 +447,6 @@ private constructor(
448447
?.let { baseUrl(it) }
449448
(System.getProperty("stagehand.browserbaseApiKey") ?: getEnv("BROWSERBASE_API_KEY"))
450449
?.let { browserbaseApiKey(it) }
451-
(System.getProperty("stagehand.browserbaseProjectId")
452-
?: getEnv("BROWSERBASE_PROJECT_ID"))
453-
?.let { browserbaseProjectId(it) }
454450
(System.getProperty("stagehand.modelApiKey") ?: getEnv("MODEL_API_KEY"))?.let {
455451
modelApiKey(it)
456452
}
@@ -520,11 +516,6 @@ private constructor(
520516
headers.replace("x-bb-api-key", it)
521517
}
522518
}
523-
browserbaseProjectId?.let {
524-
if (!it.isEmpty()) {
525-
headers.replace("x-bb-project-id", it)
526-
}
527-
}
528519
modelApiKey.let {
529520
if (!it.isEmpty()) {
530521
headers.replace("x-model-api-key", it)

stagehand-java-core/src/test/kotlin/com/browserbase/api/core/ClientOptionsTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ internal class ClientOptionsTest {
4747
.containsExactly("another My Browserbase API Key")
4848
}
4949

50+
@Test
51+
fun browserbaseProjectId_isNoOp() {
52+
val clientOptions =
53+
ClientOptions.builder()
54+
.httpClient(httpClient)
55+
.browserbaseApiKey("My Browserbase API Key")
56+
.browserbaseProjectId("My Browserbase Project ID")
57+
.modelApiKey("My Model API Key")
58+
.build()
59+
60+
assertThat(clientOptions.headers.values("x-bb-project-id")).isEmpty()
61+
}
62+
5063
@Test
5164
fun fromEnv_prefersStagehandApiUrl() {
5265
val env =

stagehand-java-example/src/main/java/com/stagehand/api/example/Env.java

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

88
final class Env {
99
private static final String[] REQUIRED_KEYS = {
10-
"STAGEHAND_API_URL", "MODEL_API_KEY", "BROWSERBASE_API_KEY", "BROWSERBASE_PROJECT_ID",
10+
"MODEL_API_KEY", "BROWSERBASE_API_KEY",
1111
};
1212

1313
private Env() {}
@@ -34,15 +34,17 @@ static void load() {
3434
case "BROWSERBASE_API_KEY":
3535
System.setProperty("stagehand.browserbaseApiKey", value);
3636
break;
37-
case "BROWSERBASE_PROJECT_ID":
38-
System.setProperty("stagehand.browserbaseProjectId", value);
39-
break;
4037
case "MODEL_API_KEY":
4138
System.setProperty("stagehand.modelApiKey", value);
4239
break;
4340
case "STAGEHAND_API_URL":
4441
System.setProperty("stagehand.baseUrl", value);
4542
break;
43+
case "STAGEHAND_BASE_URL":
44+
if (System.getProperty("stagehand.baseUrl") == null) {
45+
System.setProperty("stagehand.baseUrl", value);
46+
}
47+
break;
4648
default:
4749
break;
4850
}
@@ -67,8 +69,6 @@ private static String mapKey(String key) {
6769
switch (key) {
6870
case "BROWSERBASE_API_KEY":
6971
return "stagehand.browserbaseApiKey";
70-
case "BROWSERBASE_PROJECT_ID":
71-
return "stagehand.browserbaseProjectId";
7272
case "MODEL_API_KEY":
7373
return "stagehand.modelApiKey";
7474
case "STAGEHAND_API_URL":

stagehand-java-example/src/main/java/com/stagehand/api/example/LocalServerMultiregionBrowserExample.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
*
3434
* Required environment variables:
3535
* - BROWSERBASE_API_KEY: Your Browserbase API key
36-
* - BROWSERBASE_PROJECT_ID: Your Browserbase project ID
3736
* - MODEL_API_KEY: Your OpenAI API key
38-
* - STAGEHAND_API_URL: Local Stagehand server base URL
37+
* Optional: STAGEHAND_API_URL or STAGEHAND_BASE_URL for a local Stagehand server base URL
3938
*/
4039
public class LocalServerMultiregionBrowserExample {
4140
public static void main(String[] args) {
@@ -49,7 +48,6 @@ public static void main(String[] args) {
4948
.type(SessionStartParams.Browser.Type.BROWSERBASE)
5049
.build())
5150
.browserbaseSessionCreateParams(SessionStartParams.BrowserbaseSessionCreateParams.builder()
52-
.projectId(System.getProperty("stagehand.browserbaseProjectId"))
5351
.region(SessionStartParams.BrowserbaseSessionCreateParams.Region.EU_CENTRAL_1)
5452
.build())
5553
.build());

stagehand-java-example/src/main/java/com/stagehand/api/example/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
*
2525
* Required environment variables:
2626
* - BROWSERBASE_API_KEY: Your Browserbase API key
27-
* - BROWSERBASE_PROJECT_ID: Your Browserbase project ID
2827
* - MODEL_API_KEY: Your OpenAI API key
2928
*/
3029
public class Main {
3130
public static void main(String[] args) {
3231
Env.load();
3332
// Create client using environment variables
34-
// BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, MODEL_API_KEY
33+
// BROWSERBASE_API_KEY and MODEL_API_KEY
3534
StagehandClient client = StagehandOkHttpClient.builder().fromEnv().build();
3635

3736
// Start a new browser session

stagehand-java-example/src/main/java/com/stagehand/api/example/RemoteBrowserPlaywrightExample.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
*
3434
* Required environment variables:
3535
* - BROWSERBASE_API_KEY: Your Browserbase API key
36-
* - BROWSERBASE_PROJECT_ID: Your Browserbase project ID
3736
* - MODEL_API_KEY: Your OpenAI API key
3837
*/
3938
public class RemoteBrowserPlaywrightExample {
4039
public static void main(String[] args) {
4140
Env.load();
4241
// Create client using environment variables
43-
// BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, MODEL_API_KEY
42+
// BROWSERBASE_API_KEY and MODEL_API_KEY
4443
StagehandClient client = StagehandOkHttpClient.builder().fromEnv().build();
4544

4645
// Start a new remote Browserbase session (Playwright)
@@ -50,9 +49,6 @@ public static void main(String[] args) {
5049
.browser(SessionStartParams.Browser.builder()
5150
.type(SessionStartParams.Browser.Type.BROWSERBASE)
5251
.build())
53-
.browserbaseSessionCreateParams(SessionStartParams.BrowserbaseSessionCreateParams.builder()
54-
.projectId(System.getProperty("stagehand.browserbaseProjectId"))
55-
.build())
5652
.build());
5753

5854
String sessionId = startResponse.data().sessionId();

0 commit comments

Comments
 (0)