Official SDK
TypeScript / Node.js
Full TypeScript support with type definitions included. Async/await patterns, automatic retries, and comprehensive error handling.
Rename PDFs, split multi-page documents, and extract structured data using the official TypeScript SDK for Renamed.to.
- 1Install @renamed/sdk and initialize with your API key
- 2Call rename(), pdfSplit(), or extract() with a PDF buffer or file path
- 3Receive AI-generated filenames, split documents, or structured JSON
On this page
Installation
npm install @renamed/sdkQuickstart
Initialize the client and start making API calls.
import { RenamedClient } from '@renamed/sdk'import fs from 'fs'// Initialize the clientconst client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY,})// Rename a PDFconst result = await client.rename(fs.readFileSync('invoice.pdf'))console.log(result.suggestedFilename)// -> "2024-01-15_AcmeCorp_INV-1234.pdf"// Split a multi-page PDFconst splitJob = await client.pdfSplit(fs.readFileSync('documents.pdf'), { mode: 'smart',})console.log(splitJob.documents)// -> [{ filename: "...", downloadUrl: "..." }, ...]// Extract structured dataconst data = await client.extract(fs.readFileSync('receipt.pdf'))console.log(data)// -> { vendor: "...", date: "...", amount: "..." }Rename a PDF
Pass a PDF buffer or file path to get an AI-generated filename. Use custom instructions to control the naming format.
import { RenamedClient } from '@renamed/sdk'import fs from 'fs'const client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY })// Rename from a local fileconst buffer = fs.readFileSync('./documents/invoice.pdf')const result = await client.rename(buffer)console.log(result)// {// suggestedFilename: "2024-01-15_AcmeCorp_INV-1234.pdf",// confidence: 0.95,// metadata: { vendor: "Acme Corp", date: "2024-01-15", type: "invoice" }// }// Use custom naming instructionsconst customResult = await client.rename(buffer, { instructions: 'Format: YYYY-MM-DD_VendorName_Amount',})// -> "2024-01-15_AcmeCorp_$1250.pdf"// Rename from a URLconst urlResult = await client.rename( 'https://example.com/document.pdf')Split a PDF
Split multi-page PDFs into separate documents. The API uses async jobs for large files—poll for completion or use the built-in wait helper.
import { RenamedClient } from '@renamed/sdk'import fs from 'fs'const client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY })const buffer = fs.readFileSync('./documents/combined.pdf')// Smart split: AI detects document boundariesconst job = await client.pdfSplit(buffer, { mode: 'smart' })// Option 1: Wait for completion (built-in polling)const completed = await job.waitForCompletion()console.log(completed.documents)// [// { filename: "invoice_1.pdf", pages: [1, 2], downloadUrl: "..." },// { filename: "invoice_2.pdf", pages: [3, 4], downloadUrl: "..." },// ]// Option 2: Manual polling for progress updateslet status = await client.getJob(job.jobId)while (status.state === 'processing') { console.log(`Progress: ${status.progress}%`) await new Promise(r => setTimeout(r, 1000)) status = await client.getJob(job.jobId)}// Download split documentsfor (const doc of completed.documents) { const pdf = await client.downloadFile(doc.downloadUrl) fs.writeFileSync(`./output/${doc.filename}`, pdf)}Extract Data
Extract structured data from invoices, receipts, and other documents. Use Zod schemas for type-safe extraction.
import { RenamedClient } from '@renamed/sdk'import { z } from 'zod'import fs from 'fs'const client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY })// Basic extraction (returns inferred fields)const buffer = fs.readFileSync('./documents/receipt.pdf')const data = await client.extract(buffer)console.log(data)// { vendor: "Coffee Shop", date: "2024-01-15", total: "$4.50", ... }// Typed extraction with Zod schemaconst InvoiceSchema = z.object({ invoiceNumber: z.string(), vendor: z.string(), date: z.string(), lineItems: z.array(z.object({ description: z.string(), quantity: z.number(), unitPrice: z.number(), })), subtotal: z.number(), tax: z.number(), total: z.number(),})const invoice = await client.extract(buffer, { schema: InvoiceSchema,})// invoice is fully typed as z.infer<typeof InvoiceSchema>console.log(invoice.lineItems[0].description)Framework Integrations
Common integration patterns for popular frameworks.
Next.js Route Handler
Use the SDK in Next.js App Router route handlers to process uploaded PDFs server-side.
// app/api/rename/route.tsimport { NextRequest, NextResponse } from 'next/server'import { RenamedClient } from '@renamed/sdk'const client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY!,})export async function POST(request: NextRequest) { const formData = await request.formData() const file = formData.get('file') as File if (!file) { return NextResponse.json({ error: 'No file provided' }, { status: 400 }) } const buffer = Buffer.from(await file.arrayBuffer()) const result = await client.rename(buffer) return NextResponse.json({ suggestedFilename: result.suggestedFilename, confidence: result.confidence, })}Express.js Middleware
Integrate with Express using multer for file uploads and the SDK for processing.
// server.tsimport express from 'express'import multer from 'multer'import { RenamedClient } from '@renamed/sdk'const app = express()const upload = multer({ storage: multer.memoryStorage() })const client = new RenamedClient({ apiKey: process.env.RENAMED_API_KEY!,})app.post('/api/rename', upload.single('file'), async (req, res) => { if (!req.file) { return res.status(400).json({ error: 'No file provided' }) } try { const result = await client.rename(req.file.buffer) res.json({ suggestedFilename: result.suggestedFilename, confidence: result.confidence, }) } catch (error) { res.status(500).json({ error: 'Processing failed' }) }})app.listen(3000, () => console.log('Server running on :3000'))Error Handling
The SDK throws typed errors that you can catch and handle appropriately.
import { RenamedClient, RenamedError } from '@renamed/sdk'try { const result = await client.rename(buffer)} catch (error) { if (error instanceof RenamedError) { console.error('API Error:', error.code, error.message) // Handle specific error codes if (error.code === 'RATE_LIMITED') { // Wait and retry } } throw error}Full documentation on GitHub
For more examples, advanced usage patterns, and detailed API documentation, see the full TypeScript / Node.js SDK README on GitHub.
Read the TypeScript / Node.js SDK docsFrequently asked questions
- What Node.js versions are supported?
- The TypeScript SDK supports Node.js 18 and above. It uses modern JavaScript features like async/await and ES modules.
- Does the SDK work in the browser?
- The SDK is designed for Node.js server-side use. For browser applications, use the REST API directly or proxy requests through your server.
- How do I handle errors?
- The SDK throws typed errors that you can catch with try/catch. Each error includes a code, message, and optional details for debugging.
- Can I use custom naming formats?
- Yes! Pass instructions to the rename method to control the output format. For example: client.rename(buffer, { instructions: "Format: YYYY-MM-DD_VendorName" }).
- How do I process large PDF files?
- For files over 10MB, use the pdfSplit method which processes asynchronously. The SDK provides a waitForCompletion() helper that handles polling automatically.