Official ScrapeGraphAI SDK for the ScrapeGraph AI API v2.
npm i scrapegraph-js
# or
bun add scrapegraph-jsimport { scrapegraphai } from "scrapegraph-js";
const sgai = scrapegraphai({ apiKey: "your-api-key" });
const result = await sgai.scrape("https://example.com", { format: "markdown" });
console.log(result.data);
console.log(result._requestId);Every method returns:
type ApiResult<T> = {
data: T;
_requestId: string;
};Create a client once, then call the available v2 endpoints:
const sgai = scrapegraphai({
apiKey: "your-api-key",
baseUrl: "https://api.scrapegraphai.com", // optional
timeout: 30000, // optional
maxRetries: 2, // optional
});await sgai.scrape("https://example.com", {
format: "markdown",
fetchConfig: {
mock: false,
},
});Raw JSON schema:
await sgai.extract("https://example.com", {
prompt: "Extract the page title",
schema: {
type: "object",
properties: {
title: { type: "string" },
},
},
});Zod schema:
import { z } from "zod";
await sgai.extract("https://example.com", {
prompt: "Extract the page title",
schema: z.object({
title: z.string(),
}),
});await sgai.search("What is the capital of France?", {
numResults: 5,
});await sgai.schema("A product with name and price");await sgai.credits();await sgai.history({
page: 1,
limit: 10,
service: "scrape",
});const crawl = await sgai.crawl.start("https://example.com", {
maxPages: 10,
maxDepth: 2,
});
await sgai.crawl.status((crawl.data as { id: string }).id);await sgai.monitor.create({
url: "https://example.com",
prompt: "Notify me when the price changes",
interval: "1h",
});bun install
bun test
bun run check
bun run buildMIT - ScrapeGraph AI