Skip to content

Commit 28ca9fb

Browse files
authored
allow API custom session creation params (#496)
* allow custom session creation params * missing api url handling * changeset
1 parent 6330f3a commit 28ca9fb

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

Diff for: .changeset/shaggy-planets-fetch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": minor
3+
---
4+
5+
Fixed browserbaseSessionCreateParams not being passed in to the API initialization payload.

Diff for: lib/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class StagehandAPI {
3737
verbose,
3838
debugDom,
3939
systemPrompt,
40+
browserbaseSessionCreateParams,
4041
}: StartSessionParams): Promise<StartSessionResult> {
4142
const whitelistResponse = await this.request("/healthcheck");
4243

@@ -56,6 +57,7 @@ export class StagehandAPI {
5657
verbose,
5758
debugDom,
5859
systemPrompt,
60+
browserbaseSessionCreateParams,
5961
}),
6062
headers: {
6163
"x-model-api-key": modelApiKey,

Diff for: lib/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ export class Stagehand {
393393

394394
if (this.usingAPI && env === "LOCAL") {
395395
throw new Error("API mode can only be used with BROWSERBASE environment");
396+
} else if (this.usingAPI && !process.env.STAGEHAND_API_URL) {
397+
throw new Error(
398+
"STAGEHAND_API_URL is required when using the API. Please set it in your environment variables.",
399+
);
396400
}
401+
397402
this.selfHeal = selfHeal;
398403
}
399404

@@ -457,6 +462,7 @@ export class Stagehand {
457462
verbose: this.verbose,
458463
debugDom: this.debugDom,
459464
systemPrompt: this.userProvidedInstructions,
465+
browserbaseSessionCreateParams: this.browserbaseSessionCreateParams,
460466
});
461467
this.browserbaseSessionID = sessionId;
462468
}

Diff for: types/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Browserbase from "@browserbasehq/sdk";
12
import { LogLine } from "./log";
23

34
export interface StagehandAPIConstructorParams {
@@ -19,6 +20,7 @@ export interface StartSessionParams {
1920
verbose: number;
2021
debugDom: boolean;
2122
systemPrompt?: string;
23+
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
2224
}
2325

2426
export interface StartSessionResult {

0 commit comments

Comments
 (0)