The JavaScript SDK allows for easy interaction with the Unstructured API using JavaScript. Whether you’re using the free Unstructured API, the SaaS Unstructured API, Unstructured API on Azure/AWS or your local deployment of Unstructured API, you can access the API using the JavaScript SDK.

Installation

Before using the JavaScript SDK to interact with your Unstructured API, install the SDK using npm:
npm install unstructured-client

Basics

Let’s start with a simple example in which you send a pdf document to partition via Unstructured API using the JavaScript SDK:
import { UnstructuredClient } from "unstructured-client";
import { PartitionResponse } from "unstructured-client/dist/sdk/models/operations";
import * as fs from "fs";

const key = "YOUR_API_KEY";

const client = new UnstructuredClient({
    // you may need to provide your unique API URL
    // serverURL: "YOUR_API_URL",
    security: {
        apiKeyAuth: key,
    },
});

const filename = "sample-docs/layout-parser-paper.pdf";
const data = fs.readFileSync(filename);

client.general.partition({
    // Note that this currently only supports a single file
    files: {
        content: data,
        fileName: filename,
    },
    // Other partition params
    strategy: "fast",
}).then((res: PartitionResponse) => {
    if (res.statusCode == 200) {
        console.log(res.elements);
    }
}).catch((e) => {
    console.log(e.statusCode);
    console.log(e.body);
});
In the example above we’re sending the request to the free Unstructured API, in which case the API URL is the same for all users, and you don’t need to provide it. Note, however, that you still need to authenticate yourself with your individual API Key. If you want to use the SaaS Unstructured API, you need to replace the URL in this example with the unique API URL that you have received in the same email as your API key. For Unstructured API on Azure/AWS, use the API URL that you configured through those services.

Parameters & examples

The API parameters are the same across all methods of accessing the Unstructured API.
  • Refer to the API parameters page for the full list of available parameters.
  • Refer to the Examples page for some inspiration on using the parameters.