Skip to main content

NPM Package

npm version

Source on GitHub

Issues, PRs, and the changelog

License

License
These docs cover scrapegraph-js ≥ 2.1.0. The v2 SDK is ESM-only and requires Node ≥ 22. Earlier 0.x/1.x releases expose a different, deprecated API.
Breaking in 2.1.0 (types only): all exported TypeScript types and Zod schemas dropped the Api prefix and now match scrapegraph-py 1:1 (ApiScrapeRequestScrapeRequest, ApiFetchConfigFetchConfig, apiScrapeRequestSchemascrapeRequestSchema, etc.). Monitor input types are also renamed: ApiMonitorCreateInputMonitorCreateRequest, ApiMonitorUpdateInputMonitorUpdateRequest, ApiMonitorActivityParamsMonitorActivityRequest. ApiResult<T> is the only type that keeps the prefix. Runtime JS code is unchanged — only TypeScript consumers need to rename imports.

Installation

What’s new in v2

  • New entry point: import { ScrapeGraphAI } from "scrapegraph-js" and instantiate once — no more passing the API key to every call.
  • Nested resources: sgai.crawl.*, sgai.monitor.*, sgai.history.*.
  • ApiResult<T> wrapper: no throws — every call returns { status, data, error, elapsedMs }.
  • Auto-picks the API key from SGAI_API_KEY (or pass { apiKey } to the factory).
  • Removed: markdownify, agenticScraper, sitemap, feedback — use sgai.scrape() with the right format entry instead.
v2 is a breaking change. See the Migration Guide if you’re upgrading from v1.

Quick Start

Store your API keys securely in environment variables. Use .env files and libraries like dotenv to load them into your app.

Return Type

Every method returns ApiResult<T>:
Check res.status before accessing res.data.

Services

sgai.scrape()

Fetch a page in one or more formats (markdown, html, screenshot, json, links, images, summary, branding).

Parameters

Formats:
  • markdown — Clean markdown (modes: normal, reader, prune)
  • html — Raw HTML (modes: normal, reader, prune)
  • links — All links on the page
  • images — All image URLs
  • summary — AI-generated summary
  • json — Structured extraction with prompt/schema
  • branding — Brand colors, typography, logos
  • screenshot — Page screenshot (fullPage, width, height, quality)

sgai.extract()

Extract structured data from a URL, HTML, or markdown.

Parameters

*One of url, html, or markdown is required.
Web search with optional AI extraction.

Parameters

sgai.crawl.*

Crawl a site. Access the resource via sgai.crawl.

crawl.start() parameters

sgai.monitor.*

Scheduled monitoring jobs.

monitor.activity() — poll tick history

Paginate through per-run ticks.
Params: limit (1–100, default 20) and cursor for pagination. Each tick exposes id, createdAt, status, changed, elapsedMs, and diffs.

sgai.history.*

sgai.credits() / sgai.healthy()

Configuration Objects

FetchConfig

Controls how pages are fetched. See the proxy configuration guide for details.

Error Handling

Environment Variables

Support

GitHub

Report issues and contribute to the SDK

Email Support

Get help from our development team