StagehandBrowserDriver. The OpenAI SDK runs the model’s tool loop, and Stagehand handles browser interactions such as navigation, screenshots, and form input.
Prerequisites
- An OpenAI API key and access to a model that supports the browser toolset.
- Google Chrome for the local example, or a Browserbase API key for a hosted session.
- Node.js 22.18 or later and pnpm for TypeScript, or Python 3.11 or later and uv for Python.
Install the integration
Clone the OpenAI Toolset repository:- TypeScript
- Python
Install the OpenAI SDK and Stagehand from npm:Import the driver from the
stagehand-openai-sdk npm package.Run a browser task
Export your OpenAI API key:example.ts or example.py with the matching example below. Both launch headless Chrome, ask GPT to read the heading on example.com, and print the final answer.
- TypeScript
- Python
example.ts
typescript directory:createBrowserToolset in TypeScript or create_browser_toolset in Python, then pass the toolset to the Responses tool runner. Keep the same driver throughout the loop so tabs and page state remain available.
The tool runner doesn’t close the browser. Use finally in both languages to close the driver when the task finishes or fails.
Use Browserbase
Export your Browserbase API key:StagehandBrowserDriver.launch call with the matching factory below. Keep the tool loop and cleanup code from the previous example.
- TypeScript
- Python
Domain restrictions
SetallowedDomains and blockedDomains in TypeScript, or allowed_domains and blocked_domains in Python, to restrict HTTP and HTTPS requests and WebSocket handshakes. A domain entry includes its subdomains; blocked entries take precedence.
Troubleshooting
For additional configuration and examples, see the OpenAI Toolset repository.

