{"id":18369596,"url":"https://github.com/unstructured-io/unstructured-js-client","last_synced_at":"2025-10-06T03:11:59.858Z","repository":{"id":196101254,"uuid":"694344465","full_name":"Unstructured-IO/unstructured-js-client","owner":"Unstructured-IO","description":"A JavaScript/Typescript client for the Unstructured Platform API","archived":false,"fork":false,"pushed_at":"2025-10-02T00:30:27.000Z","size":5410,"stargazers_count":57,"open_issues_count":8,"forks_count":17,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-10-02T02:39:28.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Unstructured-IO.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-20T20:10:10.000Z","updated_at":"2025-09-19T04:38:26.000Z","dependencies_parsed_at":"2024-10-02T13:04:13.095Z","dependency_job_id":"5e216c0b-05ec-4534-9c40-14e7a20a4a33","html_url":"https://github.com/Unstructured-IO/unstructured-js-client","commit_stats":{"total_commits":158,"total_committers":14,"mean_commits":"11.285714285714286","dds":0.620253164556962,"last_synced_commit":"ea0d6c46f33d3b11d12f05fcb404095b71d567b4"},"previous_names":["unstructured-io/unstructured-js-client"],"tags_count":60,"template":false,"template_full_name":null,"purl":"pkg:github/Unstructured-IO/unstructured-js-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unstructured-IO%2Funstructured-js-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unstructured-IO%2Funstructured-js-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unstructured-IO%2Funstructured-js-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unstructured-IO%2Funstructured-js-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Unstructured-IO","download_url":"https://codeload.github.com/Unstructured-IO/unstructured-js-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unstructured-IO%2Funstructured-js-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278551857,"owners_count":26005459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T23:29:54.803Z","updated_at":"2025-10-06T03:11:59.852Z","avatar_url":"https://github.com/Unstructured-IO.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e\n  \u003cimg\n    src=\"https://raw.githubusercontent.com/Unstructured-IO/unstructured/main/img/unstructured_logo.png\"\n    height=\"200\"\n  \u003e\n\u003c/h3\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://speakeasyapi.dev/\"\u003e\u003cimg src=\"https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge\u0026logoColor=FBE331\u0026logo=speakeasy\u0026labelColor=545454\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003e\n  \u003cp\u003eTypeScript SDK for the Unstructured API\u003c/p\u003e\n\u003c/h2\u003e\n\nThis is a HTTP client for the [Unstructured Platform API](https://docs.unstructured.io/platform-api/overview). You can sign up [here](https://unstructured.io/developers) and process 1000 free pages per day for 14 days.\n\nPlease refer to the our documentation for a full guide on integrating the [Partition Endpoint](https://docs.unstructured.io/platform-api/partition-api/sdk-jsts) into your JavaScript/TypeScript code. Support for the [Workflow Endpoint](https://docs.unstructured.io/platform-api/api/overview) is coming soon. \n\n\n## SDK Installation\n\n### NPM\n\n```bash\nnpm install unstructured-client --include=dev\n```\n\n### Yarn\n\n```bash\nyarn add unstructured-client --dev\n```\n\n### Model Context Protocol (MCP) Server\n\nThis SDK is also an installable MCP server where the various SDK methods are\nexposed as tools that can be invoked by AI applications.\n\n\u003e Node.js v20 or greater is required to run the MCP server.\n\n\u003cdetails\u003e\n\u003csummary\u003eClaude installation steps\u003c/summary\u003e\n\nAdd the following server definition to your `claude_desktop_config.json` file:\n\n```json\n{\n  \"mcpServers\": {\n    \"Unstructured\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"-y\", \"--package\", \"unstructured-client\",\n        \"--\",\n        \"mcp\", \"start\",\n      ]\n    }\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCursor installation steps\u003c/summary\u003e\n\nGo to `Cursor Settings \u003e Features \u003e MCP Servers \u003e Add new MCP server` and use the following settings:\n\n- Name: Unstructured\n- Type: `command`\n- Command:\n```sh\nnpx -y --package unstructured-client -- mcp start\n```\n\n\u003c/details\u003e\n\nFor a full list of server arguments, run:\n\n```sh\nnpx -y --package unstructured-client -- mcp start --help\n```\n\n\u003c!-- No SDK Installation --\u003e\n\n## SDK Example Usage\n\n### Example\n\n```typescript\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { PartitionResponse } from \"unstructured-client/sdk/models/operations\";\nimport { Strategy } from \"unstructured-client/sdk/models/shared\";\nimport * as fs from \"fs\";\n\nconst unstructuredClient = new UnstructuredClient({\n    security: {\n        apiKeyAuth: \"YOUR_API_KEY\",\n    },\n});\n\nconst filename = \"./sample-file\";\nconst data = fs.readFileSync(filename);\n\nunstructuredClient.general.partition({\n    partitionParameters: {\n        files: {\n            content: data,\n            fileName: filename,\n        },\n\tstrategy: Strategy.Auto,\n    }\n}).then((res: PartitionResponse) =\u003e {\n    if (res.statusCode == 200) {\n        console.log(res.elements);\n    }\n}).catch((e) =\u003e {\n    console.log(e.statusCode);\n    console.log(e.body);\n});\n\n```\n\u003c!-- No SDK Example Usage [usage] --\u003e\n\nRefer to the [API parameters page](https://docs.unstructured.io/api-reference/api-services/api-parameters) for all available parameters.\n\n## Change the base URL\n\nIf you are self hosting the API, or developing locally, you can change the server URL when setting up the client.\n\n```typescript\nconst client = new UnstructuredClient({\n    serverURL: \"http://localhost:8000\",\n    security: {\n        apiKeyAuth: key,\n    },\n});\n\n// OR\n\nconst client = new UnstructuredClient({\n    serverURL: \"https://my-server-url\",\n    security: {\n        apiKeyAuth: key,\n    },\n});\n```\n\n\n\u003c!-- Start Custom HTTP Client [http-client] --\u003e\n## Custom HTTP Client\n\nThe TypeScript SDK makes API calls using an `HTTPClient` that wraps the native\n[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This\nclient is a thin wrapper around `fetch` and provides the ability to attach hooks\naround the request lifecycle that can be used to modify the request or handle\nerrors and response.\n\nThe `HTTPClient` constructor takes an optional `fetcher` argument that can be\nused to integrate a third-party HTTP client or when writing tests to mock out\nthe HTTP client and feed in fixtures.\n\nThe following example shows how to use the `\"beforeRequest\"` hook to to add a\ncustom header and a timeout to requests and how to use the `\"requestError\"` hook\nto log errors:\n\n```typescript\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { HTTPClient } from \"unstructured-client/lib/http\";\n\nconst httpClient = new HTTPClient({\n  // fetcher takes a function that has the same signature as native `fetch`.\n  fetcher: (request) =\u003e {\n    return fetch(request);\n  }\n});\n\nhttpClient.addHook(\"beforeRequest\", (request) =\u003e {\n  const nextRequest = new Request(request, {\n    signal: request.signal || AbortSignal.timeout(5000)\n  });\n\n  nextRequest.headers.set(\"x-custom-header\", \"custom value\");\n\n  return nextRequest;\n});\n\nhttpClient.addHook(\"requestError\", (error, request) =\u003e {\n  console.group(\"Request Error\");\n  console.log(\"Reason:\", `${error}`);\n  console.log(\"Endpoint:\", `${request.method} ${request.url}`);\n  console.groupEnd();\n});\n\nconst sdk = new UnstructuredClient({ httpClient: httpClient });\n```\n\u003c!-- End Custom HTTP Client [http-client] --\u003e\n\n\u003c!-- Start Retries [retries] --\u003e\n## Retries\n\nSome of the endpoints in this SDK support retries.  If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API.  However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.\n\nTo change the default retry strategy for a single API call, simply provide a retryConfig object to the call:\n```typescript\nimport { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport {\n  Strategy,\n  VLMModel,\n  VLMModelProvider,\n} from \"unstructured-client/sdk/models/shared\";\n\nconst unstructuredClient = new UnstructuredClient();\n\nasync function run() {\n  const result = await unstructuredClient.general.partition({\n    partitionParameters: {\n      chunkingStrategy: \"by_title\",\n      files: await openAsBlob(\"example.file\"),\n      splitPdfPageRange: [\n        1,\n        10,\n      ],\n      strategy: Strategy.Auto,\n      vlmModel: VLMModel.Gpt4o,\n      vlmModelProvider: VLMModelProvider.Openai,\n    },\n  }, {\n    retries: {\n      strategy: \"backoff\",\n      backoff: {\n        initialInterval: 1,\n        maxInterval: 50,\n        exponent: 1.1,\n        maxElapsedTime: 100,\n      },\n      retryConnectionErrors: false,\n    },\n  });\n\n  console.log(result);\n}\n\nrun();\n\n```\n\nIf you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:\n```typescript\nimport { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport {\n  Strategy,\n  VLMModel,\n  VLMModelProvider,\n} from \"unstructured-client/sdk/models/shared\";\n\nconst unstructuredClient = new UnstructuredClient({\n  retryConfig: {\n    strategy: \"backoff\",\n    backoff: {\n      initialInterval: 1,\n      maxInterval: 50,\n      exponent: 1.1,\n      maxElapsedTime: 100,\n    },\n    retryConnectionErrors: false,\n  },\n});\n\nasync function run() {\n  const result = await unstructuredClient.general.partition({\n    partitionParameters: {\n      chunkingStrategy: \"by_title\",\n      files: await openAsBlob(\"example.file\"),\n      splitPdfPageRange: [\n        1,\n        10,\n      ],\n      strategy: Strategy.Auto,\n      vlmModel: VLMModel.Gpt4o,\n      vlmModelProvider: VLMModelProvider.Openai,\n    },\n  });\n\n  console.log(result);\n}\n\nrun();\n\n```\n\u003c!-- End Retries [retries] --\u003e\n\n### Splitting PDF by pages\n\nSee [page splitting](https://docs.unstructured.io/api-reference/api-services/sdk#page-splitting) for more details.\n\nIn order to speed up processing of large PDF files, the client splits up PDFs into smaller files, sends these to the API concurrently, and recombines the results. `splitPdfPage` can be set to `false` to disable this.\n\nThe amount of parallel requests is controlled by `splitPdfConcurrencyLevel` parameter. By default it equals to 5. It can't be more than 15, to avoid too high resource usage and costs. The size of each batch is determined internally and it can vary between 2 and 20 pages per split.\n\n```typescript\nclient.general.partition({\n    partitionParameters: {\n        files: {\n            content: data,\n            fileName: filename,\n        },\n        // Set splitPdfPage parameter to false in order to disable splitting PDF\n        splitPdfPage: true,\n        // Modify splitPdfConcurrencyLevel to change the limit of parallel requests\n        splitPdfConcurrencyLevel: 10,\n    },\n}};\n```\n\n\u003c!-- Start Summary [summary] --\u003e\n## Summary\n\n\n\u003c!-- End Summary [summary] --\u003e\n\n\u003c!-- Start Table of Contents [toc] --\u003e\n## Table of Contents\n\u003c!-- $toc-max-depth=2 --\u003e\n  * [SDK Installation](#sdk-installation)\n  * [SDK Example Usage](#sdk-example-usage)\n  * [Change the base URL](#change-the-base-url)\n  * [Custom HTTP Client](#custom-http-client)\n  * [Retries](#retries)\n  * [Requirements](#requirements)\n  * [Standalone functions](#standalone-functions)\n  * [File uploads](#file-uploads)\n  * [Debugging](#debugging)\n\n\u003c!-- End Table of Contents [toc] --\u003e\n\n\u003c!-- Start Requirements [requirements] --\u003e\n## Requirements\n\nFor supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).\n\u003c!-- End Requirements [requirements] --\u003e\n\n\u003c!-- Start Standalone functions [standalone-funcs] --\u003e\n## Standalone functions\n\nAll the methods listed above are available as standalone functions. These\nfunctions are ideal for use in applications running in the browser, serverless\nruntimes or other environments where application bundle size is a primary\nconcern. When using a bundler to build your application, all unused\nfunctionality will be either excluded from the final bundle or tree-shaken away.\n\nTo read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAvailable standalone functions\u003c/summary\u003e\n\n- [`generalPartition`](docs/sdks/general/README.md#partition) - Summary\n\n\u003c/details\u003e\n\u003c!-- End Standalone functions [standalone-funcs] --\u003e\n\n\u003c!-- Start File uploads [file-upload] --\u003e\n## File uploads\n\nCertain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.\n\n\u003e [!TIP]\n\u003e\n\u003e Depending on your JavaScript runtime, there are convenient utilities that return a handle to a file without reading the entire contents into memory:\n\u003e\n\u003e - **Node.js v20+:** Since v20, Node.js comes with a native `openAsBlob` function in [`node:fs`](https://nodejs.org/docs/latest-v20.x/api/fs.html#fsopenasblobpath-options).\n\u003e - **Bun:** The native [`Bun.file`](https://bun.sh/docs/api/file-io#reading-files-bun-file) function produces a file handle that can be used for streaming file uploads.\n\u003e - **Browsers:** All supported browsers return an instance to a [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) when reading the value from an `\u003cinput type=\"file\"\u003e` element.\n\u003e - **Node.js v18:** A file stream can be created using the `fileFrom` helper from [`fetch-blob/from.js`](https://www.npmjs.com/package/fetch-blob).\n\n```typescript\nimport { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport {\n  Strategy,\n  VLMModel,\n  VLMModelProvider,\n} from \"unstructured-client/sdk/models/shared\";\n\nconst unstructuredClient = new UnstructuredClient();\n\nasync function run() {\n  const result = await unstructuredClient.general.partition({\n    partitionParameters: {\n      chunkingStrategy: \"by_title\",\n      files: await openAsBlob(\"example.file\"),\n      splitPdfPageRange: [\n        1,\n        10,\n      ],\n      strategy: Strategy.Auto,\n      vlmModel: VLMModel.Gpt4o,\n      vlmModelProvider: VLMModelProvider.Openai,\n    },\n  });\n\n  console.log(result);\n}\n\nrun();\n\n```\n\u003c!-- End File uploads [file-upload] --\u003e\n\n\u003c!-- No Authentication --\u003e\n\u003c!-- No SDK Available Operations --\u003e\n\u003c!-- No Pagination --\u003e\n\u003c!-- No Error Handling --\u003e\n\u003c!-- No Server Selection --\u003e\n\n\u003c!-- Start Debugging [debug] --\u003e\n## Debugging\n\nYou can setup your SDK to emit debug logs for SDK requests and responses.\n\nYou can pass a logger that matches `console`'s interface as an SDK option.\n\n\u003e [!WARNING]\n\u003e Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.\n\n```typescript\nimport { UnstructuredClient } from \"unstructured-client\";\n\nconst sdk = new UnstructuredClient({ debugLogger: console });\n```\n\u003c!-- End Debugging [debug] --\u003e\n\n\u003c!-- Placeholder for Future Speakeasy SDK Sections --\u003e\n\n### Maturity\n\nThis SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage\nto a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally\nlooking for the latest version.\n\n### Contributions\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically.\nFeel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!\n\n### SDK Created by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funstructured-io%2Funstructured-js-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funstructured-io%2Funstructured-js-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funstructured-io%2Funstructured-js-client/lists"}