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

# Create Document Handler

> Create a new document with initial v0 version.

The document is created as a child of the specified parent folder.
An initial version (v0) is automatically created.



## OpenAPI

````yaml /openapi.yaml post /v1/documents
openapi: 3.1.0
info:
  title: Knowledge Stack API
  description: Knowledge Stack backend API for authentication and knowledge management
  version: 0.1.0
servers:
  - url: http://localhost:8000
    description: Knowledge Stack API local dev server
security: []
tags:
  - name: auth
    description: Authentication and identity management
  - name: users
    description: User accounts
  - name: tenants
    description: Tenant management
  - name: invites
    description: Tenant invitations
  - name: folders
    description: Folder management
  - name: documents
    description: Document management
  - name: document-versions
    description: Document version management
  - name: sections
    description: Document sections
  - name: chunks
    description: Chunk CRUD and semantic search
  - name: chunk-lineages
    description: Chunk lineage tracking
  - name: tags
    description: Tag management
  - name: path-parts
    description: Path part traversal and tagging
  - name: Threads
    description: Thread conversations
  - name: Thread Messages
    description: Thread message management
  - name: user-permissions
    description: User path permissions
  - name: workflows
    description: Ingestion workflows
paths:
  /v1/documents:
    post:
      tags:
        - documents
      summary: Create Document Handler
      description: |-
        Create a new document with initial v0 version.

        The document is created as a child of the specified parent folder.
        An initial version (v0) is automatically created.
      operationId: create_document
      parameters:
        - name: authorization
          in: header
          required: false
          schema:
            type: string
            nullable: true
            title: Authorization
        - name: ks_uat
          in: cookie
          required: false
          schema:
            type: string
            nullable: true
            title: Ks Uat
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDocumentRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CreateDocumentRequest:
      properties:
        name:
          type: string
          maxLength: 255
          minLength: 1
          title: Name
          description: Document name
        parent_path_part_id:
          type: string
          format: uuid
          title: Parent Path Part Id
          description: Parent PathPart ID (must be a FOLDER type)
        document_type:
          $ref: '#/components/schemas/DocumentType'
          description: Type of document (PDF, UNKNOWN, etc.)
        document_origin:
          $ref: '#/components/schemas/DocumentOrigin'
          description: Origin of document (SOURCE, GENERATED)
      additionalProperties: false
      type: object
      required:
        - name
        - parent_path_part_id
        - document_type
        - document_origin
      title: CreateDocumentRequest
      description: Request to create a new document.
    DocumentResponse:
      properties:
        part_type:
          type: string
          title: Part Type
          description: Path part type
          enum:
            - DOCUMENT
        id:
          type: string
          format: uuid
          title: Id
          description: Document ID
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        name:
          type: string
          title: Name
          description: Document name
        parent_path_part_id:
          type: string
          format: uuid
          nullable: true
          title: Parent Path Part Id
          description: Parent PathPart ID
        document_type:
          $ref: '#/components/schemas/DocumentType'
          description: Type of document
        document_origin:
          $ref: '#/components/schemas/DocumentOrigin'
          description: Origin of document
        active_version_id:
          type: string
          format: uuid
          title: Active Version Id
          description: Active version ID
        active_version:
          $ref: '#/components/schemas/DocumentVersionResponse'
          description: Active version details
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this document is system-managed
        tenant_id:
          type: string
          format: uuid
          title: Tenant Id
          description: Tenant ID
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          title: Updated At
          description: Last update timestamp
        tags:
          items:
            $ref: '#/components/schemas/TagResponse'
          type: array
          nullable: true
          title: Tags
          description: Tags attached to this document
      additionalProperties: false
      type: object
      required:
        - part_type
        - id
        - path_part_id
        - name
        - parent_path_part_id
        - document_type
        - document_origin
        - active_version_id
        - active_version
        - materialized_path
        - system_managed
        - tenant_id
        - created_at
        - updated_at
      title: DocumentResponse
      description: Document response model.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DocumentType:
      type: string
      enum:
        - PDF
        - DOCX
        - PLAINTEXT
        - IMAGE
        - XLSX
        - CSV
        - PPTX
        - UNKNOWN
      title: DocumentType
      description: Type of document.
    DocumentOrigin:
      type: string
      enum:
        - SOURCE
        - GENERATED
      title: DocumentOrigin
      description: Origin of document - source/purpose (all origins are first-class).
    DocumentVersionResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: DocumentVersion ID
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        version:
          type: integer
          title: Version
          description: Version number (0, 1, 2...)
        name:
          type: string
          title: Name
          description: Auto-generated name from path_part (v0, v1, ...)
        parent_path_id:
          type: string
          format: uuid
          nullable: true
          title: Parent Path Id
          description: Document's PathPart ID
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this version is system-managed
        tenant_id:
          type: string
          format: uuid
          title: Tenant Id
          description: Tenant ID
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          title: Updated At
          description: Last update timestamp
        asset_s3_url:
          type: string
          nullable: true
          title: Asset S3 Url
          description: Presigned URL to download the source document (6-hour validity)
        fast_plaintext_url:
          type: string
          nullable: true
          title: Fast Plaintext Url
          description: >-
            Presigned URL to download the fast plaintext export (6-hour
            validity)
        system_metadata:
          $ref: '#/components/schemas/DocumentVersionMetadata'
          description: Version metadata (S3 artifacts, pipeline state, statistics)
      additionalProperties: false
      type: object
      required:
        - id
        - path_part_id
        - version
        - name
        - parent_path_id
        - materialized_path
        - system_managed
        - tenant_id
        - created_at
        - updated_at
      title: DocumentVersionResponse
      description: |-
        DocumentVersion response model.

        Shared schema for DocumentVersion responses, used by Document endpoints
        and DocumentVersion endpoints.
    TagResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: Tag ID
        name:
          type: string
          title: Name
          description: Tag name
        color:
          type: string
          title: Color
          description: Tag color hex
        description:
          type: string
          nullable: true
          title: Description
          description: Tag description
        tenant_id:
          type: string
          format: uuid
          title: Tenant Id
          description: Tenant ID
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          title: Updated At
          description: Last update timestamp
      additionalProperties: false
      type: object
      required:
        - id
        - name
        - color
        - tenant_id
        - created_at
        - updated_at
      title: TagResponse
      description: Tag response model.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    DocumentVersionMetadata:
      properties:
        source_s3:
          type: string
          nullable: true
          title: Source S3
          description: S3 URL to the source document (set by API on upload)
        cleaned_source_s3:
          type: string
          nullable: true
          title: Cleaned Source S3
          description: S3 URL to watermark-removed source document
        fast_plaintext_s3:
          type: string
          nullable: true
          title: Fast Plaintext S3
          description: S3 URL to the fast plaintext export of the document
        hash:
          type: string
          nullable: true
          title: Hash
          description: Base64-encoded SHA256 hash of the uploaded source file
        pipeline_state:
          $ref: '#/components/schemas/PipelineState'
          nullable: true
          description: Current state of the ingestion pipeline workflow
        total_pages:
          type: integer
          nullable: true
          title: Total Pages
          description: Total number of pages in the document
        total_sections:
          type: integer
          nullable: true
          title: Total Sections
          description: Total number of sections created
        total_chunks:
          type: integer
          nullable: true
          title: Total Chunks
          description: Total number of chunks created
        total_formulas:
          type: integer
          nullable: true
          title: Total Formulas
          description: Total formula cells in the workbook (XLSX only)
        xlsx_parse_result_s3:
          type: string
          nullable: true
          title: Xlsx Parse Result S3
          description: >-
            S3 URI to the full XLSX parse result JSON containing dependency
            graph, named ranges, and KPI catalog
        xlsx_named_ranges:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Xlsx Named Ranges
          description: Named ranges defined in the workbook (name, ref_string, scope)
        xlsx_kpi_catalog:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Xlsx Kpi Catalog
          description: >-
            KPI (Key Performance Indicator) cells detected by the XLSX parser.
            Each entry contains a label, computed value, cell address, and
            driver cell references. Applicable to financial models and
            operational spreadsheets; not populated for template spreadsheets
            that lack computed KPI cells.
        information_statistics:
          $ref: '#/components/schemas/InformationStatistics'
          nullable: true
          description: >-
            Aggregate statistics for the document version (tokens, chunk counts,
            depth)
      type: object
      title: DocumentVersionMetadata
      description: >-
        Schema for document_version.system_metadata JSONB field.


        Tracks S3 URLs for generated artifacts, pipeline execution state,

        and document statistics. Convention-based paths (images, page
        screenshots)

        are derived from document_id/document_version_id via s3_paths helpers,

        using a flat S3 layout:
        documents/{document_id}/{document_version_id}/...


        Internal conversion artifact paths (standard_pipeline_json_s3,
        high_accuracy_*_s3) are

        excluded from API responses via ``Field(exclude=True)`` so we don't

        expose underlying technology names to external consumers.
    PipelineState:
      properties:
        status:
          $ref: '#/components/schemas/PipelineStatus'
          description: Current status of the ingestion pipeline
        last_run_timestamp:
          type: string
          format: date-time
          nullable: true
          title: Last Run Timestamp
          description: >-
            Timestamp of the last pipeline execution attempt (set once when a
            run starts)
        last_state_update_timestamp:
          type: string
          format: date-time
          nullable: true
          title: Last State Update Timestamp
          description: Timestamp of the last pipeline state change (set by activities)
        last_activity:
          type: string
          nullable: true
          title: Last Activity
          description: >-
            Name of the last activity that executed (e.g.,
            'document_preparation')
        error:
          type: string
          nullable: true
          title: Error
          description: Error message if pipeline failed
        temporal_workflow_id:
          type: string
          nullable: true
          title: Temporal Workflow Id
          description: Temporal workflow ID for tracking the ingestion run
        chunks_processed:
          type: integer
          nullable: true
          title: Chunks Processed
          description: Number of chunks processed (for progress tracking)
        page_dpi:
          type: integer
          nullable: true
          title: Page Dpi
          description: DPI used for PDF page screenshots during ingestion
        ingestion_mode:
          $ref: '#/components/schemas/IngestionMode'
          nullable: true
          description: Ingestion mode used (standard, high_accuracy, or single_chunk)
        chunk_type:
          $ref: '#/components/schemas/ChunkType'
          nullable: true
          description: Forced chunk type (TABLE/IMAGE/HTML), only for single_chunk mode
      type: object
      required:
        - status
      title: PipelineState
      description: Pipeline execution state tracking.
    InformationStatistics:
      properties:
        num_chunks_by_type:
          additionalProperties:
            type: integer
          type: object
          title: Num Chunks By Type
          description: 'Count of chunks by type (e.g. {"TEXT": 42, "TABLE": 3})'
        total_tokens:
          type: integer
          title: Total Tokens
          description: Sum of all chunk content tokens in subtree
          default: 0
        num_direct_children:
          type: integer
          title: Num Direct Children
          description: Count of immediate children (sections + chunks)
          default: 0
        children_depth:
          type: integer
          title: Children Depth
          description: Max depth to deepest leaf (0 = no children)
          default: 0
      type: object
      title: InformationStatistics
      description: Aggregate statistics for a section subtree or document version.
    PipelineStatus:
      type: string
      enum:
        - pending
        - processing
        - completed
        - failed
        - cancelled
      title: PipelineStatus
      description: Status of the ingestion pipeline workflow.
    IngestionMode:
      type: string
      enum:
        - high_accuracy
        - standard
        - single_chunk
      title: IngestionMode
      description: Ingestion pipeline mode — determines conversion and chunking strategy.
    ChunkType:
      type: string
      enum:
        - TEXT
        - TABLE
        - IMAGE
        - HTML
        - UNKNOWN
      title: ChunkType
      description: Type of chunk content.

````