Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@ export class StagehandAPI {
verbose,
debugDom,
systemPrompt,
selfHeal,
waitForCaptchaSolves,
actionTimeoutMs,
browserbaseSessionCreateParams,
}: StartSessionParams): Promise<StartSessionResult> {
const whitelistResponse = await this.request("/healthcheck");

if (whitelistResponse.status === 401) {
throw new Error(
"Unauthorized. Ensure you provided a valid API key and that it is whitelisted.",
);
} else if (whitelistResponse.status !== 200) {
throw new Error(`Unknown error: ${whitelistResponse.status}`);
}

const sessionResponse = await this.request("/sessions/start", {
method: "POST",
body: JSON.stringify({
Expand All @@ -57,6 +50,9 @@ export class StagehandAPI {
verbose,
debugDom,
systemPrompt,
selfHeal,
waitForCaptchaSolves,
actionTimeoutMs,
browserbaseSessionCreateParams,
}),
headers: {
Expand Down
12 changes: 11 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,15 @@ export class Stagehand {
throw new Error(
"STAGEHAND_API_URL is required when using the API. Please set it in your environment variables.",
);
} else if (
this.usingAPI &&
this.llmClient.type !== "openai" &&
this.llmClient.type !== "anthropic"
) {
throw new Error(
"API mode requires an OpenAI or Anthropic LLM. Please provide a compatible model.",
);
}

this.waitForCaptchaSolves = waitForCaptchaSolves;

this.selfHeal = selfHeal;
Expand Down Expand Up @@ -613,6 +620,9 @@ export class Stagehand {
verbose: this.verbose,
debugDom: this.debugDom,
systemPrompt: this.userProvidedInstructions,
selfHeal: this.selfHeal,
waitForCaptchaSolves: this.waitForCaptchaSolves,
actionTimeoutMs: this.actTimeoutMs,
browserbaseSessionCreateParams: this.browserbaseSessionCreateParams,
});
this.browserbaseSessionID = sessionId;
Expand Down
3 changes: 3 additions & 0 deletions types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface StartSessionParams {
debugDom: boolean;
systemPrompt?: string;
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
selfHeal?: boolean;
waitForCaptchaSolves?: boolean;
actionTimeoutMs?: number;
}

export interface StartSessionResult {
Expand Down