> ## Documentation Index
> Fetch the complete documentation index at: https://hyperbrowser.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Authenticate REST, SDK, and CLI requests with the `x-api-key` header using the `HYPERBROWSER_API_KEY` environment variable (create keys at https://app.hyperbrowser.ai).
> Always stop browser sessions (`sessions.stop(id)` / `PUT /api/session/{id}/stop`) and sandboxes (`sandboxes.stop(id)` / `PUT /api/sandbox/{id}/stop`) in `try`/`finally` blocks to avoid idle billing.
> Choose the right surface: use Web API (`/api/web/fetch`, `batch-fetch`, `crawl`, `search`) for stateless reading and extraction (prefer it over legacy `/api/scrape`); Browser Sessions (`/api/session`) for interactive, authenticated, or Playwright/Puppeteer workflows; Cloud Agents (`/api/task/*`) for autonomous browser tasks; and Sandboxes (`/api/sandbox`) for isolated Linux or macOS code execution.
> Use `@hyperbrowser/sdk` for Node.js/TypeScript, `hyperbrowser` 1.0+ typed-dict request params for Python (avoid legacy Pydantic request classes), the unified `hx` CLI for terminal workflows, and hosted OAuth MCP at `https://mcp.hyperbrowser.ai/mcp/web` (web tools; use `https://mcp.hyperbrowser.ai/mcp` only when browser, sandbox, admin, and usage tools are needed).

# Batch Web Extraction with Web API v2

> Run interactive pre-capture actions on single pages and extract structured JSON across URL batches without managing browser lifecycles

When you need clean Markdown or typed JSON from public web pages without managing Playwright connections, use [Web API v2](https://hyperbrowser.ai/docs/web/overview.md). This recipe combines:

1. **`web.fetch` with `actions`** to expand dynamic tabs or dismiss gates before extraction.
2. **`web.batchFetch.startAndWait`** *(Scale plans and above)* to extract structured JSON across many URLs in parallel.

**Required API key scopes:** `web.fetch.run`, `web.batch-fetch.run`, `web.batch-fetch.read`.

## Prerequisites

* `HYPERBROWSER_API_KEY` exported in your shell.
* `@hyperbrowser/sdk` (TypeScript) or `hyperbrowser` (Python) installed.

***

## Single-Page Fetch with Pre-Capture Actions

```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { Hyperbrowser } from "@hyperbrowser/sdk";

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

const single = await client.web.fetch({
  url: "https://example.com/pricing",
  stealth: "auto",
  navigation: { waitUntil: "networkidle", timeoutMs: 20000 },
  actions: {
    mode: "bestEffort",
    timeoutMs: 10000,
    steps: [
      { type: "click", selector: 'button[data-billing="annual"]' },
      { type: "wait", until: "duration", durationMs: 500 },
    ],
  },
  outputs: {
    formats: [
      "markdown",
      {
        type: "json",
        prompt: "Extract plan names and annual monthly prices.",
        schema: {
          type: "object",
          properties: {
            plans: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  name: { type: "string" },
                  priceUsd: { type: "number" },
                },
                required: ["name", "priceUsd"],
              },
            },
          },
          required: ["plans"],
        },
      },
    ],
  },
});

console.log("Action replay:", single.data?.actionReplay);
console.log("Extracted JSON:", single.data?.json);
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os
from hyperbrowser import Hyperbrowser

client = Hyperbrowser(api_key=os.environ["HYPERBROWSER_API_KEY"])

single = client.web.fetch({
    "url": "https://example.com/pricing",
    "stealth": "auto",
    "navigation": {"wait_until": "networkidle", "timeout_ms": 20000},
    "actions": {
        "mode": "bestEffort",
        "timeout_ms": 10000,
        "steps": [
            {"type": "click", "selector": 'button[data-billing="annual"]'},
            {"type": "wait", "until": "duration", "duration_ms": 500},
        ],
    },
    "outputs": {
        "formats": [
            "markdown",
            {
                "type": "json",
                "prompt": "Extract plan names and annual monthly prices.",
                "schema": {
                    "type": "object",
                    "properties": {
                        "plans": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "name": {"type": "string"},
                                    "priceUsd": {"type": "number"},
                                },
                                "required": ["name", "priceUsd"],
                            },
                        }
                    },
                    "required": ["plans"],
                },
            },
        ]
    },
})

print("Action replay:", single.data.action_replay)
print("Extracted JSON:", single.data.json_)
```

***

## Parallel Batch Extraction (`web.batchFetch`)

```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const urls = [
  "https://example.com/docs/a",
  "https://example.com/docs/b",
  "https://example.com/docs/c",
];

const batch = await client.web.batchFetch.startAndWait({
  urls,
  stealth: "auto",
  outputs: {
    formats: ["markdown", "links"],
    sanitize: "basic",
  },
  cache: { maxAgeSeconds: 3600 },
});

for (const page of batch.data ?? []) {
  console.log(page.url, page.status, page.markdown?.length ?? 0);
}
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
urls = [
    "https://example.com/docs/a",
    "https://example.com/docs/b",
    "https://example.com/docs/c",
]

batch = client.web.batch_fetch.start_and_wait({
    "urls": urls,
    "stealth": "auto",
    "outputs": {
        "formats": ["markdown", "links"],
        "sanitize": "basic",
    },
    "cache": {"max_age_seconds": 3600},
})

for page in batch.data or []:
    print(page.url, page.status, len(page.markdown or ""))
```

## Expected output

* Single-page fetch prints the `actionReplay` status for each click/wait step along with a schema-validated `plans` JSON object.
* Batch fetch logs each URL's status (`completed`) and extracted Markdown character count once the parallel job finishes.

## Next Steps

* [Web Fetch](https://hyperbrowser.ai/docs/web/fetch.md) — actions, wait conditions, screenshots, and JSON Schema extraction.
* [Batch Fetch](https://hyperbrowser.ai/docs/web/batch-fetch.md) — pagination, cache tuning, and stealth tiers.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.