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

# Get Document Version Contents Handler

> List all sections and chunks for a document version in depth-first logical order.

Returns a discriminated union of SectionContentItem and ChunkContentItem,
distinguished by the `part_type` field ("SECTION" or "CHUNK").

Use `content_type` to return only one type (e.g. `content_type=CHUNK` for
chunk-only pagination where offset/limit apply only to chunks).



## OpenAPI

````yaml /openapi.yaml get /v1/document_versions/{version_id}/contents
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/document_versions/{version_id}/contents:
    get:
      tags:
        - document-versions
      summary: Get Document Version Contents Handler
      description: >-
        List all sections and chunks for a document version in depth-first
        logical order.


        Returns a discriminated union of SectionContentItem and
        ChunkContentItem,

        distinguished by the `part_type` field ("SECTION" or "CHUNK").


        Use `content_type` to return only one type (e.g. `content_type=CHUNK`
        for

        chunk-only pagination where offset/limit apply only to chunks).
      operationId: get_document_version_contents
      parameters:
        - name: version_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Version Id
            description: DocumentVersion ID
          description: DocumentVersion ID
        - name: section_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
            nullable: true
            description: Optional section ID to scope traversal to a subtree
            title: Section Id
          description: Optional section ID to scope traversal to a subtree
        - name: content_type
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/DocumentVersionContentTypeFilter'
            nullable: true
            description: >-
              Filter by content type: SECTION or CHUNK. Omit to return both
              types.
            title: Content Type
          description: 'Filter by content type: SECTION or CHUNK. Omit to return both types.'
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            maximum: 100
            minimum: 1
            description: Number of items per page
            default: 20
            title: Limit
          description: Number of items per page
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
            description: Number of items to skip
            default: 0
            title: Offset
          description: Number of items to skip
        - 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
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PaginatedResponse_Annotated_Union_SectionContentItem__ChunkContentItem___Discriminator__
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    DocumentVersionContentTypeFilter:
      type: string
      enum:
        - SECTION
        - CHUNK
      title: DocumentVersionContentTypeFilter
      description: Filter for the type of content rows to return.
    PaginatedResponse_Annotated_Union_SectionContentItem__ChunkContentItem___Discriminator__:
      properties:
        items:
          items:
            $ref: '#/components/schemas/SectionContentItemOrChunkContentItem'
          type: array
          title: Items
          description: List of items
        total:
          type: integer
          minimum: 0
          title: Total
          description: Total number of items
        limit:
          type: integer
          minimum: 1
          title: Limit
          description: Number of items per page
        offset:
          type: integer
          minimum: 0
          title: Offset
          description: Number of items to skip
      additionalProperties: false
      type: object
      required:
        - items
        - total
        - limit
        - offset
      title: >-
        PaginatedResponse[Annotated[Union[SectionContentItem, ChunkContentItem],
        Discriminator]]
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SectionContentItemOrChunkContentItem:
      oneOf:
        - $ref: '#/components/schemas/SectionContentItem'
        - $ref: '#/components/schemas/ChunkContentItem'
      discriminator:
        propertyName: part_type
        mapping:
          CHUNK:
            $ref: '#/components/schemas/ChunkContentItem'
          SECTION:
            $ref: '#/components/schemas/SectionContentItem'
    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
    SectionContentItem:
      properties:
        part_type:
          type: string
          title: Part Type
          description: Path part type
          enum:
            - SECTION
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        name:
          type: string
          title: Name
          description: PathPart name
        parent_path_id:
          type: string
          format: uuid
          title: Parent Path Id
          description: Parent PathPart ID
        metadata_obj_id:
          type: string
          format: uuid
          title: Metadata Obj Id
          description: Section ID
        depth:
          type: integer
          title: Depth
          description: Depth relative to document version root
        page_number:
          type: integer
          nullable: true
          title: Page Number
          description: Section page number
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this item is system-managed
        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:
        - part_type
        - path_part_id
        - name
        - parent_path_id
        - metadata_obj_id
        - depth
        - materialized_path
        - system_managed
        - created_at
        - updated_at
      title: SectionContentItem
      description: Response model for a section item in document version contents.
    ChunkContentItem:
      properties:
        part_type:
          type: string
          title: Part Type
          description: Path part type
          enum:
            - CHUNK
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        name:
          type: string
          title: Name
          description: PathPart name
        parent_path_id:
          type: string
          format: uuid
          title: Parent Path Id
          description: Parent PathPart ID
        metadata_obj_id:
          type: string
          format: uuid
          title: Metadata Obj Id
          description: Chunk ID
        depth:
          type: integer
          title: Depth
          description: Depth relative to document version root
        content:
          type: string
          nullable: true
          title: Content
          description: Chunk content
        chunk_type:
          $ref: '#/components/schemas/ChunkType'
          nullable: true
          description: Chunk type
        chunk_metadata:
          $ref: '#/components/schemas/ChunkMetadata-Output'
          nullable: true
          description: Chunk metadata
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this item is system-managed
        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:
        - part_type
        - path_part_id
        - name
        - parent_path_id
        - metadata_obj_id
        - depth
        - materialized_path
        - system_managed
        - created_at
        - updated_at
      title: ChunkContentItem
      description: Response model for a chunk item in document version contents.
    ChunkType:
      type: string
      enum:
        - TEXT
        - TABLE
        - IMAGE
        - HTML
        - UNKNOWN
      title: ChunkType
      description: Type of chunk content.
    ChunkMetadata-Output:
      properties:
        polygons:
          items:
            $ref: '#/components/schemas/PolygonReference'
          type: array
          title: Polygons
          description: >-
            List of bounding boxes in the source document for the chunk,
            potentially from multiple areas of multiple pages.
        s3_urls:
          items:
            type: string
          type: array
          title: S3 Urls
          description: >-
            Ordered s3:// URIs to visual assets for this chunk. Single-element
            for standard IMAGE/TABLE/HTML chunks, multi-element for multi-page
            single-chunk ingestion.
        summary:
          type: string
          nullable: true
          title: Summary
          description: >-
            LLM-generated summary of the chunk content. Used for TABLE and HTML
            chunks to enrich embedding text.
        extracted_text_s3_uri:
          type: string
          nullable: true
          title: Extracted Text S3 Uri
          description: >-
            S3 URI to extracted PDF text used for LLM grounding during
            enrichment
        secondary_taxonomy:
          $ref: '#/components/schemas/ImageTaxonomy'
          nullable: true
          description: >-
            Sub-classification within a primary chunk type. For IMAGE chunks:
            'flowchart' (Mermaid extraction) or 'picture' (image description).
            None when not applicable. Will expand to cover TABLE sub-types in
            the future.
        sheet_name:
          type: string
          nullable: true
          title: Sheet Name
          description: Worksheet name this chunk was extracted from (XLSX only)
        block_type:
          type: string
          nullable: true
          title: Block Type
          description: XLSXParser block type (e.g. table, calculation_block, chart_anchor)
        source_uri:
          type: string
          nullable: true
          title: Source Uri
          description: Cell range URI reference in the source workbook (XLSX only)
        enriched_html:
          type: string
          nullable: true
          title: Enriched Html
          description: >-
            Rendered HTML for non-table XLSX chunks (tables use render_html as
            content)
        cell_range:
          type: string
          nullable: true
          title: Cell Range
          description: Cell address range, e.g. 'A1:D10' (XLSX only)
        dependency_summary:
          additionalProperties: true
          type: object
          nullable: true
          title: Dependency Summary
          description: >-
            Upstream/downstream/cross-sheet cell references for audit reasoning
            (XLSX only)
        formulas:
          items:
            additionalProperties:
              type: string
            type: object
          type: array
          nullable: true
          title: Formulas
          description: >-
            Formula cells in this chunk as [{address, formula, value}] (XLSX
            only)
        key_cells:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Key Cells
          description: Notable output/header cells for quick identification (XLSX only)
        named_ranges:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Named Ranges
          description: Named ranges overlapping this chunk (XLSX only)
      type: object
      title: ChunkMetadata
      description: Metadata for a chunk including source document references.
    PolygonReference:
      properties:
        page:
          type: integer
          title: Page
          description: The page number of the source document where the polygon is located.
        polygon:
          $ref: '#/components/schemas/Polygon'
          description: The bounding box of the polygon.
      type: object
      required:
        - page
        - polygon
      title: PolygonReference
      description: Reference to a polygon on a specific page.
    ImageTaxonomy:
      type: string
      enum:
        - picture
        - flowchart
      title: ImageTaxonomy
      description: Image classification taxonomy with prompt descriptions.
    Polygon:
      properties:
        x:
          type: integer
          title: X
          description: The x-coordinate of the top-left corner of the bounding box.
        'y':
          type: integer
          title: 'Y'
          description: The y-coordinate of the top-left corner of the bounding box.
        width:
          type: integer
          title: Width
          description: The width of the bounding box.
        height:
          type: integer
          title: Height
          description: The height of the bounding box.
      type: object
      required:
        - x
        - 'y'
        - width
        - height
      title: Polygon
      description: Bounding box polygon.

````