-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed as duplicate of#1378
Closed as duplicate of#1378
Copy link
Description
Description
When using AISdkClient with Amazon Bedrock models in BROWSERBASE environment, Stagehand throws a StagehandAPIError: modelApiKey is required error during initialization.
Error
StagehandAPIError: modelApiKey is required
at <anonymous> (/usr/src/app/node_modules/@browserbasehq/stagehand/dist/index.js:38340:19)
Root Cause
When passing an llmClient to Stagehand, the code at lines 38695-38699 sets modelClientOptions to baseClientOptions without adding an apiKey:
if (opts.llmClient) {
this.llmClient = opts.llmClient;
this.modelClientOptions = baseClientOptions; // No apiKey added
}However, later at line 39129, when env: "BROWSERBASE" and disableAPI: false, the code tries to access this.modelClientOptions.apiKey:
const { sessionId: sessionId2, available } = yield this.apiClient.init({
modelName: this.modelName,
modelApiKey: this.modelClientOptions.apiKey, // undefined for Bedrock
// ...
});Bedrock models use AWS credential chains (via credentialProvider) rather than a simple apiKey property, so this.modelClientOptions.apiKey is undefined.
Reproduction
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { AISdkClient, Stagehand } from '@browserbasehq/stagehand';
const bedrock = createAmazonBedrock({
region: 'eu-north-1',
credentialProvider: fromNodeProviderChain(),
});
const bedrockClient = new AISdkClient({
model: bedrock('eu.amazon.nova-pro-v1:0'),
});
const stagehand = new Stagehand({
env: 'BROWSERBASE',
llmClient: bedrockClient,
});
await stagehand.init(); // Error: modelApiKey is requiredWorkaround
Setting disableAPI: true bypasses the API client that requires modelApiKey:
const stagehand = new Stagehand({
env: 'BROWSERBASE',
llmClient: bedrockClient,
disableAPI: true, // Bypasses the modelApiKey requirement
});Suggested Fix
When llmClient is provided, Stagehand should either:
- Skip
modelApiKeyvalidation for custom LLM clients (similar to PR fix: allow custom LLM clients to skip modelApiKey validation in BrowserBase #966) - Extract credentials from the AI SDK model if available
- Document that
disableAPI: trueis required for Bedrock/custom credential providers
Environment
- Stagehand version: 3.0.1
- Node version: 22.x
- Using @ai-sdk/amazon-bedrock with Bedrock models
- BROWSERBASE environment
Metadata
Metadata
Assignees
Labels
No labels