For each of these examples, you’ll need:

These environment variables:

  • UNSTRUCTURED_API_KEY - Your Unstructured API key value.
  • UNSTRUCTURED_API_URL - Your Unstructured API URL.

If you do not specify the API URL, the Unstructured Platform Partition Endpoint URL of https://api.unstructuredapp.io/general/v0/general is used by default. You must always specify your Platform Partition Endpoint key.

To specify the API URL in your code if needed:

  • For the Unstructured Python SDK and the Unstructured JavaScript/TypeScript SDK, set the server_url parameter in the UnstructuredClient constructor to the target API URL.
  • For Unstructured Ingest, set partition_endpoint (for Python) or --partition-endpoint (for the CLI) to the target API URL.
  • For the Unstructured open source library, set api_url to the target API URL.

Changing partition strategy for a PDF

Here’s how you can modify partition strategy for a PDF file, and select an alternative model to use with Unstructured API. The hi_res strategy supports different models, and the default is layout_v1.1.0.

If you have a local deployment of the Unstructured API, you can use other supported models, such as yolox.

Specifying the language of a document for better OCR results

For better OCR results, you can specify what languages your document is in using the languages parameter. View the list of available languages.

Saving bounding box coordinates

When elements are extracted from PDFs or images, it may be useful to get their bounding boxes as well. Set the coordinates parameter to true to add this field to the elements in the response.

Returning unique element IDs

By default, the element ID is a SHA-256 hash of the element text. This is to ensure that the ID is deterministic. One downside is that the ID is not guaranteed to be unique. Different elements with the same text will have the same ID, and there could also be hash collisions. To use UUIDs in the output instead, set unique_element_ids=true. Note: this means that the element IDs will be random, so with every partition of the same file, you will get different IDs. This can be helpful if you’d like to use the IDs as a primary key in a database, for example.

Adding the chunking step after partitioning

You can combine partitioning and subsequent chunking in a single request by setting the chunking_strategy parameter. By default, the chunking_strategy is set to None, and no chunking is performed.