> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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.
</Note>

## Request

<ParamField body="pdf_file" type="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.
</ParamField>

<ParamField body="file_url" type="string">
  URL to a document to classify (PDF or image). Either `pdf_file` or `file_url` must be provided, but not both.
</ParamField>

<ParamField body="categories" type="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.
</ParamField>

## Response

<ResponseField name="job_id" type="string">
  Unique identifier for the classification job
</ResponseField>

<ResponseField name="status" type="string">
  Current status of the job ("processing")
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message
</ResponseField>

<ResponseField name="quota_remaining" type="number">
  Remaining API quota after this request
</ResponseField>

## Examples

<RequestExample>
  ```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());
  }
  ```
</RequestExample>

<ResponseExample>
  ```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": "..."
      }
    }
  }
  ```
</ResponseExample>

## 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

````