parsejet
v0.2.0
Published
Official ParseJet SDK for Node.js/Bun/Deno - parse URLs, PDFs, YouTube transcripts and 25+ formats, and convert video to MP3
Downloads
37
Maintainers
Readme
ParseJet SDK
The official ParseJet SDK for Node.js, Bun, and Deno. Extract text from URLs, PDFs, YouTube videos, web pages, and images with a single API.
Installation
# npm
npm install parsejet
# pnpm
pnpm add parsejet
# yarn
yarn add parsejet
# bun
bun add parsejetRequirements: Node.js 18+ (uses native fetch).
Quick Start
import { ParseJet } from "parsejet";
const client = new ParseJet({ apiKey: "pj_YOUR_KEY" });
const result = await client.parse.url("https://example.com");
console.log(result.title);
console.log(result.text);Authentication
Pass your API key directly or set it as an environment variable:
// Option 1: Pass directly
const client = new ParseJet({ apiKey: "pj_YOUR_KEY" });
// Option 2: Environment variable (PARSEJET_API_KEY)
const client = new ParseJet();API Reference
All parse methods return a ParseResult:
type ParseResult = {
text: string;
title: string;
source_type: string;
metadata: Record<string, any>;
};client.parse.url(url, options?)
Parse any URL. ParseJet auto-detects the content type (web page, PDF, YouTube, etc.).
const result = await client.parse.url("https://example.com/report.pdf");
console.log(result.text);
console.log(result.source_type); // "pdf", "webpage", "youtube", etc.With markdown output:
const result = await client.parse.url("https://example.com/article", {
outputFormat: "markdown",
});client.parse.file(buffer, filename, options?)
Parse a file from a Buffer or Uint8Array.
import fs from "fs";
const buffer = fs.readFileSync("report.pdf");
const result = await client.parse.file(buffer, "report.pdf");
console.log(result.text);client.parse.filePath(path, options?)
Parse a file directly from a local path.
const result = await client.parse.filePath("/path/to/report.pdf");
console.log(result.text);client.parse.youtube(url, options?)
Extract a YouTube video transcript.
const result = await client.parse.youtube(
"https://youtube.com/watch?v=dQw4w9WgXcQ",
{ language: "en" }
);
console.log(result.text);client.parse.webpage(url, options?)
Parse a web page and extract its content.
const result = await client.parse.webpage("https://example.com/article");
console.log(result.title);
console.log(result.text);client.convert.audio(buffer, filename, options?)
Convert a video or audio file into a downloadable audio file. Unlike the
parse methods, this returns the file itself rather than extracted text.
Costs 3 credits per request.
import fs from "fs";
import { writeFile } from "fs/promises";
const video = fs.readFileSync("interview.mov");
const audio = await client.convert.audio(video, "interview.mov", {
outputFormat: "mp3", // mp3 | m4a | opus | wav | flac
bitrate: "192k", // ignored for wav and flac
channels: 2, // 1 = mono, 2 = stereo
});
await writeFile(audio.filename, audio.data); // interview.mp3
console.log(audio.duration, audio.sizeBytes);Accepts MP4, MOV, MKV, AVI, WMV, WebM, M4V, FLV, 3GP and MPEG-TS, plus audio containers such as MP3, WAV, M4A, AAC, OGG, OPUS, FLAC and WMA.
client.parse.ocr(buffer, filename, options?)
Perform OCR on an image.
import fs from "fs";
const image = fs.readFileSync("screenshot.png");
const result = await client.parse.ocr(image, "screenshot.png");
console.log(result.text);Options
ParseOptions
Available on all methods:
| Option | Type | Description |
| -------------- | ------------------------ | ---------------------- |
| outputFormat | "text" | "markdown" | Output format |
YouTubeOptions
Additional options for client.parse.youtube():
| Option | Type | Description |
| ---------- | -------- | ---------------------------------- |
| language | string | Preferred transcript language code |
Error Handling
The SDK throws ParseJetError for API errors, which includes the HTTP status code and the error body.
import { ParseJet, ParseJetError } from "parsejet";
const client = new ParseJet();
try {
const result = await client.parse.url("https://example.com");
} catch (error) {
if (error instanceof ParseJetError) {
console.error(`API error ${error.status}: ${error.message}`);
console.error(error.body);
} else {
throw error;
}
}Configuration
const client = new ParseJet({
apiKey: "pj_YOUR_KEY", // API key (or set PARSEJET_API_KEY env var)
baseUrl: "https://api.parsejet.com", // Custom base URL (optional)
});Environment Variables
| Variable | Description |
| ------------------ | ------------- |
| PARSEJET_API_KEY | Your API key |
License
MIT
