Configuration
How to configure Stagehand
Stagehand constructor
This constructor is used to create an instance of Stagehand.
Arguments: ConstructorParams
Defaults to 'BROWSERBASE'
Your Browserbase API key. Defaults to BROWSERBASE_API_KEY
environment variable
Your Browserbase project ID. Defaults to BROWSERBASE_PROJECT_ID
environment variable
Configuration options for creating new Browserbase sessions
ID of an existing Browserbase session to resume
Specifying the default language model to use
Configuration options for the language model client (i.e. apiKey
)
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
Determines if the browser runs in headless mode. Defaults to false
. When the env is set to BROWSERBASE
, this will be ignored
Specifies the timeout in milliseconds for waiting for the DOM to settle. Defaults to 30_000
(30 seconds)
message
is a LogLine
object. Handles log messages. Useful for custom logging implementations. For more information, see the Logging page
Enables several levels of logging during automation: 0
: limited to no logging, 1
: SDK-level logging, 2
: LLM-client level logging (most granular)
Draws bounding boxes around elements presented to the LLM during automation
A custom system prompt to use for the LLM in addition to the default system prompt for act, extract, and observe methods.
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 either with init()
or initFromPage()
.
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.