# Web Scraping & Search (totalum-sdk/web)

> Read the web from your app: one page as Markdown or HTML (scrape), a web search (search), every URL of a site (map), a whole site in the background (crawl) and screenshots. Use it to read pages; when you need to click, type or log in, use the cloud browser instead. Every call is billed in credits and returns its price in usage.credits.

`import … from 'totalum-sdk/web'`, or the same namespace on `totalum` from `'totalum-sdk'`. Install, configuration and errors: [Totalum SDK](https://www.totalum.app/docs/sdk).

Read the web from your app: one page as Markdown or HTML (`scrape`), a web search (`search`), every URL of a site
(`map`), a whole site in the background (`crawl`) and screenshots. Use it to read pages; when you need to click,
type or log in, use the cloud browser instead. Every call is billed in credits and returns its price in
`usage.credits`.

```ts
const page = await totalum.web.scrape('https://example.com', { formats: ['markdown'] });
```

| Method or type | What it does |
|---|---|
| [`totalumWeb`](#totalumweb) | Creates the `web` namespace (the same object as `totalum.web`, scope `web`): scrape, search, map, crawl and screenshots, billed in credits — every result carries `usage.credits`. |
| [`web.scrape`](#webscrape) | Reads one web page and returns its content as clean Markdown (the default), HTML, its links, a screenshot, a summary or JSON extracted with your schema. |
| [`web.search`](#websearch) | Searches the web and returns the results (title, URL, snippet); with `scrapeOptions`, each result's page content too. |
| [`web.map`](#webmap) | Lists the URLs of a site (from its sitemap and links) without reading the pages — to choose what to scrape, or to build a site index. |
| [`web.crawl`](#webcrawl) | Starts reading a whole site (or part of it) in the background and returns a job id at once. |
| [`web.crawlStatus`](#webcrawlstatus) | Reads a crawl job: its status, how many pages are done and their content. |
| [`web.cancelCrawl`](#webcancelcrawl) | Stops a running crawl. |
| [`web.screenshot`](#webscreenshot) | Takes a screenshot of a web page (`url`) or of HTML you pass (`html`) and stores it as a public project file: link previews, social images, visual checks. |
| [`JobCreated`](#jobcreated) | A background job that was started. |
| [`ScreenshotInput`](#screenshotinput) | The options of `web.screenshot()`. |
| [`ScreenshotOutput`](#screenshotoutput) | A screenshot stored as a public project file. |
| [`WebJob`](#webjob) | A crawl job, from `web.crawlStatus()` and `web.cancelCrawl()`. |
| [`WebScrapeOutput`](#webscrapeoutput) | One page read by `web.scrape()`. |
| [`WebSearchOutput`](#websearchoutput) | The results of `web.search()`, by source. |

## `totalumWeb`

```ts
totalumWeb(options?: TotalumClientOptions): TotalumWeb
```

Creates the `web` namespace (the same object as `totalum.web`, scope `web`): scrape, search, map, crawl and
screenshots, billed in credits — every result carries `usage.credits`.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `options` | [`TotalumClientOptions`](https://www.totalum.app/docs/sdk/types#totalumclientoptions) | no | The project key, API URL and environment; each falls back to its environment variable. |
| `options.key` | `string` | no | Project key `tlm_pk_…`; default `TOTALUM_PROJECT_KEY`. Server-side only. |
| `options.apiUrl` | `string` | no | The Totalum API's URL: default `TOTALUM_SDK_API_URL`, else `https://sdk-api.totalum.app`. |
| `options.env` | `'dev' \| 'live'` | no | Sent as `x-totalum-env` on every call (the database it targets, and dev vs live usage); default `TOTALUM_ENV`, else `live`. |

**Returns** [`TotalumWeb`](#totalumweb) — The `web` namespace: the methods below.

**Example**

```ts
import { totalumWeb } from 'totalum-sdk/web';

const web = totalumWeb();
const page = await web.scrape('https://example.com');
```

The namespace's type is exported as `TotalumWeb` (`import type { TotalumWeb } from 'totalum-sdk/web'`).

## `web.scrape`

```ts
web.scrape(url: string, opts?: { formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }): Promise<WebScrapeOutput>
```

Reads one web page and returns its content as clean Markdown (the default), HTML, its links, a screenshot, a
summary or JSON extracted with your schema. Use it to import an article, read a product page or feed a page to
AI. Pages that need a click or a login need the cloud browser instead.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | yes | The page's `https://` URL. |
| `opts` | `{ formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }` | no | What to return and how to load the page. |
| `opts.formats` | `('screenshot' \| 'markdown' \| 'html' \| 'rawHtml' \| 'links' \| 'json' \| 'summary')[]` | no | What to return: `markdown` (default, clean text), `html` (cleaned HTML), `rawHtml` (the page as served), `links`, `screenshot` (a URL of a page screenshot), `json` (data extracted with `schema`/`prompt`), `summary`. |
| `opts.onlyMainContent` | `boolean` | no | `true` (default) drops headers, footers and navigation; `false` keeps the whole page. |
| `opts.waitFor` | `number` | no | Milliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0. |
| `opts.timeout` | `number` | no | Milliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000. |
| `opts.proxy` | `'basic' \| 'stealth' \| 'auto'` | no | `basic` (default), `stealth` for sites that block scrapers (costs more), or `auto` (stealth only when needed). |
| `opts.location` | `{ country?, languages? }` | no | Where the request appears to come from. |
| `opts.location.country` | `string` | no | Two-letter country code (`ES`, `US`). |
| `opts.location.languages` | `string[]` | no | Preferred languages (`["es-ES"]`). |
| `opts.actions` | `(Record<string, unknown>)[]` | no | Browser steps to run before reading (click, type, wait, scroll), each `{ type, … }`; up to 20. Allowed: at most 20 items. |
| `opts.schema` | `Record<string, unknown>` | no | With `formats: ["json"]`: the JSON Schema of the data to extract. |
| `opts.prompt` | `string` | no | With `formats: ["json"]`: what to extract, in words (with or without `schema`). |
| `opts.cacheMaxAgeMs` | `number` | no | Accept a cached copy of the page up to this old, in milliseconds (faster, same price). Allowed: ≥ 0. |

**Returns** `Promise<WebScrapeOutput>` — The page in the formats asked for, its metadata, and the credits it cost.

| Field | Type | Always present | Description |
|---|---|---|---|
| `url` | `string` | yes | The page's final URL (after redirects). |
| `statusCode` | `number` | yes | The HTTP status the page answered with. |
| `metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `metadata.title` | `string` | no | The page `<title>`. |
| `metadata.description` | `string` | no | The page's meta description. |
| `metadata.language` | `string` | no | The page language (`en`). |
| `usage` | `{ credits }` | yes | What the call cost. |
| `usage.credits` | `number` | yes | Credits charged for this call. |
| `markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `html` | `string` | no | The cleaned HTML (with `html`). |
| `rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `links` | `string[]` | no | Every link on the page (with `links`). |
| `screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `summary` | `string` | no | A short summary of the page (with `summary`). |
| `contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `URL_NOT_ALLOWED` | 400 | Not a public `http(s)` URL (a private address, `localhost`, a Totalum host). |
| `SCRAPE_BLOCKED` | 502 | The site refused the request; try `proxy: 'stealth'`. |
| `SCRAPE_FAILED` | 502 | The page could not be read. |
| `PROVIDER_TIMEOUT` | 504 | The page took too long; raise `timeout` or retry. |
| `PROVIDER_UNAVAILABLE` | 503 | The scraping service is unavailable; retry later. |

**Examples**

```ts
const page = await totalum.web.scrape('https://example.com', { formats: ['markdown'] });
```

Result:

```json
{
  "url": "https://example.com/",
  "statusCode": 200,
  "metadata": { "sourceURL": "https://example.com/", "title": "Example Domain", "language": "en" },
  "markdown": "# Example Domain\n\nThis domain is for use in documentation examples without needing permission. …",
  "usage": { "credits": 0.0343 }
}
```

```ts
// structured data with a JSON schema
const { json } = await totalum.web.scrape('https://shop.example.com/p/red-shoes', {
  formats: ['json'],
  schema: { type: 'object', properties: { name: { type: 'string' }, price: { type: 'number' } } },
});
```

Result:

```json
{ "name": "Red running shoes", "price": 79.9 }
```

## `web.search`

```ts
web.search(query: string, opts?: { limit?, location?, sources?, timeRange?, scrapeOptions? }): Promise<{ web, news?, images?, scraped?, usage }>
```

Searches the web and returns the results (title, URL, snippet); with `scrapeOptions`, each result's page content
too. Use it for research features, lead finding or to ground an AI answer in current pages.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `query` | `string` | yes | What to search for, as you would type it in a search engine. |
| `opts` | `{ limit?, location?, sources?, timeRange?, scrapeOptions? }` | no | How many results, which sources, where and how recent. |
| `opts.limit` | `number` | no | Results per source. Default 5. Allowed: > 0, ≤ 100. |
| `opts.location` | `{ country?, city? }` | no | Search as if from this place. |
| `opts.location.country` | `string` | no | Two-letter country code. |
| `opts.location.city` | `string` | no | A city name. |
| `opts.sources` | `('web' \| 'news' \| 'images')[]` | no | Which result types: `web` (default), `news`, `images`. |
| `opts.timeRange` | `'day' \| 'month' \| 'week' \| 'year'` | no | Only results from the last `day`, `week`, `month` or `year`. |
| `opts.scrapeOptions` | `{ formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }` | no | Also read each result page with these scrape options (see `web.scrape`); the page content comes back in `scraped`. Costs more. |
| `opts.scrapeOptions.formats` | `('screenshot' \| 'markdown' \| 'html' \| 'rawHtml' \| 'links' \| 'json' \| 'summary')[]` | no | What to return: `markdown` (default, clean text), `html` (cleaned HTML), `rawHtml` (the page as served), `links`, `screenshot` (a URL of a page screenshot), `json` (data extracted with `schema`/`prompt`), `summary`. |
| `opts.scrapeOptions.onlyMainContent` | `boolean` | no | `true` (default) drops headers, footers and navigation; `false` keeps the whole page. |
| `opts.scrapeOptions.waitFor` | `number` | no | Milliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0. |
| `opts.scrapeOptions.timeout` | `number` | no | Milliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000. |
| `opts.scrapeOptions.proxy` | `'basic' \| 'stealth' \| 'auto'` | no | `basic` (default), `stealth` for sites that block scrapers (costs more), or `auto` (stealth only when needed). |
| `opts.scrapeOptions.location` | `{ country?, languages? }` | no | Where the request appears to come from. |
| `opts.scrapeOptions.location.country` | `string` | no | Two-letter country code (`ES`, `US`). |
| `opts.scrapeOptions.location.languages` | `string[]` | no | Preferred languages (`["es-ES"]`). |
| `opts.scrapeOptions.actions` | `(Record<string, unknown>)[]` | no | Browser steps to run before reading (click, type, wait, scroll), each `{ type, … }`; up to 20. Allowed: at most 20 items. |
| `opts.scrapeOptions.schema` | `Record<string, unknown>` | no | With `formats: ["json"]`: the JSON Schema of the data to extract. |
| `opts.scrapeOptions.prompt` | `string` | no | With `formats: ["json"]`: what to extract, in words (with or without `schema`). |
| `opts.scrapeOptions.cacheMaxAgeMs` | `number` | no | Accept a cached copy of the page up to this old, in milliseconds (faster, same price). Allowed: ≥ 0. |

**Returns** `Promise<{ web, news?, images?, scraped?, usage }>` — The results by source and the credits the search cost.

| Field | Type | Always present | Description |
|---|---|---|---|
| `web` | `({ title, url, position, snippet? })[]` | yes | Web results, best first. |
| `web.title` | `string` | yes | The result's title. |
| `web.url` | `string` | yes | The result's URL. |
| `web.position` | `number` | yes | The rank, from 1. |
| `web.snippet` | `string` | no | A short extract of the page. |
| `news` | `({ title, url, position, snippet? })[]` | no | News results (with `sources` including `news`). |
| `news.title` | `string` | yes | The article's title. |
| `news.url` | `string` | yes | The article's URL. |
| `news.position` | `number` | yes | The rank, from 1. |
| `news.snippet` | `string` | no | A short extract. |
| `images` | `(Record<string, unknown>)[]` | no | Image results (with `sources` including `images`), as the search returns them. |
| `scraped` | `({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]` | no | With `scrapeOptions`: each web result's page, read like `web.scrape()` (same fields). |
| `scraped.url` | `string` | yes | The page's final URL (after redirects). |
| `scraped.statusCode` | `number` | yes | The HTTP status the page answered with. |
| `scraped.metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `scraped.metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `scraped.metadata.title` | `string` | no | The page `<title>`. |
| `scraped.metadata.description` | `string` | no | The page's meta description. |
| `scraped.metadata.language` | `string` | no | The page language (`en`). |
| `scraped.markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `scraped.html` | `string` | no | The cleaned HTML (with `html`). |
| `scraped.rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `scraped.links` | `string[]` | no | Every link on the page (with `links`). |
| `scraped.screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `scraped.json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `scraped.summary` | `string` | no | A short summary of the page (with `summary`). |
| `scraped.contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |
| `usage` | `{ credits }` | yes | What the call cost. |
| `usage.credits` | `number` | yes | Credits charged for this call. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `SEARCH_FAILED` | 502 | The search could not be run. |
| `PROVIDER_TIMEOUT` | 504 | The search took too long; retry. |
| `PROVIDER_UNAVAILABLE` | 503 | The search service is unavailable; retry later. |

**Example**

```ts
const results = await totalum.web.search('totalum app builder', { limit: 2 });
```

Result:

```json
{
  "web": [
    {
      "title": "Totalum - The most powerful AI app builder for humans and for agents",
      "url": "https://www.totalum.app/en",
      "snippet": "Create any web or app. The first AI app builder you can use via API and MCP…",
      "position": 1
    },
    {
      "title": "Totalum Blog: AI app builder, AI coding agents, MCP guides",
      "url": "https://www.totalum.app/blog",
      "snippet": "An AI app builder that generates real code lets you export and own the source…",
      "position": 2
    }
  ],
  "usage": { "credits": 0.0685 }
}
```

## `web.map`

```ts
web.map(url: string, opts?: { limit?, search? }): Promise<{ links, usage }>
```

Lists the URLs of a site (from its sitemap and links) without reading the pages — to choose what to scrape, or
to build a site index.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | yes | The site's `https://` URL. |
| `opts` | `{ limit?, search? }` | no | A search filter and the maximum number of links. |
| `opts.limit` | `number` | no | At most this many URLs. Allowed: > 0, ≤ 5000. |
| `opts.search` | `string` | no | Only URLs related to this word. |

**Returns** `Promise<{ links, usage }>` — The URLs found and the credits the call cost.

| Field | Type | Always present | Description |
|---|---|---|---|
| `links` | `string[]` | yes | The URLs found. |
| `usage` | `{ credits }` | yes | What the call cost. |
| `usage.credits` | `number` | yes | Credits charged for this call. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `URL_NOT_ALLOWED` | 400 | Not a public `http(s)` URL. |
| `SCRAPE_FAILED` | 502 | The site could not be mapped. |
| `PROVIDER_UNAVAILABLE` | 503 | The scraping service is unavailable; retry later. |

**Example**

```ts
const { links } = await totalum.web.map('https://docs.example.com', { search: 'pricing', limit: 5 });
```

Result:

```json
{
  "links": ["https://docs.example.com/pricing", "https://docs.example.com/pricing/teams"],
  "usage": { "credits": 0.0343 }
}
```

## `web.crawl`

```ts
web.crawl(url: string, opts?: { limit?, scrapeOptions?, maxDepth?, includePaths?, excludePaths?, webhook? }): Promise<JobCreated>
```

Starts reading a whole site (or part of it) in the background and returns a job id at once. Store the id, then
call `crawlStatus(jobId)` (from a later request or a cron job) until `status` is no longer `running`; the job
is charged by the pages read, settled on that read. The plan caps the pages per crawl: 20 on Free, 500 on
Starter, 2,000 on Builder, 10,000 on Professional and 50,000 on Enterprise.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | yes | The `https://` URL to start from. |
| `opts` | `{ limit?, scrapeOptions?, maxDepth?, includePaths?, excludePaths?, webhook? }` | no | How many pages, how deep, which paths, and how to read each page. |
| `opts.limit` | `number` | no | At most this many pages. Default: 100, or the plan's maximum if lower. Allowed: > 0. |
| `opts.scrapeOptions` | `{ formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }` | no | How each page is read (see `web.scrape`). |
| `opts.scrapeOptions.formats` | `('screenshot' \| 'markdown' \| 'html' \| 'rawHtml' \| 'links' \| 'json' \| 'summary')[]` | no | What to return: `markdown` (default, clean text), `html` (cleaned HTML), `rawHtml` (the page as served), `links`, `screenshot` (a URL of a page screenshot), `json` (data extracted with `schema`/`prompt`), `summary`. |
| `opts.scrapeOptions.onlyMainContent` | `boolean` | no | `true` (default) drops headers, footers and navigation; `false` keeps the whole page. |
| `opts.scrapeOptions.waitFor` | `number` | no | Milliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0. |
| `opts.scrapeOptions.timeout` | `number` | no | Milliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000. |
| `opts.scrapeOptions.proxy` | `'basic' \| 'stealth' \| 'auto'` | no | `basic` (default), `stealth` for sites that block scrapers (costs more), or `auto` (stealth only when needed). |
| `opts.scrapeOptions.location` | `{ country?, languages? }` | no | Where the request appears to come from. |
| `opts.scrapeOptions.location.country` | `string` | no | Two-letter country code (`ES`, `US`). |
| `opts.scrapeOptions.location.languages` | `string[]` | no | Preferred languages (`["es-ES"]`). |
| `opts.scrapeOptions.actions` | `(Record<string, unknown>)[]` | no | Browser steps to run before reading (click, type, wait, scroll), each `{ type, … }`; up to 20. Allowed: at most 20 items. |
| `opts.scrapeOptions.schema` | `Record<string, unknown>` | no | With `formats: ["json"]`: the JSON Schema of the data to extract. |
| `opts.scrapeOptions.prompt` | `string` | no | With `formats: ["json"]`: what to extract, in words (with or without `schema`). |
| `opts.scrapeOptions.cacheMaxAgeMs` | `number` | no | Accept a cached copy of the page up to this old, in milliseconds (faster, same price). Allowed: ≥ 0. |
| `opts.maxDepth` | `number` | no | How many links away from `url` to follow. Allowed: ≥ 0. |
| `opts.includePaths` | `string[]` | no | Only URLs whose path matches one of these regular expressions (`/blog/.*`). |
| `opts.excludePaths` | `string[]` | no | Skip URLs whose path matches one of these regular expressions. |
| `opts.webhook` | `boolean` | no | Accepted for compatibility but not used: poll `crawlStatus()` instead. |

**Returns** `Promise<JobCreated>` — The job id and the credits reserved for it (the real charge is settled when it ends).

| Field | Type | Always present | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The job id: store it and pass it to the status method. |
| `estimatedCredits` | `number` | no | The credits reserved for the job; the real charge is settled when it ends. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `VALIDATION_ERROR` | 400 | `limit` is above the plan's pages per crawl; `details.maxPages`. |
| `URL_NOT_ALLOWED` | 400 | Not a public `http(s)` URL. |
| `SCRAPE_FAILED` | 502 | The crawl could not be started. |
| `PROVIDER_UNAVAILABLE` | 503 | The scraping service is unavailable; retry later. |

**Example**

```ts
const { jobId } = await totalum.web.crawl('https://docs.example.com', { limit: 50, includePaths: ['/guides/.*'] });
// save jobId, then poll crawlStatus(jobId) later
```

Result:

```json
{ "jobId": "01M4P1C8Z3X7Y2W5V9T6S4R0QA", "estimatedCredits": 1.716 }
```

## `web.crawlStatus`

```ts
web.crawlStatus(jobId: string): Promise<WebJob>
```

Reads a crawl job: its status, how many pages are done and their content. Poll it every few seconds or from a cron
job until `status` is `completed`, `failed`, `cancelled` or `expired`. Reading a finished job settles its charge.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The `jobId` from `crawl()`. |

**Returns** `Promise<WebJob>` — The job's progress and the pages read so far.

| Field | Type | Always present | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The job id. |
| `status` | `'expired' \| 'completed' \| 'queued' \| 'running' \| 'failed' \| 'cancelled'` | yes | `running` while pages are read; then `completed`, `failed`, `cancelled` or `expired`. `queued` before it starts. |
| `total` | `number` | yes | Pages found so far. |
| `completed` | `number` | yes | Pages read so far. |
| `creditsUsed` | `number` | yes | The crawl's usage units so far (one per page, more with `stealth` or `json`); the charge in Totalum credits is settled from it when the job ends. |
| `data` | `({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]` | yes | The pages read so far, each like a `web.scrape()` result. |
| `data.url` | `string` | yes | The page's final URL (after redirects). |
| `data.statusCode` | `number` | yes | The HTTP status the page answered with. |
| `data.metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `data.metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `data.metadata.title` | `string` | no | The page `<title>`. |
| `data.metadata.description` | `string` | no | The page's meta description. |
| `data.metadata.language` | `string` | no | The page language (`en`). |
| `data.markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `data.html` | `string` | no | The cleaned HTML (with `html`). |
| `data.rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `data.links` | `string[]` | no | Every link on the page (with `links`). |
| `data.screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `data.json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `data.summary` | `string` | no | A short summary of the page (with `summary`). |
| `data.contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |
| `next` | `string` | no | Reserved for paging very large jobs; not returned today. |
| `resultUrl` | `string` | no | Reserved for very large results; not returned today. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `JOB_NOT_FOUND` | 404 | No such job for this project (job ids are kept 7 days). |
| `SCRAPE_FAILED` | 502 | The job could not be read; retry. |

**Example**

```ts
const job = await totalum.web.crawlStatus('01M4P1C8Z3X7Y2W5V9T6S4R0QA');
if (job.status === 'completed') for (const page of job.data) await savePage(page.url, page.markdown);
```

Result:

```json
{
  "jobId": "01M4P1C8Z3X7Y2W5V9T6S4R0QA",
  "status": "completed",
  "total": 2,
  "completed": 2,
  "creditsUsed": 2,
  "data": [
    { "url": "https://docs.example.com/guides/start", "statusCode": 200, "metadata": { "sourceURL": "https://docs.example.com/guides/start", "title": "Getting started" }, "markdown": "# Getting started\n…" },
    { "url": "https://docs.example.com/guides/deploy", "statusCode": 200, "metadata": { "sourceURL": "https://docs.example.com/guides/deploy", "title": "Deploy" }, "markdown": "# Deploy\n…" }
  ]
}
```

## `web.cancelCrawl`

```ts
web.cancelCrawl(jobId: string): Promise<WebJob>
```

Stops a running crawl. Pages already read are kept in the answer and charged.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The `jobId` from `crawl()`. |

**Returns** `Promise<WebJob>` — The job, now `cancelled`, with the pages read before it stopped.

| Field | Type | Always present | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The job id. |
| `status` | `'expired' \| 'completed' \| 'queued' \| 'running' \| 'failed' \| 'cancelled'` | yes | `running` while pages are read; then `completed`, `failed`, `cancelled` or `expired`. `queued` before it starts. |
| `total` | `number` | yes | Pages found so far. |
| `completed` | `number` | yes | Pages read so far. |
| `creditsUsed` | `number` | yes | The crawl's usage units so far (one per page, more with `stealth` or `json`); the charge in Totalum credits is settled from it when the job ends. |
| `data` | `({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]` | yes | The pages read so far, each like a `web.scrape()` result. |
| `data.url` | `string` | yes | The page's final URL (after redirects). |
| `data.statusCode` | `number` | yes | The HTTP status the page answered with. |
| `data.metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `data.metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `data.metadata.title` | `string` | no | The page `<title>`. |
| `data.metadata.description` | `string` | no | The page's meta description. |
| `data.metadata.language` | `string` | no | The page language (`en`). |
| `data.markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `data.html` | `string` | no | The cleaned HTML (with `html`). |
| `data.rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `data.links` | `string[]` | no | Every link on the page (with `links`). |
| `data.screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `data.json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `data.summary` | `string` | no | A short summary of the page (with `summary`). |
| `data.contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |
| `next` | `string` | no | Reserved for paging very large jobs; not returned today. |
| `resultUrl` | `string` | no | Reserved for very large results; not returned today. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `JOB_NOT_FOUND` | 404 | No such job for this project. |

**Example**

```ts
const job = await totalum.web.cancelCrawl('01M4P1C8Z3X7Y2W5V9T6S4R0QA');
```

Result:

```ts
{ "jobId": "01M4P1C8Z3X7Y2W5V9T6S4R0QA", "status": "cancelled", "total": 50, "completed": 12, "creditsUsed": 12, "data": […] }
```

## `web.screenshot`

```ts
web.screenshot(input: ScreenshotInput): Promise<{ key, url, format, base64?, usage }>
```

Takes a screenshot of a web page (`url`) or of HTML you pass (`html`) and stores it as a public project file:
link previews, social images, visual checks.

**Parameters**

| Name | Type | Required | Description |
|---|---|---|---|
| `input` | [`ScreenshotInput`](#screenshotinput) | yes | What to capture and how. |
| `input.url` | `string` | no | The page to capture (or pass `html`). Allowed: a URL. |
| `input.html` | `string` | no | HTML to render and capture instead of a URL. |
| `input.fullPage` | `boolean` | no | `true` captures the whole scrolling page; default only the viewport. |
| `input.viewport` | `{ width, height }` | no | The browser window size. |
| `input.viewport.width` | `number` | yes | Width in pixels. Allowed: > 0. |
| `input.viewport.height` | `number` | yes | Height in pixels. Allowed: > 0. |
| `input.format` | `'png' \| 'jpeg' \| 'webp'` | no | `png` (default), `jpeg` or `webp`. |
| `input.waitForSelector` | `string` | no | Wait until this CSS selector is on the page before capturing. |
| `input.inline` | `boolean` | no | `true` also returns the image as base64 (images up to 2 MB). |

**Returns** `Promise<{ key, url, format, base64?, usage }>` — The stored image's `key` and `url`, its format, and the credits it cost.

| Field | Type | Always present | Description |
|---|---|---|---|
| `key` | `string` | yes | The stored file's key (see `totalum.files`). |
| `url` | `string` | yes | The image's public URL. |
| `format` | `'png' \| 'jpeg' \| 'webp'` | yes | The image format. |
| `base64` | `string` | no | The image bytes in base64, with `inline: true` (up to 2 MB). |
| `usage` | `{ credits }` | yes | What the call cost. |
| `usage.credits` | `number` | yes | Credits charged for this call. |

**Errors** — besides the [errors every call can throw](https://www.totalum.app/docs/sdk#errors):

| Code | HTTP | When |
|---|---|---|
| `URL_NOT_ALLOWED` | 400 | Not a public `http(s)` URL. |
| `SCREENSHOT_FAILED` | 502 | The page could not be captured. |
| `VALIDATION_ERROR` | 400 | Neither `url` nor `html` was given. |

**Example**

```ts
const shot = await totalum.web.screenshot({
  html: '<div style="font:48px sans-serif;padding:40px">Launch day 🚀</div>',
  viewport: { width: 1200, height: 630 },
});
```

Result:

```json
{
  "key": "p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png",
  "url": "https://files.totalum-project.com/p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png",
  "format": "png",
  "usage": { "credits": 0.0002 }
}
```

## `JobCreated`

A background job that was started.

| Field | Type | Always present | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The job id: store it and pass it to the status method. |
| `estimatedCredits` | `number` | no | The credits reserved for the job; the real charge is settled when it ends. |

## `ScreenshotInput`

The options of `web.screenshot()`.

| Name | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | no | The page to capture (or pass `html`). Allowed: a URL. |
| `html` | `string` | no | HTML to render and capture instead of a URL. |
| `fullPage` | `boolean` | no | `true` captures the whole scrolling page; default only the viewport. |
| `viewport` | `{ width, height }` | no | The browser window size. |
| `viewport.width` | `number` | yes | Width in pixels. Allowed: > 0. |
| `viewport.height` | `number` | yes | Height in pixels. Allowed: > 0. |
| `format` | `'png' \| 'jpeg' \| 'webp'` | no | `png` (default), `jpeg` or `webp`. |
| `waitForSelector` | `string` | no | Wait until this CSS selector is on the page before capturing. |
| `inline` | `boolean` | no | `true` also returns the image as base64 (images up to 2 MB). |

## `ScreenshotOutput`

A screenshot stored as a public project file.

| Field | Type | Always present | Description |
|---|---|---|---|
| `key` | `string` | yes | The stored file's key (see `totalum.files`). |
| `url` | `string` | yes | The image's public URL. |
| `format` | `'png' \| 'jpeg' \| 'webp'` | yes | The image format. |
| `base64` | `string` | no | The image bytes in base64, with `inline: true` (up to 2 MB). |

## `WebJob`

A crawl job, from `web.crawlStatus()` and `web.cancelCrawl()`.

| Field | Type | Always present | Description |
|---|---|---|---|
| `jobId` | `string` | yes | The job id. |
| `status` | `'expired' \| 'completed' \| 'queued' \| 'running' \| 'failed' \| 'cancelled'` | yes | `running` while pages are read; then `completed`, `failed`, `cancelled` or `expired`. `queued` before it starts. |
| `total` | `number` | yes | Pages found so far. |
| `completed` | `number` | yes | Pages read so far. |
| `creditsUsed` | `number` | yes | The crawl's usage units so far (one per page, more with `stealth` or `json`); the charge in Totalum credits is settled from it when the job ends. |
| `data` | `({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]` | yes | The pages read so far, each like a `web.scrape()` result. |
| `data.url` | `string` | yes | The page's final URL (after redirects). |
| `data.statusCode` | `number` | yes | The HTTP status the page answered with. |
| `data.metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `data.metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `data.metadata.title` | `string` | no | The page `<title>`. |
| `data.metadata.description` | `string` | no | The page's meta description. |
| `data.metadata.language` | `string` | no | The page language (`en`). |
| `data.markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `data.html` | `string` | no | The cleaned HTML (with `html`). |
| `data.rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `data.links` | `string[]` | no | Every link on the page (with `links`). |
| `data.screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `data.json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `data.summary` | `string` | no | A short summary of the page (with `summary`). |
| `data.contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |
| `next` | `string` | no | Reserved for paging very large jobs; not returned today. |
| `resultUrl` | `string` | no | Reserved for very large results; not returned today. |

## `WebScrapeOutput`

One page read by `web.scrape()`.

| Field | Type | Always present | Description |
|---|---|---|---|
| `url` | `string` | yes | The page's final URL (after redirects). |
| `statusCode` | `number` | yes | The HTTP status the page answered with. |
| `metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `metadata.title` | `string` | no | The page `<title>`. |
| `metadata.description` | `string` | no | The page's meta description. |
| `metadata.language` | `string` | no | The page language (`en`). |
| `usage` | `{ credits }` | yes | What the call cost. |
| `usage.credits` | `number` | yes | Credits charged for this call. |
| `markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `html` | `string` | no | The cleaned HTML (with `html`). |
| `rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `links` | `string[]` | no | Every link on the page (with `links`). |
| `screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `summary` | `string` | no | A short summary of the page (with `summary`). |
| `contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |

## `WebSearchOutput`

The results of `web.search()`, by source.

| Field | Type | Always present | Description |
|---|---|---|---|
| `web` | `({ title, url, position, snippet? })[]` | yes | Web results, best first. |
| `web.title` | `string` | yes | The result's title. |
| `web.url` | `string` | yes | The result's URL. |
| `web.position` | `number` | yes | The rank, from 1. |
| `web.snippet` | `string` | no | A short extract of the page. |
| `news` | `({ title, url, position, snippet? })[]` | no | News results (with `sources` including `news`). |
| `news.title` | `string` | yes | The article's title. |
| `news.url` | `string` | yes | The article's URL. |
| `news.position` | `number` | yes | The rank, from 1. |
| `news.snippet` | `string` | no | A short extract. |
| `images` | `(Record<string, unknown>)[]` | no | Image results (with `sources` including `images`), as the search returns them. |
| `scraped` | `({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]` | no | With `scrapeOptions`: each web result's page, read like `web.scrape()` (same fields). |
| `scraped.url` | `string` | yes | The page's final URL (after redirects). |
| `scraped.statusCode` | `number` | yes | The HTTP status the page answered with. |
| `scraped.metadata` | `{ sourceURL, title?, description?, language? }` | yes | The page's title, description and language. |
| `scraped.metadata.sourceURL` | `string` | yes | The URL that was asked for. |
| `scraped.metadata.title` | `string` | no | The page `<title>`. |
| `scraped.metadata.description` | `string` | no | The page's meta description. |
| `scraped.metadata.language` | `string` | no | The page language (`en`). |
| `scraped.markdown` | `string` | no | The page as Markdown (with `formats` including `markdown`, the default). |
| `scraped.html` | `string` | no | The cleaned HTML (with `html`). |
| `scraped.rawHtml` | `string` | no | The HTML exactly as served (with `rawHtml`). |
| `scraped.links` | `string[]` | no | Every link on the page (with `links`). |
| `scraped.screenshotUrl` | `string` | no | A URL of a screenshot of the page (with `screenshot`). |
| `scraped.json` | `unknown` | no | The data extracted with your `schema`/`prompt` (with `json`). |
| `scraped.summary` | `string` | no | A short summary of the page (with `summary`). |
| `scraped.contentUrl` | `string` | no | Reserved for content too large to return inline; not returned today. |
