Skip to main content

Stagehand constructor

This constructor is used to create an instance of Stagehand.

Arguments: ConstructorParams

'LOCAL' | 'BROWSERBASE'
Defaults to 'BROWSERBASE'
string
Your Browserbase API key. Defaults to BROWSERBASE_API_KEY environment variable
string
Your Browserbase project ID. Defaults to BROWSERBASE_PROJECT_ID environment variable
boolean
Enables access to experimental features.
boolean
Whether to use the stagehand API. Defaults to true when env: "BROWSERBASE".
object
Configuration options for creating new Browserbase sessions. More information on browserbaseSessionCreateParams can be found here.
string
ID of an existing Browserbase session to resume
string
Specifying the default language model to use. Format supported is {provider}/{modelName}. For a list of supported providers, see Available Providers.
object
Configuration options for the language model client (i.e. apiKey)
boolean
Enables caching of LLM responses. When set to true, the LLM requests will be cached on disk and reused for identical requests. Defaults to false
integer
Specifies the timeout in milliseconds for waiting for the DOM to settle. Defaults to 30_000 (30 seconds)
(message: LogLine) => void
message is a LogLine object. Handles log messages. Useful for custom logging implementations. For more information, see the Logging page
boolean
Whether Pino should be disabled for logging. This is helpful for Next.js or test environments. Pino will automatically be disabled if a custom logger is defined.
integer
Enables several levels of logging during automation:
  • 0: ERROR (limited to no logging)
  • 1: INFO (SDK-level logging)
  • 2: DEBUG (Detailed logging and tracing)
LLMClient
A custom LLM client implementation that conforms to the LLMClient abstract class
string
A custom system prompt to use for the LLM in addition to the default system prompt for act, extract, and observe methods.
boolean
Enables self-healing mode. When set to true, Stagehand will attempt to recover from errors (eg. outdated cached element not resolving) by retrying the last action. Defaults to true. Set to false to disable LLM inference on cache errors.
LocalBrowserLaunchOptions
Provides comprehensive options for local browser instances.

Returns: Stagehand object

The constructor returns an instance of the Stagehand class configured with the specified options. However, to use Stagehand, you must still initialize it with init().

stagehand.init()

init() asynchronously initializes the Stagehand instance. It should be called before any other methods.

stagehand.close()

close() is a cleanup method to remove the temporary files created by Stagehand. It’s recommended that you call this explicitly when you’re done with your automation.