Skip to main content
HyperAgent is our open-source tool that supercharges Playwright with AI. To view the full details on HyperAgent, check out the HyperAgent Github Repo. Here, we will just go over using one of the features of HyperAgent which is being able to have it automatically execute tasks on your behalf on the web with just a simple call. By default, HyperAgent tasks are handled in an asynchronous manner of first starting the task and then checking its status until it is completed. However, if you don’t want to handle the monitoring yourself, our SDKs provide a simple function that handles the whole flow and returns the data once the task is completed. You can view your HyperAgent tasks in the dashboard.

How It Works

You can use HyperAgent in two ways:
  1. Start and Wait: SDKs provide a startAndWait() method that blocks until the task completes and returns the result
  2. Async Pattern: Start a task, get a job ID, then poll for status and results—useful for long-running tasks or when you want more control

Installation

npm install @hyperbrowser/sdk dotenv

Quick Start

The simplest way to run a HyperAgent task is with the startAndWait() method, which handles everything for you:
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

async function main() {
  const result = await client.agents.hyperAgent.startAndWait({
    task: "Go to Hacker News and tell me the title of the top post",
    llm: "gpt-4o",
    maxSteps: 20,
  });

  console.log(`Output:\n${result.data?.finalResult}`);
}

main().catch((err) => {
  console.error(`Error: ${err.message}`);
});

Async Pattern

When you need more control, use the async pattern to start a task and poll for results:
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

async function main() {
  try {
    // Start the task
    const task = await client.agents.hyperAgent.start({
      task: "What is the title of the first post on Hacker News today?",
      llm: "gpt-4o",
      maxSteps: 20,
    });

    console.log(`Task started: ${task.jobId}`);
    console.log(`Watch live: ${task.liveUrl}`);

    // Poll for completion
    let result;
    while (true) {
      result = await client.agents.hyperAgent.getStatus(task.jobId);
      console.log(`Status: ${result.status}`);

      if (result.status === "completed" || result.status === "failed") {
        break;
      }

      await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5s
    }

    const fullResult = await client.agents.hyperAgent.get(task.jobId);

    if (fullResult.status === "completed") {
      console.log("Result:", fullResult.data?.finalResult);
      console.log("Steps taken:", fullResult.data?.steps?.length);
    } else {
      console.error("Task failed:", fullResult.error);
    }
  } catch (err) {
    console.error(`Error: ${err.message}`);
  }
}

main();

Stop a Running Task

Stop a task before it completes:
await client.agents.hyperAgent.stop("job-id");

Parameters

task
string
required
Natural language description of what you want HyperAgent to accomplish. Be specific for best results.
llm
string
default:"gpt-4o"
LLM model to use. Available options:
  • "gpt-4o" - GPT-4o (recommended)
  • "gpt-4o-mini" - GPT-4o Mini
  • "gpt-4.1" - GPT-4.1
  • "gpt-4.1-mini" - GPT-4.1 Mini
maxSteps
number
default:"20"
Maximum number of actions HyperAgent can take (clicks, typing, navigation, etc.). Increase for complex tasks.
sessionId
string
ID of an existing browser session to reuse. Useful for multi-step workflows that need to maintain the same browser session.
keepBrowserOpen
boolean
default:"false"
Keep the browser session alive after task completion.
sessionOptions
object
Session configuration (proxy, stealth, captcha solving, etc.). Only applies when creating a new session. If you provide an existing sessionId, these options are ignored.
useCustomApiKeys
boolean
default:"false"
Use your own LLM API keys instead of consuming Hyperbrowser credits for LLM calls. You will only be charged for browser usage.
apiKeys
object
API key for openai. Required when useCustomApiKeys is true.
{
  openai: "..."
}
The agent may not complete the task within the specified maxSteps. If that happens, try increasing the maxSteps parameter.Additionally, the browser session used by the AI Agent will time out based on your team’s default Session Timeout settings or the session’s timeoutMinutes parameter if provided. You can adjust the default Session Timeout in the Settings page.

Reuse Browser Sessions

You can pass in an existing sessionId to the HyperAgent task so that it can execute the task on an existing session. Also, if you want to keep the session open after executing the task, you can supply the keepBrowserOpen parameter.
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

const main = async () => {
  const session = await client.sessions.create();

  try {
    const result = await client.agents.hyperAgent.startAndWait({
      task: "What is the title of the first post on Hacker News today?",
      sessionId: session.id,
      keepBrowserOpen: true,
    });

    console.log(`Output:\n${result.data?.finalResult}`);

    const result2 = await client.agents.hyperAgent.startAndWait({
      task: "Tell me how many upvotes the first post has.",
      sessionId: session.id,
    });

    console.log(`\nOutput:\n${result2.data?.finalResult}`);
  } catch (err) {
    console.error(`Error: ${err}`);
  } finally {
    await client.sessions.stop(session.id);
  }
};

main().catch((err) => {
  console.error(`Error: ${err.message}`);
});
Always set keepBrowserOpen: true on tasks that you want to reuse the session from. Otherwise, the session will be automatically closed when the task completes.

Using Your Own API Keys

Bring your own LLM API keys to avoid consuming Hyperbrowser credits for LLM calls. You’ll still be charged for browser session usage, but save on token costs.
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

const main = async () => {
  const result = await client.agents.hyperAgent.startAndWait({
    task: "What is the title of the first post on Hacker News today?",
    llm: "gpt-4o",
    useCustomApiKeys: true,
    apiKeys: {
      openai: "<OPENAI_API_KEY>",
    },
  });

  console.log(`Output:\n\n${result.data?.finalResult}`);
};

main().catch((err) => {
  console.error(`Error: ${err.message}`);
});

Session Configuration

Customize the browser session used by HyperAgent with session options.
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

const main = async () => {
  const result = await client.agents.hyperAgent.startAndWait({
    task: "What is the title of the first post on Hacker News today?",
    llm: "gpt-4o",
    sessionOptions: {
      acceptCookies: true,
    }
  });

  console.log(`Output:\n\n${result.data?.finalResult}`);
};

main().catch((err) => {
  console.error(`Error: ${err.message}`);
});
sessionOptions only applies when creating a new session. If you provide a sessionId, these options are ignored.
Proxies and CAPTCHA solving add latency to page navigation. Only enable them when necessary for your use case.

Best Practices

Be explicit about what you want HyperAgent to do. Instead of “check the website”, say “go to example.com, find the pricing page, and extract the cost of the Enterprise plan”.
Simple tasks need 10-20 steps. Complex multi-page workflows might need 50+ steps. Monitor failed tasks and adjust accordingly.
It is usually better to split up complex tasks into smaller, more manageable ones and execute them as separate agent calls on the same session.