Skip to content

Usage

Minimal Node.js example

Creates a cloud browser session, opens a URL, runs an AI page query, prints the result, and terminates the session.

ts
import { AirtopClient } from '@airtop/sdk';

const client = new AirtopClient({ apiKey: process.env.AIRTOP_API_KEY });

const session = await client.sessions.create();
const window = await client.windows.create(session.data.id, {
  url: 'https://www.airtop.ai',
});

const contentSummary = await client.windows.pageQuery(
  session.data.id,
  window.data.windowId,
  {
    prompt:
      'Summarize the contents of the page in 1 short paragraph up to 170 characters.',
  }
);

console.log(contentSummary.data.modelResponse);

await client.sessions.terminate(session.data.id);

Minimal Python example

python
import os
from airtop import Airtop

client = Airtop(api_key=os.environ["AIRTOP_API_KEY"])

session = client.sessions.create()
window = client.windows.create(session.data.id, url="https://www.airtop.ai")

prompt = "Summarize the contents of the page in 1 short paragraph up to 170 characters."
content_summary = client.windows.page_query(
    session.data.id, window.data.window_id, prompt=prompt
)
print(content_summary.data.model_response)

client.sessions.terminate(session.data.id)

Core SDK primitives

MethodWhat it does
sessions.create()Spins up a new isolated cloud browser session
windows.create(sessionId, { url })Opens a browser tab at the given URL
windows.pageQuery(sessionId, windowId, { prompt })Runs an AI prompt against the current page DOM
windows.paginatedExtraction(sessionId, windowId, { prompt })Extracts structured data across paginated results
windows.click(sessionId, windowId, { elementDescription })AI-driven element click by natural language description
sessions.terminate(sessionId)Closes the session and stops credit usage

Notes

  • Always call sessions.terminate() when done. Unclosed sessions continue consuming credits until they hit the platform timeout.
  • The pageQuery prompt is plain English. Be specific: "Extract the first 10 product names and prices as JSON" works better than "get the products."
  • For sites behind login, load auth cookies or run login steps before extraction. See the authentication recipe at https://docs.airtop.ai/recipes/recipes/extract-data-behind-authentication.