Skip to main content

Get an API key

  • Copy your Agent API key from the dashboard.
  • Send it in the header: Authorization: Bearer <AGENT_API_KEY> or pass it as an argument to the SDK.

(Optional) Install the SDK

If your project uses Node.js or TypeScript, you can install the Browsercash SDK for easier access to the Agent API.
npm install @browsercash/sdk

1) Create a task

All agents are available via the Agent API. Here is an example using the gemini agent to fetch text from a webpage. Agents are consumed via tasks, which you create, fetch, and list.
import BrowsercashSDK from '@browsercash/sdk';

const client = new BrowsercashSDK({
  apiKey: process.env.BROWSER_API_KEY!,
});

const agent = await client.agent.task.create({
  agent: 'gemini',
  prompt: 'What text does the homepage of example.com say?',
  mode: 'text',
  stepLimit: 10,
});

console.log(agent.taskId);
This will create a new agent task. The response is a taskId you can use to track progress and fetch results.
{ "taskId": "02a94d68-b9e9-49bd-a3e4-54b8426e3550" }

2) Get a task

Now that you have a taskId, you can fetch the task to track status and retrieve the output of the agent. An agent’s state can either be active, completed, or failed. You can see the full output shape here.
import BrowsercashSDK from '@browsercash/sdk';

const client = new BrowsercashSDK({
  apiKey: process.env.BROWSER_API_KEY!,
});

const agent = await client.agent.task.get({ taskId: process.env.TASK_ID! });

console.log(agent);

3) List tasks

After you’ve ran a few tasks, you might want to list them. Using the list endpoint, you can paginate through your tasks. This will return a paginated list of tasks you have created. It can have a slightly different shape than fetching a single task. You can see the full output shape here.
import BrowsercashSDK from '@browsercash/sdk';

const client = new BrowsercashSDK({
  apiKey: process.env.BROWSER_API_KEY!,
});

const tasks = await client.agent.task.list({ pageSize: 20, page: 1 });

console.log(tasks);

Notes:

  • Agent runs cannot be deleted or stopped once started at this time.
  • Session outputs may be deleted at any time after completion.