Skip to main content
@vakra-dev/reader-js is the official TypeScript/JavaScript SDK for the Reader API. It wraps the HTTP contract, parses the response envelope into a discriminated result type, polls async jobs to completion, throws typed errors, and retries transient failures with exponential backoff.

Installation

Current version: 0.2.0. Works in Node 18+, Deno, Bun, Cloudflare Workers, and any modern browser.

Quick start

Do not ship your API key in browser code. The SDK works in the browser, but exposing apiKey client-side means anyone can read and reuse it. Proxy requests through your own backend that holds the key server-side.

Configuration

Scraping

Single URL, synchronous

Single-URL requests return immediately with { kind: "scrape", data: ScrapeResult }.

Screenshots

Request a screenshot alongside content:

Multiple URLs (batch)

Passing urls creates an async job. The SDK auto-polls until the job terminates and returns { kind: "job", data: Job } with all results collected across pagination.

Crawl

Same shape as batch, but with maxDepth or maxPages:

Proxy mode

Control how aggressively Reader bypasses bot walls with proxyMode:
See Proxy modes for the full picture.

Job management

The SDK’s read() method auto-polls batches and crawls, so most callers never need to touch job APIs directly. When you do, these methods are available:

Streaming

For real-time progress updates on a job, use reader.stream(jobId), an async generator that yields events as the job makes progress.
The generator closes automatically when the job terminates.

Credits

Error handling

Every error response from the API is parsed into a specific ReaderApiError subclass. Branch on instanceof rather than HTTP status codes.
Every error has:
  • code: one of 11 stable codes (e.g. "insufficient_credits", "rate_limited")
  • message: human-readable description
  • httpStatus: the HTTP status code
  • details: typed payload specific to the error (e.g. required/available for insufficient_credits)
  • docsUrl: deep link to the error’s documentation
  • requestId: the x-request-id header from the response, for support tickets
The full catalog is at Errors.

Automatic retries

The SDK retries these codes automatically with exponential backoff before throwing: rate_limited (honors Retry-After), concurrency_limited, internal_error, upstream_unavailable, scrape_timeout. All other codes throw immediately.

Webhooks per request

Every read() call can include an inline webhook config that fires on job lifecycle events, useful for fire-and-forget batches.
See Webhooks for the full delivery contract and signature verification.

Types

All public types are re-exported from the package root:

Browser Sessions

Create stealthed browser sessions for Playwright/Puppeteer automation:

Sessions API

Session Types

Next