> ## Documentation Index
> Fetch the complete documentation index at: https://www.unsiloed.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Classify Document

> Classify PDF and image documents into predefined categories with confidence scoring using job-based processing

## Overview

The Classify Document endpoint analyzes documents and assigns them to predefined categories based on their content, structure, and visual characteristics. This endpoint uses job-based processing where files are uploaded to cloud storage and processed asynchronously.

> [!NOTE]
>
> The endpoint supports both single-page and multi-page classification with detailed confidence scoring for each page. Documents longer than 4 pages are classified from their first 4 pages. Files are uploaded to cloud storage and processed in the background.

## Request

**pdf\_file** `file`

The document to classify: a PDF or an image (JPG, PNG, GIF, WebP, BMP, TIFF). Either `pdf_file` or `file_url` must be provided, but not both. Maximum file size: 500MB.

**file\_url** `string`

URL to a document to classify (PDF or image). Either `pdf_file` or `file_url` must be provided, but not both.

**categories** `string` *required*

JSON string containing an array of category objects with a required name (e.g., `[{"name":"invoice"},{"name":"contract"}]`). A `description` key is accepted for compatibility but is not used by classification; only the names guide the result.

## Response

**job\_id** `string`

Unique identifier for the classification job

**status** `string`

Current status of the job ("processing")

**message** `string`

Human-readable status message

**quota\_remaining** `number`

Remaining API quota after this request

## Examples

```bash cURL theme={null}
curl -X POST "https://prod.visionapi.unsiloed.ai/classify" \
  -H "api-key: your-api-key" \
  -F "pdf_file=@document.pdf" \
  -F 'categories=[{"name":"invoice"},{"name":"contract"},{"name":"receipt"}]'
```

```python Python theme={null}
import requests
import json

url = "https://prod.visionapi.unsiloed.ai/classify"
headers = {"api-key": "your-api-key"}

categories = [
    {"name": "invoice"},
    {"name": "contract"},
    {"name": "receipt"}
]

files = {"pdf_file": ("document.pdf", open("document.pdf", "rb"), "application/pdf")}
data = {"categories": json.dumps(categories)}

response = requests.post(url, headers=headers, files=files, data=data)

if response.status_code == 202:
    result = response.json()
    print(f"Job ID: {result['job_id']}")
    print(f"Status: {result['status']}")
    print(f"Quota Remaining: {result['quota_remaining']}")
else:
    print("Error:", response.status_code, response.text)
```

```javascript JavaScript theme={null}
const formData = new FormData();
formData.append('pdf_file', fileInput.files[0]);

const categories = [
  {name: 'invoice'},
  {name: 'contract'},
  {name: 'receipt'}
];
formData.append('categories', JSON.stringify(categories));

const response = await fetch('https://prod.visionapi.unsiloed.ai/classify', {
  method: 'POST',
  headers: {
    'api-key': 'your-api-key'
  },
  body: formData
});

if (response.status === 202) {
  const result = await response.json();
  console.log('Job ID:', result.job_id);
  console.log('Status:', result.status);
  console.log('Quota Remaining:', result.quota_remaining);
} else {
  console.error('Error:', response.status, await response.text());
}
```

```json 202 - Success theme={null}
{
  "job_id": "7e10f5cd-6d83-4b8e-9f80-ac103fd9b2f1",
  "status": "processing",
  "message": "Classification started",
  "quota_remaining": 450
}
```

```json 400 - Bad Request theme={null}
{
  "detail": "Either pdf_file or file_url must be provided"
}
```

```json 402 - Payment Required theme={null}
{
  "detail": {
    "message": "Insufficient credits. Please contact hello@unsiloed.ai to top up.",
    "quota_data": {
      "remaining": 0,
      "message": "..."
    }
  }
}
```

## Job Status Checking

After starting a classification job, you can check its status using the job ID by making a GET request to `/classify/{job_id}`.

## Job Status Values

* **`queued`**: Job is waiting to be picked up for processing
* **`processing`**: Job is currently being processed
* **`completed`**: Job completed successfully with results available
* **`failed`**: Job failed with error details


## OpenAPI

````yaml api-reference/openapi.json POST /classify
openapi: 3.1.0
info:
  title: Unsiloed AI Document Processing API
  description: >-
    A comprehensive API for document processing, extraction, and analysis using
    AI-powered tools
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://prod.visionapi.unsiloed.ai
    description: Production server
security:
  - apiKeyAuth: []
paths:
  /classify:
    post:
      summary: Classify Document
      description: Classify PDF and image documents into predefined categories
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                pdf_file:
                  type: string
                  format: binary
                  description: >-
                    The document to classify: a PDF or an image (JPG, PNG, GIF,
                    WebP, BMP, TIFF). Provide either pdf_file or file_url, not
                    both. Maximum file size: 500MB.
                file_url:
                  type: string
                  description: >-
                    URL to a document to classify (PDF or image). Provide either
                    pdf_file or file_url, not both.
                categories:
                  type: string
                  description: >-
                    JSON string containing an array of category objects with a
                    required name. Example:
                    [{"name":"invoice"},{"name":"contract"},{"name":"receipt"}].
                    A "description" key is accepted for compatibility but is not
                    used by classification.
              required:
                - categories
      responses:
        '202':
          description: Accepted - classification job started
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                    description: Unique identifier for the classification job
                  status:
                    type: string
                    description: Current job status (typically 'processing')
                  message:
                    type: string
                    description: Status message about the job
                  quota_remaining:
                    type: number
                    description: Remaining API quota after this request
      security:
        - apiKeyAuth: []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.