Use the TypeScript SDK when your Node.js application needs typed access to Iteration Layer APIs without hand-writing HTTP requests, authorization headers, or base64 conversion for binary fields.
Key Features
- Full API Coverage — Call document extraction, document to markdown, website extraction, image transformation, image generation, document generation, and sheet generation from one client.
- Typed Requests and Responses — Import request and response types from the package instead of maintaining local API shapes.
-
Native Binary Inputs — Pass inline file bytes as
Uint8Array; the SDK serializes them to the API wire format. -
Native Binary Outputs — Receive generated documents, images, and sheets as
Uint8Arrayplusmime_type. -
Async Variants — Every long-running API has an async method that accepts
webhook_urland returns immediately after the job is accepted. -
Structured API Errors — Failed API responses throw
IterationLayerErrorwithstatusCodeanderrorMessage.
Installation
Install the SDK from npm in the Node.js project that sends API requests to Iteration Layer.
npm install iterationlayerClient Setup
Create one client with your API key. The SDK sends requests to https://api.iterationlayer.com and adds the required bearer token automatically.
import { IterationLayer } from "iterationlayer";
const client = new IterationLayer({
apiKey: "YOUR_API_KEY",
});First Request
The SDK request shape matches the HTTP API shape, with native JavaScript byte types for binary fields. This example extracts the vendor name and invoice total from a remote PDF.
const result = await client.extractDocument({
files: [
{
type: "url",
name: "invoice.pdf",
url: "https://example.com/invoice.pdf",
},
],
schema: {
fields: [
{
type: "TEXT",
name: "vendor",
description: "Vendor name",
},
{
type: "CURRENCY_AMOUNT",
name: "total",
description: "Total amount",
},
],
},
});API Methods
Each API has a sync method and an async method. Async methods append Async, require webhook_url, and return an acceptance result instead of the final payload.
| API | Sync method | Async method |
|---|---|---|
| Document Extraction |
extractDocument |
extractDocumentAsync |
| Document to Markdown |
convertDocumentToMarkdown |
convertDocumentToMarkdownAsync |
| Website Extraction |
extractWebsite |
extractWebsiteAsync |
| Image Transformation |
transformImage |
transformImageAsync |
| Image Generation |
generateImage |
generateImageAsync |
| Document Generation |
generateDocument |
generateDocumentAsync |
| Sheet Generation |
generateSheet |
generateSheetAsync |
Binary Files
Inline file inputs use Uint8Array in TypeScript. Binary API outputs return { buffer: Uint8Array, mime_type: string }, so application code can write the buffer directly to storage, an HTTP response, or another processing step.
Error Handling
API validation errors, authentication failures, rate limits, and server errors throw IterationLayerError. Network-level failures from fetch are not wrapped.
import { IterationLayer, IterationLayerError } from "iterationlayer";
const client = new IterationLayer({
apiKey: "YOUR_API_KEY",
});
try {
const result = await client.extractDocument({ /* ... */ });
} catch (error) {
if (error instanceof IterationLayerError) {
console.log(error.statusCode);
console.log(error.errorMessage);
}
}Async Webhooks
Use async methods when processing should continue after your application request has returned. Iteration Layer validates and accepts the job, then sends the final result to your webhook endpoint.
const result = await client.extractDocumentAsync({
files: [
{
type: "url",
name: "doc.pdf",
url: "https://example.com/doc.pdf",
},
],
schema: {
fields: [
{
type: "TEXT",
name: "title",
description: "Document title",
},
],
},
webhook_url: "https://your-app.com/webhooks/extraction",
});