Docs
BlogHomeStart building

Web Scraping & Search (totalum-sdk/web)


import … from 'totalum-sdk/web' — or the same namespace on totalum from 'totalum-sdk'. Install, configuration and errors: Totalum 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 typeWhat it does
totalumWebCreates 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.scrapeReads 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.searchSearches the web and returns the results (title, URL, snippet); with scrapeOptions, each result's page content too.
web.mapLists 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.crawlStarts reading a whole site (or part of it) in the background and returns a job id at once.
web.crawlStatusReads a crawl job: its status, how many pages are done and their content.
web.cancelCrawlStops a running crawl.
web.screenshotTakes 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.
JobCreatedA background job that was started.
ScreenshotInputThe options of web.screenshot().
ScreenshotOutputA screenshot stored as a public project file.
WebJobA crawl job, from web.crawlStatus() and web.cancelCrawl().
WebScrapeOutputOne page read by web.scrape().
WebSearchOutputThe 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

NameTypeRequiredDescription
optionsTotalumClientOptionsnoThe project key, API URL and environment; each falls back to its environment variable.
options.keystringnoProject key tlm_pk_…; default TOTALUM_PROJECT_KEY. Server-side only.
options.apiUrlstringnoThe Totalum API's URL: default TOTALUM_SDK_API_URL, else https://sdk-api.totalum.app.
options.env'dev' | 'live'noSent as x-totalum-env on every call (the database it targets, and dev vs live usage); default TOTALUM_ENV, else live.

Returns 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

NameTypeRequiredDescription
urlstringyesThe page's https:// URL.
opts{ formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }noWhat to return and how to load the page.
opts.formats('screenshot' | 'markdown' | 'html' | 'rawHtml' | 'links' | 'json' | 'summary')[]noWhat 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.onlyMainContentbooleannotrue (default) drops headers, footers and navigation; false keeps the whole page.
opts.waitFornumbernoMilliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0.
opts.timeoutnumbernoMilliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000.
opts.proxy'basic' | 'stealth' | 'auto'nobasic (default), stealth for sites that block scrapers (costs more), or auto (stealth only when needed).
opts.location{ country?, languages? }noWhere the request appears to come from.
opts.location.countrystringnoTwo-letter country code (ES, US).
opts.location.languagesstring[]noPreferred languages (["es-ES"]).
opts.actions(Record<string, unknown>)[]noBrowser steps to run before reading (click, type, wait, scroll), each { type, … }; up to 20. Allowed: at most 20 items.
opts.schemaRecord<string, unknown>noWith formats: ["json"]: the JSON Schema of the data to extract.
opts.promptstringnoWith formats: ["json"]: what to extract, in words (with or without schema).
opts.cacheMaxAgeMsnumbernoAccept 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.

FieldTypeAlways presentDescription
urlstringyesThe page's final URL (after redirects).
statusCodenumberyesThe HTTP status the page answered with.
metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
metadata.sourceURLstringyesThe URL that was asked for.
metadata.titlestringnoThe page <title>.
metadata.descriptionstringnoThe page's meta description.
metadata.languagestringnoThe page language (en).
usage{ credits }yesWhat the call cost.
usage.creditsnumberyesCredits charged for this call.
markdownstringnoThe page as Markdown (with formats including markdown, the default).
htmlstringnoThe cleaned HTML (with html).
rawHtmlstringnoThe HTML exactly as served (with rawHtml).
linksstring[]noEvery link on the page (with links).
screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
jsonunknownnoThe data extracted with your schema/prompt (with json).
summarystringnoA short summary of the page (with summary).
contentUrlstringnoReserved for content too large to return inline; not returned today.

Errors — besides the errors every call can throw:

CodeHTTPWhen
URL_NOT_ALLOWED400Not a public http(s) URL (a private address, localhost, a Totalum host).
SCRAPE_BLOCKED502The site refused the request; try proxy: 'stealth'.
SCRAPE_FAILED502The page could not be read.
PROVIDER_TIMEOUT504The page took too long; raise timeout or retry.
PROVIDER_UNAVAILABLE503The 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

NameTypeRequiredDescription
querystringyesWhat to search for, as you would type it in a search engine.
opts{ limit?, location?, sources?, timeRange?, scrapeOptions? }noHow many results, which sources, where and how recent.
opts.limitnumbernoResults per source. Default 5. Allowed: > 0, ≤ 100.
opts.location{ country?, city? }noSearch as if from this place.
opts.location.countrystringnoTwo-letter country code.
opts.location.citystringnoA city name.
opts.sources('web' | 'news' | 'images')[]noWhich result types: web (default), news, images.
opts.timeRange'day' | 'month' | 'week' | 'year'noOnly results from the last day, week, month or year.
opts.scrapeOptions{ formats?, onlyMainContent?, waitFor?, timeout?, proxy?, location?, actions?, schema?, prompt?, cacheMaxAgeMs? }noAlso 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')[]noWhat 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.onlyMainContentbooleannotrue (default) drops headers, footers and navigation; false keeps the whole page.
opts.scrapeOptions.waitFornumbernoMilliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0.
opts.scrapeOptions.timeoutnumbernoMilliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000.
opts.scrapeOptions.proxy'basic' | 'stealth' | 'auto'nobasic (default), stealth for sites that block scrapers (costs more), or auto (stealth only when needed).
opts.scrapeOptions.location{ country?, languages? }noWhere the request appears to come from.
opts.scrapeOptions.location.countrystringnoTwo-letter country code (ES, US).
opts.scrapeOptions.location.languagesstring[]noPreferred languages (["es-ES"]).
opts.scrapeOptions.actions(Record<string, unknown>)[]noBrowser steps to run before reading (click, type, wait, scroll), each { type, … }; up to 20. Allowed: at most 20 items.
opts.scrapeOptions.schemaRecord<string, unknown>noWith formats: ["json"]: the JSON Schema of the data to extract.
opts.scrapeOptions.promptstringnoWith formats: ["json"]: what to extract, in words (with or without schema).
opts.scrapeOptions.cacheMaxAgeMsnumbernoAccept 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.

FieldTypeAlways presentDescription
web({ title, url, position, snippet? })[]yesWeb results, best first.
web.titlestringyesThe result's title.
web.urlstringyesThe result's URL.
web.positionnumberyesThe rank, from 1.
web.snippetstringnoA short extract of the page.
news({ title, url, position, snippet? })[]noNews results (with sources including news).
news.titlestringyesThe article's title.
news.urlstringyesThe article's URL.
news.positionnumberyesThe rank, from 1.
news.snippetstringnoA short extract.
images(Record<string, unknown>)[]noImage results (with sources including images), as the search returns them.
scraped({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]noWith scrapeOptions: each web result's page, read like web.scrape() (same fields).
scraped.urlstringyesThe page's final URL (after redirects).
scraped.statusCodenumberyesThe HTTP status the page answered with.
scraped.metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
scraped.metadata.sourceURLstringyesThe URL that was asked for.
scraped.metadata.titlestringnoThe page <title>.
scraped.metadata.descriptionstringnoThe page's meta description.
scraped.metadata.languagestringnoThe page language (en).
scraped.markdownstringnoThe page as Markdown (with formats including markdown, the default).
scraped.htmlstringnoThe cleaned HTML (with html).
scraped.rawHtmlstringnoThe HTML exactly as served (with rawHtml).
scraped.linksstring[]noEvery link on the page (with links).
scraped.screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
scraped.jsonunknownnoThe data extracted with your schema/prompt (with json).
scraped.summarystringnoA short summary of the page (with summary).
scraped.contentUrlstringnoReserved for content too large to return inline; not returned today.
usage{ credits }yesWhat the call cost.
usage.creditsnumberyesCredits charged for this call.

Errors — besides the errors every call can throw:

CodeHTTPWhen
SEARCH_FAILED502The search could not be run.
PROVIDER_TIMEOUT504The search took too long; retry.
PROVIDER_UNAVAILABLE503The 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

NameTypeRequiredDescription
urlstringyesThe site's https:// URL.
opts{ limit?, search? }noA search filter and the maximum number of links.
opts.limitnumbernoAt most this many URLs. Allowed: > 0, ≤ 5000.
opts.searchstringnoOnly URLs related to this word.

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

FieldTypeAlways presentDescription
linksstring[]yesThe URLs found.
usage{ credits }yesWhat the call cost.
usage.creditsnumberyesCredits charged for this call.

Errors — besides the errors every call can throw:

CodeHTTPWhen
URL_NOT_ALLOWED400Not a public http(s) URL.
SCRAPE_FAILED502The site could not be mapped.
PROVIDER_UNAVAILABLE503The 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

NameTypeRequiredDescription
urlstringyesThe https:// URL to start from.
opts{ limit?, scrapeOptions?, maxDepth?, includePaths?, excludePaths?, webhook? }noHow many pages, how deep, which paths, and how to read each page.
opts.limitnumbernoAt 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? }noHow each page is read (see web.scrape).
opts.scrapeOptions.formats('screenshot' | 'markdown' | 'html' | 'rawHtml' | 'links' | 'json' | 'summary')[]noWhat 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.onlyMainContentbooleannotrue (default) drops headers, footers and navigation; false keeps the whole page.
opts.scrapeOptions.waitFornumbernoMilliseconds to wait after the page loads, for content that appears late. Allowed: ≥ 0.
opts.scrapeOptions.timeoutnumbernoMilliseconds to wait for the page; capped at 9 s. Allowed: > 0, ≤ 55000.
opts.scrapeOptions.proxy'basic' | 'stealth' | 'auto'nobasic (default), stealth for sites that block scrapers (costs more), or auto (stealth only when needed).
opts.scrapeOptions.location{ country?, languages? }noWhere the request appears to come from.
opts.scrapeOptions.location.countrystringnoTwo-letter country code (ES, US).
opts.scrapeOptions.location.languagesstring[]noPreferred languages (["es-ES"]).
opts.scrapeOptions.actions(Record<string, unknown>)[]noBrowser steps to run before reading (click, type, wait, scroll), each { type, … }; up to 20. Allowed: at most 20 items.
opts.scrapeOptions.schemaRecord<string, unknown>noWith formats: ["json"]: the JSON Schema of the data to extract.
opts.scrapeOptions.promptstringnoWith formats: ["json"]: what to extract, in words (with or without schema).
opts.scrapeOptions.cacheMaxAgeMsnumbernoAccept a cached copy of the page up to this old, in milliseconds (faster, same price). Allowed: ≥ 0.
opts.maxDepthnumbernoHow many links away from url to follow. Allowed: ≥ 0.
opts.includePathsstring[]noOnly URLs whose path matches one of these regular expressions (/blog/.*).
opts.excludePathsstring[]noSkip URLs whose path matches one of these regular expressions.
opts.webhookbooleannoAccepted 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).

FieldTypeAlways presentDescription
jobIdstringyesThe job id: store it and pass it to the status method.
estimatedCreditsnumbernoThe credits reserved for the job; the real charge is settled when it ends.

Errors — besides the errors every call can throw:

CodeHTTPWhen
VALIDATION_ERROR400limit is above the plan's pages per crawl; details.maxPages.
URL_NOT_ALLOWED400Not a public http(s) URL.
SCRAPE_FAILED502The crawl could not be started.
PROVIDER_UNAVAILABLE503The 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

NameTypeRequiredDescription
jobIdstringyesThe jobId from crawl().

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

FieldTypeAlways presentDescription
jobIdstringyesThe job id.
status'expired' | 'completed' | 'queued' | 'running' | 'failed' | 'cancelled'yesrunning while pages are read; then completed, failed, cancelled or expired. queued before it starts.
totalnumberyesPages found so far.
completednumberyesPages read so far.
creditsUsednumberyesThe 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? })[]yesThe pages read so far, each like a web.scrape() result.
data.urlstringyesThe page's final URL (after redirects).
data.statusCodenumberyesThe HTTP status the page answered with.
data.metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
data.metadata.sourceURLstringyesThe URL that was asked for.
data.metadata.titlestringnoThe page <title>.
data.metadata.descriptionstringnoThe page's meta description.
data.metadata.languagestringnoThe page language (en).
data.markdownstringnoThe page as Markdown (with formats including markdown, the default).
data.htmlstringnoThe cleaned HTML (with html).
data.rawHtmlstringnoThe HTML exactly as served (with rawHtml).
data.linksstring[]noEvery link on the page (with links).
data.screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
data.jsonunknownnoThe data extracted with your schema/prompt (with json).
data.summarystringnoA short summary of the page (with summary).
data.contentUrlstringnoReserved for content too large to return inline; not returned today.
nextstringnoReserved for paging very large jobs; not returned today.
resultUrlstringnoReserved for very large results; not returned today.

Errors — besides the errors every call can throw:

CodeHTTPWhen
JOB_NOT_FOUND404No such job for this project (job ids are kept 7 days).
SCRAPE_FAILED502The 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

NameTypeRequiredDescription
jobIdstringyesThe jobId from crawl().

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

FieldTypeAlways presentDescription
jobIdstringyesThe job id.
status'expired' | 'completed' | 'queued' | 'running' | 'failed' | 'cancelled'yesrunning while pages are read; then completed, failed, cancelled or expired. queued before it starts.
totalnumberyesPages found so far.
completednumberyesPages read so far.
creditsUsednumberyesThe 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? })[]yesThe pages read so far, each like a web.scrape() result.
data.urlstringyesThe page's final URL (after redirects).
data.statusCodenumberyesThe HTTP status the page answered with.
data.metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
data.metadata.sourceURLstringyesThe URL that was asked for.
data.metadata.titlestringnoThe page <title>.
data.metadata.descriptionstringnoThe page's meta description.
data.metadata.languagestringnoThe page language (en).
data.markdownstringnoThe page as Markdown (with formats including markdown, the default).
data.htmlstringnoThe cleaned HTML (with html).
data.rawHtmlstringnoThe HTML exactly as served (with rawHtml).
data.linksstring[]noEvery link on the page (with links).
data.screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
data.jsonunknownnoThe data extracted with your schema/prompt (with json).
data.summarystringnoA short summary of the page (with summary).
data.contentUrlstringnoReserved for content too large to return inline; not returned today.
nextstringnoReserved for paging very large jobs; not returned today.
resultUrlstringnoReserved for very large results; not returned today.

Errors — besides the errors every call can throw:

CodeHTTPWhen
JOB_NOT_FOUND404No 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

NameTypeRequiredDescription
inputScreenshotInputyesWhat to capture and how.
input.urlstringnoThe page to capture (or pass html). Allowed: a URL.
input.htmlstringnoHTML to render and capture instead of a URL.
input.fullPagebooleannotrue captures the whole scrolling page; default only the viewport.
input.viewport{ width, height }noThe browser window size.
input.viewport.widthnumberyesWidth in pixels. Allowed: > 0.
input.viewport.heightnumberyesHeight in pixels. Allowed: > 0.
input.format'png' | 'jpeg' | 'webp'nopng (default), jpeg or webp.
input.waitForSelectorstringnoWait until this CSS selector is on the page before capturing.
input.inlinebooleannotrue 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.

FieldTypeAlways presentDescription
keystringyesThe stored file's key (see totalum.files).
urlstringyesThe image's public URL.
format'png' | 'jpeg' | 'webp'yesThe image format.
base64stringnoThe image bytes in base64, with inline: true (up to 2 MB).
usage{ credits }yesWhat the call cost.
usage.creditsnumberyesCredits charged for this call.

Errors — besides the errors every call can throw:

CodeHTTPWhen
URL_NOT_ALLOWED400Not a public http(s) URL.
SCREENSHOT_FAILED502The page could not be captured.
VALIDATION_ERROR400Neither 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.

FieldTypeAlways presentDescription
jobIdstringyesThe job id: store it and pass it to the status method.
estimatedCreditsnumbernoThe credits reserved for the job; the real charge is settled when it ends.

#ScreenshotInput

The options of web.screenshot().

NameTypeRequiredDescription
urlstringnoThe page to capture (or pass html). Allowed: a URL.
htmlstringnoHTML to render and capture instead of a URL.
fullPagebooleannotrue captures the whole scrolling page; default only the viewport.
viewport{ width, height }noThe browser window size.
viewport.widthnumberyesWidth in pixels. Allowed: > 0.
viewport.heightnumberyesHeight in pixels. Allowed: > 0.
format'png' | 'jpeg' | 'webp'nopng (default), jpeg or webp.
waitForSelectorstringnoWait until this CSS selector is on the page before capturing.
inlinebooleannotrue also returns the image as base64 (images up to 2 MB).

#ScreenshotOutput

A screenshot stored as a public project file.

FieldTypeAlways presentDescription
keystringyesThe stored file's key (see totalum.files).
urlstringyesThe image's public URL.
format'png' | 'jpeg' | 'webp'yesThe image format.
base64stringnoThe image bytes in base64, with inline: true (up to 2 MB).

#WebJob

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

FieldTypeAlways presentDescription
jobIdstringyesThe job id.
status'expired' | 'completed' | 'queued' | 'running' | 'failed' | 'cancelled'yesrunning while pages are read; then completed, failed, cancelled or expired. queued before it starts.
totalnumberyesPages found so far.
completednumberyesPages read so far.
creditsUsednumberyesThe 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? })[]yesThe pages read so far, each like a web.scrape() result.
data.urlstringyesThe page's final URL (after redirects).
data.statusCodenumberyesThe HTTP status the page answered with.
data.metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
data.metadata.sourceURLstringyesThe URL that was asked for.
data.metadata.titlestringnoThe page <title>.
data.metadata.descriptionstringnoThe page's meta description.
data.metadata.languagestringnoThe page language (en).
data.markdownstringnoThe page as Markdown (with formats including markdown, the default).
data.htmlstringnoThe cleaned HTML (with html).
data.rawHtmlstringnoThe HTML exactly as served (with rawHtml).
data.linksstring[]noEvery link on the page (with links).
data.screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
data.jsonunknownnoThe data extracted with your schema/prompt (with json).
data.summarystringnoA short summary of the page (with summary).
data.contentUrlstringnoReserved for content too large to return inline; not returned today.
nextstringnoReserved for paging very large jobs; not returned today.
resultUrlstringnoReserved for very large results; not returned today.

#WebScrapeOutput

One page read by web.scrape().

FieldTypeAlways presentDescription
urlstringyesThe page's final URL (after redirects).
statusCodenumberyesThe HTTP status the page answered with.
metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
metadata.sourceURLstringyesThe URL that was asked for.
metadata.titlestringnoThe page <title>.
metadata.descriptionstringnoThe page's meta description.
metadata.languagestringnoThe page language (en).
usage{ credits }yesWhat the call cost.
usage.creditsnumberyesCredits charged for this call.
markdownstringnoThe page as Markdown (with formats including markdown, the default).
htmlstringnoThe cleaned HTML (with html).
rawHtmlstringnoThe HTML exactly as served (with rawHtml).
linksstring[]noEvery link on the page (with links).
screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
jsonunknownnoThe data extracted with your schema/prompt (with json).
summarystringnoA short summary of the page (with summary).
contentUrlstringnoReserved for content too large to return inline; not returned today.

#WebSearchOutput

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

FieldTypeAlways presentDescription
web({ title, url, position, snippet? })[]yesWeb results, best first.
web.titlestringyesThe result's title.
web.urlstringyesThe result's URL.
web.positionnumberyesThe rank, from 1.
web.snippetstringnoA short extract of the page.
news({ title, url, position, snippet? })[]noNews results (with sources including news).
news.titlestringyesThe article's title.
news.urlstringyesThe article's URL.
news.positionnumberyesThe rank, from 1.
news.snippetstringnoA short extract.
images(Record<string, unknown>)[]noImage results (with sources including images), as the search returns them.
scraped({ url, statusCode, metadata, markdown?, html?, rawHtml?, links?, screenshotUrl?, json?, summary?, contentUrl? })[]noWith scrapeOptions: each web result's page, read like web.scrape() (same fields).
scraped.urlstringyesThe page's final URL (after redirects).
scraped.statusCodenumberyesThe HTTP status the page answered with.
scraped.metadata{ sourceURL, title?, description?, language? }yesThe page's title, description and language.
scraped.metadata.sourceURLstringyesThe URL that was asked for.
scraped.metadata.titlestringnoThe page <title>.
scraped.metadata.descriptionstringnoThe page's meta description.
scraped.metadata.languagestringnoThe page language (en).
scraped.markdownstringnoThe page as Markdown (with formats including markdown, the default).
scraped.htmlstringnoThe cleaned HTML (with html).
scraped.rawHtmlstringnoThe HTML exactly as served (with rawHtml).
scraped.linksstring[]noEvery link on the page (with links).
scraped.screenshotUrlstringnoA URL of a screenshot of the page (with screenshot).
scraped.jsonunknownnoThe data extracted with your schema/prompt (with json).
scraped.summarystringnoA short summary of the page (with summary).
scraped.contentUrlstringnoReserved for content too large to return inline; not returned today.