> ## 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).

# Rate Limits, Errors & Pagination

> HTTP error formats, status codes, rate limits, retry strategies, and pagination conventions

Use this guide to handle API errors cleanly, respect rate and concurrency limits, and paginate through multi-page responses.

## Error Response Format

Failed API requests return a non-2xx HTTP status code and a JSON body with a `message` (authentication and scope rejections use `error` instead, sometimes with a structured error code):

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "message": "Job not found"
}
```

Scope and authentication denials use stable error strings:

| Error string | HTTP status | Meaning |
| - | - | - |
| `NOT AUTHENTICATED` | `401` | Missing `x-api-key` or `Authorization` credentials. |
| `Invalid token` | `401` | Expired, malformed, or revoked Bearer JWT. |
| `API_KEY_SCOPE_DENIED` | `403` | The scoped API key lacks the permission required by this endpoint. |
| `MCP_SCOPE_DENIED` | `403` | The OAuth MCP token lacks the scope required by this endpoint. |
| `SESSION_TOKEN_SCOPE_MISMATCH` | `403` | A session or management token was sent to an endpoint outside its scope. |

***

## HTTP Status Codes

| Status | Meaning | Retryable? | Typical Action |
| - | - | - | - |
| `400` | Invalid request parameters or schema validation failure | No | Fix the request payload, URL format, or parameter bounds. |
| `401` | Missing or invalid credentials | No | Verify `HYPERBROWSER_API_KEY` / `x-api-key` or refresh your Bearer token. |
| `402` | Insufficient credits or plan does not include the feature (for example, Batch Fetch requires Scale, Ultra, or Custom) | No | Top up credits or upgrade your plan in the [billing settings](https://app.hyperbrowser.ai/settings?tab=billing). |
| `403` | Forbidden or missing API key scope | No | Grant the required scope on the API key (see [Authentication](https://hyperbrowser.ai/docs/platform/authentication.md#permission-groups)) or check team role. |
| `404` | Session, job, sandbox, profile, or resource not found (or belongs to another team) | No | Verify the resource ID and that you are using the matching team API key. |
| `429` | Rate limit, concurrency limit, or transient capacity exceeded | **Yes** | Honor `Retry-After` if present, otherwise retry with exponential backoff and jitter. |
| `500`, `502`, `503`, `504` | Server or upstream gateway error | **Yes** | Retry with exponential backoff; avoid blind retries on non-idempotent POST calls without deduplication. |

> [!NOTE]
>
> For Web API endpoints (`fetch`, `batch-fetch`, `crawl`), an HTTP `200` with `status: "completed"` means Hyperbrowser loaded the page, not that the target site returned HTTP 200. Always check `data.statusCode` on fetched pages to detect target-side `401`, `403`, `404`, or `5xx` responses.

***

## Rate Limits & Concurrency

Each plan caps concurrent active browser sessions and concurrent batch-fetch jobs; requests over those caps return `429 Too Many Requests`. Plans also cap URLs per batch-fetch job and `maxPages` per crawl; requests over those caps return `400`. During temporary capacity spikes, session or sandbox creation may also return `429`; retry after a few seconds.

Need higher limits? Contact [info@hyperbrowser.ai](mailto:info@hyperbrowser.ai).

***

## Handling Errors & Retries in the SDKs

Both SDKs throw `HyperbrowserError` on non-2xx responses and network failures. Inspect `statusCode` (`status_code` in Python), `retryable`, `code`, and `requestId` (`request_id`) to decide whether to retry.

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

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

async function withRetry<T>(fn: () => Promise<T>, maxAttempts = 4): Promise<T> {
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    try {
      return await fn();
    } catch (err) {
      const isRetryable =
        err instanceof HyperbrowserError &&
        (err.retryable ||
          err.statusCode === 429 ||
          (err.statusCode !== undefined && err.statusCode >= 500));

      if (!isRetryable || attempt === maxAttempts - 1) {
        throw err;
      }

      const backoffMs = Math.min(1000 * 2 ** attempt, 15000);
      const jitterMs = Math.random() * 500;
      await new Promise((resolve) => setTimeout(resolve, backoffMs + jitterMs));
    }
  }
  throw new Error("Unreachable");
}

const result = await withRetry(() =>
  client.web.fetch({ url: "https://example.com" })
);
console.log(result.data?.statusCode);
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os
import random
import time
from typing import Callable, TypeVar
from hyperbrowser import Hyperbrowser
from hyperbrowser.exceptions import HyperbrowserError

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


def with_retry(fn: Callable[[], T], max_attempts: int = 4) -> T:
    for attempt in range(max_attempts):
        try:
            return fn()
        except HyperbrowserError as err:
            is_retryable = err.retryable or (
                err.status_code is not None
                and (err.status_code == 429 or err.status_code >= 500)
            )
            if not is_retryable or attempt == max_attempts - 1:
                raise

            backoff_s = min(1.0 * (2**attempt), 15.0)
            time.sleep(backoff_s + random.uniform(0, 0.5))
    raise RuntimeError("Unreachable")


result = with_retry(lambda: client.web.fetch({"url": "https://example.com"}))
print(result.data.status_code if result.data else None)
```

***

## Pagination Conventions

Hyperbrowser uses two consistent 1-indexed pagination shapes depending on the resource:

### 1. Multi-page job results (`GET /api/web/crawl/:id`, `GET /api/web/batch-fetch/:id`)

| Query parameter | Type | Default | Range | Description |
| - | - | - | - | - |
| `page` | `integer` | `1` | `>= 1` | 1-indexed result batch to retrieve. |
| `batchSize` | `integer` | `20` | `1–100` | Number of page results returned per batch. |

Responses return `totalPages`, `totalPageBatches`, `currentPageBatch`, and `batchSize` alongside `data`.

> [!TIP]
>
> In the Node and Python SDKs, `startAndWait` / `start_and_wait` on `web.crawl` and `web.batchFetch` (`web.batch_fetch`) accept `returnAllPages` / `return_all_pages` (default `true`), which automatically fetches every batch (`batchSize: 100`) and concatenates `data` for you.

### 2. List endpoints (sessions, profiles, sandboxes, jobs)

List endpoints such as `GET /api/sessions`, `GET /api/web/fetch`, `GET /api/web/batch-fetch`, and `GET /api/web/crawl` accept `page` (1-indexed, default `1`) and `limit` (page size; endpoint-specific; Web API job lists default to `10` with a max of `20`).


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