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

# Synchronous Classification

> Classify a document into predefined categories synchronously.

**Modes:**
- `document` — Returns a single best-fit category for the whole document with confidence and reasoning.
- `split` — Classifies each page individually and groups pages by category. A page can appear in multiple categories (multi-label).

Provide categories inline via `classification_config` or reference a saved classify config via `config_id`.

> **Tip:** You can save and reuse classification settings (categories & mode) by creating a config via [Create Config](/docs/api-reference-v2/configuration-management/create-config). Pass the returned `config_id` instead of repeating `classification_config` each time.



## OpenAPI

````yaml /openapi-extraction-v2.json post /api/v2/classify/sync
openapi: 3.1.0
info:
  title: Nanonets V2 API
  description: >-
    Stateful document processing API with file management, reusable configs, and
    JSON-body endpoints for parse, extract, and classify operations.


    **Key differences from V1:**

    - JSON request bodies instead of multipart/form-data

    - Upload files once via `POST /files`, then reference them with
    `file://<uuid>` URIs

    - Save and reuse processing configurations via `config://<uuid>` URIs

    - Batch processing via list inputs on async endpoints (up to 50 items)

    - Document classification with `document` and `split` modes
  version: 2.0.0
  contact:
    name: Nanonets Support
    email: info@nanonets.com
servers:
  - url: https://extraction-api.nanonets.com
    description: Production
security:
  - BearerAuth: []
paths:
  /api/v2/classify/sync:
    post:
      tags:
        - Document Classification
      summary: Synchronous Classification
      description: >-
        Classify a document into predefined categories synchronously.


        **Modes:**

        - `document` — Returns a single best-fit category for the whole document
        with confidence and reasoning.

        - `split` — Classifies each page individually and groups pages by
        category. A page can appear in multiple categories (multi-label).


        Provide categories inline via `classification_config` or reference a
        saved classify config via `config_id`.


        > **Tip:** You can save and reuse classification settings (categories &
        mode) by creating a config via [Create
        Config](/docs/api-reference-v2/configuration-management/create-config).
        Pass the returned `config_id` instead of repeating
        `classification_config` each time.
      operationId: v2_classify_sync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClassifyRequest'
            examples:
              document_mode:
                summary: Document mode — single category
                value:
                  input: file://a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  classification_config:
                    categories:
                      - name: Invoice
                        description: Bills and invoices
                      - name: Receipt
                        description: Payment receipts
                      - name: Contract
                        description: Legal agreements
                    mode: document
              split_mode:
                summary: Split mode — page-level grouping
                value:
                  input: https://example.com/multi-doc.pdf
                  classification_config:
                    categories:
                      - name: Invoice
                      - name: Receipt
                      - name: Contract
                    mode: split
              with_saved_config:
                summary: Using saved classify config
                value:
                  input: file://a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  config_id: config://d4e5f6a7-b8c9-0123-defa-b12345678901
      responses:
        '200':
          description: Classification completed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClassifyResponse'
              examples:
                document_result:
                  summary: Document mode result
                  value:
                    success: true
                    message: Document classified successfully
                    status: completed
                    result:
                      filename: invoice.pdf
                      total_pages: 3
                      mode: document
                      document_category: Invoice
                      confidence: 92.5
                      reasoning: >-
                        Page 1: Contains invoice header with vendor details;
                        Page 2: Itemized list of products with pricing
                    processing_time: 1.5
                    filename: invoice.pdf
                split_result:
                  summary: Split mode result
                  value:
                    success: true
                    message: Document split successfully
                    status: completed
                    result:
                      filename: multi-doc.pdf
                      total_pages: 5
                      mode: split
                      splits:
                        - category: Invoice
                          pages:
                            - 1
                            - 2
                          confidence: 95
                          reasoning: 'Page 1: Invoice header; Page 2: Itemized charges'
                        - category: Receipt
                          pages:
                            - 2
                            - 3
                          confidence: 88
                          reasoning: >-
                            Page 2: Payment confirmation; Page 3: Receipt with
                            payment details
                        - category: Contract
                          pages:
                            - 4
                            - 5
                          confidence: 91.5
                          reasoning: >-
                            Page 4: Agreement header with parties; Page 5:
                            Signature block
                    processing_time: 3.2
                    filename: multi-doc.pdf
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  schemas:
    ClassifyRequest:
      type: object
      required:
        - input
      properties:
        input:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
              maxItems: 50
          description: '`file://<uuid>` URI or public URL. Async accepts a list (max 50).'
        config_id:
          type: string
          description: '`config://<uuid>` of a saved classify config'
        classification_config:
          $ref: '#/components/schemas/ClassifyConfig'
    ClassifyResponse:
      type: object
      required:
        - success
        - message
      properties:
        success:
          type: boolean
        message:
          type: string
        record_id:
          type: string
        file_id:
          type: string
        config_id:
          type: string
        status:
          type: string
          enum:
            - completed
            - processing
            - failed
        result:
          oneOf:
            - $ref: '#/components/schemas/ClassifyDocumentResult'
            - $ref: '#/components/schemas/ClassifySplitResult'
          description: Classification result (shape depends on mode)
        processing_time:
          type: number
          description: Time in seconds
        filename:
          type: string
        file_size:
          type: integer
          description: Size in bytes
    ClassifyConfig:
      type: object
      required:
        - categories
      properties:
        categories:
          type: array
          items:
            $ref: '#/components/schemas/ClassifyCategory'
          minItems: 1
          maxItems: 50
          description: List of categories (max 50, names must be unique)
        mode:
          type: string
          enum:
            - document
            - split
          default: document
          description: >-
            `document`: single best-fit category for the whole file. `split`:
            page-level grouping by category.
    ClassifyDocumentResult:
      type: object
      required:
        - filename
        - total_pages
        - mode
        - document_category
        - confidence
        - reasoning
      properties:
        filename:
          type: string
        total_pages:
          type: integer
        mode:
          type: string
          enum:
            - document
        document_category:
          type: string
          description: Best-fit category for the document
        confidence:
          type: number
          minimum: 0
          maximum: 100
        reasoning:
          type: string
          description: Per-page reasoning aggregated
    ClassifySplitResult:
      type: object
      required:
        - filename
        - total_pages
        - mode
        - splits
      properties:
        filename:
          type: string
        total_pages:
          type: integer
        mode:
          type: string
          enum:
            - split
        splits:
          type: array
          items:
            $ref: '#/components/schemas/ClassifySplitEntry'
          description: Page groupings by category. A page can appear in multiple splits.
    ErrorResponse:
      type: object
      properties:
        detail:
          type: string
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
    ClassifyCategory:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 200
          description: Category name
        description:
          type: string
          maxLength: 1000
          description: Optional description to help with classification
    ClassifySplitEntry:
      type: object
      required:
        - category
        - pages
        - confidence
        - reasoning
      properties:
        category:
          type: string
        pages:
          type: array
          items:
            type: integer
            minimum: 1
          description: 1-indexed page numbers belonging to this category
        confidence:
          type: number
          minimum: 0
          maximum: 100
          description: Average confidence score (0-100)
        reasoning:
          type: string
    ValidationError:
      type: object
      required:
        - loc
        - msg
        - type
      properties:
        loc:
          type: array
          items:
            oneOf:
              - type: string
              - type: integer
        msg:
          type: string
        type:
          type: string
  responses:
    BadRequest:
      description: Invalid input
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HTTPValidationError'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 'API key as Bearer token: `Authorization: Bearer YOUR_API_KEY`'

````