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.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— usesgai.scrape()with the right format entry instead.
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 returnsApiResult<T>:
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 pageimages— All image URLssummary— AI-generated summaryjson— Structured extraction with prompt/schemabranding— Brand colors, typography, logosscreenshot— Page screenshot (fullPage,width,height,quality)
Multi-format example
Multi-format example
sgai.extract()
Extract structured data from a URL, HTML, or markdown.
Parameters
*One of
url, html, or markdown is required.With a JSON schema
With a JSON schema
sgai.search()
Web search with optional AI extraction.
Parameters
Search + extraction
Search + extraction
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.
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