This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Always run these commands before committing or saying a task is done:
bun run format
bun run lint
bunx tsc --noEmit
bun run build
bun testNo exceptions.
scrapegraph-js is the official JavaScript/TypeScript SDK for the ScrapeGraph AI API. It provides a TypeScript client for intelligent web scraping powered by AI.
scrapegraph-js/
├── src/ # TypeScript SDK source
├── tests/ # Test suite
├── examples/ # Usage examples
├── scripts/ # Development utilities
└── .github/workflows/ # CI/CD
- Language: TypeScript (Node.js 22+)
- Runtime: Bun
- Core Dependencies: zod (validation)
- Testing: Bun test
- Code Quality: Biome (lint + format)
- Build: tsup
# Install
bun install
# Dev (watch mode)
bun run dev
# Test
bun test # unit tests
bun run test:integration # integration tests
# Format
bun run format
# Lint
bun run lint
# Type check
bunx tsc --noEmit
# Build
bun run build
# Playground (loads .env)
bun run playgroundCore Components:
-
Client (
src/scrapegraphai.ts):ScrapeGraphAI()- Factory function returning namespaced client- Handles all API communication
-
Types (
src/types.ts):- Request/response types for all endpoints
- Zod schema inference
-
Schemas (
src/schemas.ts):- Zod validation schemas
-
Config (
src/env.ts):- Environment variable handling
| Method | Purpose |
|---|---|
sgai.scrape() |
AI data extraction from URL |
sgai.extract() |
Extract from raw HTML/text |
sgai.search() |
Web search + extraction |
sgai.crawl.start() |
Start crawl job |
sgai.crawl.get() |
Get crawl status |
sgai.monitor.create() |
Create monitoring job |
sgai.monitor.get() |
Get monitor status |
sgai.monitor.update() |
Update monitor config |
sgai.monitor.delete() |
Delete monitor |
sgai.credits() |
Check API credits |
sgai.healthy() |
Health check |
sgai.history.list() |
List request history |
sgai.history.get() |
Get specific request |
- Add types in
src/types.ts - Add Zod schema in
src/schemas.ts - Add function in
src/scrapegraphai.ts - Wire into
ScrapeGraphAI()client object - Export types in
src/index.ts - Add tests in
tests/ - Add example in
examples/
SGAI_API_KEY- API key for authenticationSGAI_DEBUG- Enable debug logging (optional)
import { ScrapeGraphAI } from "scrapegraph-js";
const sgai = ScrapeGraphAI(); // reads SGAI_API_KEY from env
const res = await sgai.scrape({
url: "https://example.com",
prompt: "Extract the main heading",
});
if (res.status === "success") {
console.log(res.data?.result);
}