Prepare the environment

  • Node.js (v20.19.4 or higher)
  • npm (v10.9.0 or higher)
First, we recommend using Node.js to setup the Node.js environment.
npm init -y
Install the dependencies:
npm install browsernode
Then install playwright:
npx playwright install

Create an agent

Then you can use the agent as follows:
import { Agent } from "browsernode";
import { ChatOpenAI } from "browsernode/llm";

const llm = new ChatOpenAI({
	model: "gpt-4.1",
	temperature: 0.0,
	apiKey: process.env.OPENAI_API_KEY,
});

const task = "Compare the price of gpt-4o and DeepSeek-V3";
const agent = new Agent(task, llm);
const history = await agent.run();
console.log(history.usage);

Set up your LLM API keys

Add your API keys for the provider you want to use to your .env file.
mv .env.example .env
ChatOpenAI and other Langchain chat models require API keys. You should store these in your .env file. For example, for OpenAI and Anthropic, you can set the API keys in your .env file, such as:
.env
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
For other LLM models you can refer to the Supported Models page to find how to set them up with their specific API keys.

Run the example

npx tsx examples/simple.ts