Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.unsiloed.ai/llms.txt

Use this file to discover all available pages before exploring further.

We’ll walk through classifying a single document end to end. For parsing the document into Markdown or extracting structured fields instead, see the Parse Quickstart or Getting Started With Extract.

Before You Start

  • Get an Unsiloed AI API key by signing up.
  • Have a document to classify (PDF, DOCX, PPTX, JPG, PNG, etc.).
  • Decide on the candidate categories you want the document scored against.
Keep your API key out of source control. The examples below read it from the UNSILOED_API_KEY environment variable.

1. Submit a Document With Categories

The /classify endpoint accepts a multipart upload with two fields: pdf_file (the document) and categories (a JSON list of category objects, each with a name and an optional description). It returns a job_id you can poll for results.
The JavaScript example uses ES modules (top-level await, import). Save it as script.mjs or add "type": "module" to your package.json. You’ll also need Node.js 18 or newer, which exposes fetch, FormData, and Blob as globals.
import os
import json
import requests

API_KEY = os.environ["UNSILOED_API_KEY"]
BASE_URL = "https://prod.visionapi.unsiloed.ai"

categories = [
    {"name": "Medical Record", "description": "Patient medical records and history"},
    {"name": "Lab Report", "description": "Laboratory test results"},
    {"name": "Prescription"},
]

with open("document.pdf", "rb") as f:
    response = requests.post(
        f"{BASE_URL}/classify",
        headers={"api-key": API_KEY},
        files={"pdf_file": ("document.pdf", f, "application/pdf")},
        data={"categories": json.dumps(categories)},
    )
response.raise_for_status()

job_id = response.json()["job_id"]
print(f"Job submitted: {job_id}")

2. Poll for Results

Polling GET /classify/{job_id} returns the job’s current state. A status of completed indicates the result is ready, failed indicates the job errored, and any other value (such as processing) means the job is still running.
import time

while True:
    result = requests.get(
        f"{BASE_URL}/classify/{job_id}",
        headers={"api-key": API_KEY},
    ).json()
    print(f"Status: {result['status']}")
    if result["status"] == "completed":
        break
    if result["status"] == "failed":
        raise RuntimeError(result.get("error", "classify job failed"))
    time.sleep(5)

classification = result["result"]
print(f"Classification: {classification['classification']}")
print(f"Confidence: {classification['confidence']:.2%}")
See the Response Format reference for the full response shape.