Your first request in Node.js
- Get a free API keySign up and copy it from your dashboard.
- Store it in an environment variable
PDF_SUMMARIZE_KEY. - Build a FormDataAppend the PDF as a Blob under the field
file. - POST it and read the JSON.
// summarize.mjs — node summarize.mjs report.pdf
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
const API_URL = 'https://pdf-summarize.com/api/summarize.php';
const KEY = process.env.PDF_SUMMARIZE_KEY;
export async function summarizePdf(path, { length = 'medium', format = 'bullets', outputLang = 'auto' } = {}) {
const form = new FormData();
form.append('file', new Blob([await readFile(path)], { type: 'application/pdf' }), basename(path));
form.append('length', length);
form.append('format', format);
form.append('outputLang', outputLang);
const res = await fetch(API_URL, {
method: 'POST',
headers: { Authorization: `Bearer ${KEY}` },
body: form,
signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok || !data.success) throw new Error(`${res.status}: ${data.error ?? JSON.stringify(data)}`);
return data;
}
const result = await summarizePdf(process.argv[2]);
console.log(result.summary);
console.log(`${result.page_count} pages, ${result.processing_time}s, ${result.requests_remaining} requests left`);
Streaming the summary
export async function streamSummary(path, onText) {
const form = new FormData();
form.append('file', new Blob([await readFile(path)], { type: 'application/pdf' }), basename(path));
form.append('length', 'long');
const res = await fetch(API_URL + '?stream=1', { method: 'POST', headers: { Authorization: `Bearer ${KEY}` }, body: form });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const decoder = new TextDecoder();
let buffer = '';
for await (const chunk of res.body) {
buffer += decoder.decode(chunk, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const payload = line.slice(6);
if (payload === '[DONE]') return;
const event = JSON.parse(payload);
if (event.error) throw new Error(event.error);
if (event.type === 'summary') onText(event.content);
}
}
}
await streamSummary('paper.pdf', (t) => process.stdout.write(t));
An Express endpoint for your own app
Your front-end uploads to your server, which adds the key and forwards the file:
import express from 'express';
import multer from 'multer';
const app = express();
const upload = multer({ limits: { fileSize: 20 * 1024 * 1024 } });
app.post('/summarize', upload.single('file'), async (req, res) => {
if (!req.file) return res.status(400).json({ error: 'No file' });
const form = new FormData();
form.append('file', new Blob([req.file.buffer], { type: 'application/pdf' }), req.file.originalname);
form.append('length', req.body.length ?? 'medium');
const r = await fetch('https://pdf-summarize.com/api/summarize.php', {
method: 'POST', headers: { Authorization: `Bearer ${process.env.PDF_SUMMARIZE_KEY}` }, body: form,
});
res.status(r.status).json(await r.json());
});
app.listen(3000);
Error handling
| Status | Meaning |
|---|---|
| 400 | Missing file, not a PDF, or page limit exceeded |
| 401 | Missing or invalid key |
| 413 | File too large |
| 422 | No readable text in the PDF |
| 429 | Rate limit or quota reached — retry later with backoff |
| 500 | Temporary summarization error — retry |
Frequently asked questions
Can I call the API directly from the browser?
Technically yes, but your key would be visible to anyone. Proxy requests through your backend as in the Express example.
Does it work with Deno, Bun or Cloudflare Workers?
Yes — any runtime with standard fetch and FormData works the same way.
Is there a TypeScript SDK?
Not yet. The API is a single multipart endpoint, so a small typed wrapper around fetch is enough.
Where is the full reference?
In the API documentation, with all parameters and examples in several languages.