For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Logo
Portal
GuidesRecipesAPI ReferenceChangelog
GuidesRecipesAPI ReferenceChangelog
  • Airtop API
      • Wait for Session Ready
      • Get Window Info for Puppeteer Page
      • Get Window Info for Playwright Page
      • Get Window Info for Selenium Driver
      • Batch Operate
      • Process Screenshots
Portal
Airtop APIExtras

Batch Operate

1import { Airtop, BatchOperationUrl, BatchOperationInput, BatchOperationResponse } from '@airtop/sdk';
2
3const client = new Airtop({ apiKey: 'your-api-key' });
4
5// Define URLs to process
6const urls: BatchOperationUrl[] = [
7 {
8 url: 'https://example.com/page1',
9 context: { category: 'news' },
10 },
11 {
12 url: 'https://example.com/page2',
13 context: { category: 'blog' },
14 },
15];
16
17// Define operation function
18const operation = async (input: BatchOperationInput): Promise<BatchOperationResponse<string>> => {
19 const { windowId, sessionId, liveViewUrl, operationUrl } = input;
20
21 // Example: Run a custom query on each page
22 const result = await client.windows.pageQuery({
23 sessionId,
24 windowId,
25 prompt: `What is the main idea of this ${operationUrl.context?.category} page?`,
26 });
27
28 return {
29 data: result.data.modelResponse,
30 shouldHaltBatch: false,
31 additionalUrls: [],
32 };
33};
34
35// Execute batch operation
36const results = await client.batchOperate({
37 urls,
38 operation,
39 config: {
40 maxConcurrentSessions: 30,
41 maxWindowsPerSession: 1,
42 onError: async (error) => {
43 console.error(`Error processing URLs:`, error.operationUrls);
44 console.error(`Error details:`, error.error);
45 },
46 },
47});
Was this page helpful?
Previous

Process Screenshots

Next
Built with

Execute batch operations in parallel while automatically managing browser sessions and windows.

Parameters

urls
BatchOperationUrl[]Required

An array of URLs to process in parallel.

+ Show 2 properties
url
stringRequired

The URL to process.

context
Record<string, unknown>

Additional context data to be passed with the URL.

operation
(input: BatchOperationInput) => Promise<BatchOperationResponse<T>>Required

The operation function to execute for each URL.

+ Show 2 objects
input
BatchOperationInputRequired

The input provided to the operation function.

+ Show 4 properties
sessionId
stringRequired

The ID of the browser session.

windowId
stringRequired

The ID of the browser window.

liveViewUrl
stringRequired

The URL that can be used to view the browser window in real-time.

operationUrl
BatchOperationUrlRequired

The URL being processed, including any context data.

response
BatchOperationResponse<T>Required

The response returned by the operation function.

+ Show 3 properties
data
TRequired

Contains the relevant data returned by the operation, which will ultimately be returned in the results array.

shouldHaltBatch
boolean

If set to true, the batch operator will stop processing remaining URLs.

additionalUrls
BatchOperationUrl[]

If set, additional URLs will be processed as part of the same batch operation.

config
BatchOperateConfig

Configuration options for the batch operation.

+ Show 4 properties
maxConcurrentSessions
number

Maximum number of concurrent browser sessions. Defaults to 30.

maxWindowsPerSession
number

Maximum number of windows per session. Defaults to 1 (recommended).

sessionConfig
AirtopSessionConfigV1

Configuration for browser sessions.

onError
(error: BatchOperationError) => Promise<void>

Callback function for handling errors.

+ Show 5 properties
error.error
Error | stringRequired

The error that occurred.

error.operationUrls
BatchOperationUrl[]Required

The URLs that were being processed when the error occurred.

error.sessionId
string

The ID of the session where the error occurred (if available).

error.windowId
string

The ID of the window where the error occurred (if available).

error.liveViewUrl
string

The live view URL of the window where the error occurred (if available).

Returns

results
T[]Required

An array containing the results from each operation, in the order that the operations were executed. Note that the order of the input URLs does not necessarily match the order of the results.