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

# Clone from knowledge base

> Clone a knowledge-base file into an Extract chat.

Copies a Knowledge Base file into the chat (clone, not a link). Session or bearer only — an org API key is refused. Extraction of the clone is billed like a new upload.


## OpenAPI

````yaml POST /api/v2/chats/{thread_id}/attachments/kb/
openapi: 3.1.0
info:
  title: Abacus Docs API
  version: 1.0.0
  description: |
    REST + SSE surface for Abacus Docs on the same host as the web app
    (`https://abacusdocs.com`). Paths are `/api/v2/…`.

    Authenticate with an organisation API key (`sk-abacus-*`) as a Bearer
    token, or an Auth0 access token. Cross-tenant reads return **404**, not
    403. Page-based lists use `?page=` and `?page_size=`.

    Extraction, reprocess, schema tests, and chat turns spend credits.
    See the help centre Credits pages for rates.
  contact:
    name: Abacus Docs
    url: https://abacusdocs.com/contact
servers:
  - url: https://abacusdocs.com
    description: Production (Extract)
security: []
paths:
  /api/v2/chats/{thread_id}/attachments/kb/:
    post:
      tags:
        - v2/chats
      summary: Attach Knowledge Base file(s) to a chat
      description: >-
        Clones the given Knowledge Base files into the chat as fresh
        ``ChatAttachment`` rows (``is_from_kb=true``) and dispatches Lynx
        processing. Kept as CLONE (not LINK) for back-compat with the legacy
        chat-upload behaviour. KB files not owned by the caller are silently
        skipped; already-attached bytes go to ``skipped_duplicates``.
      operationId: v2_chats_attachments_kb_create
      parameters:
        - in: path
          name: thread_id
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatAttachmentKbRequestRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatAttachmentUploadResponse'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    ChatAttachmentKbRequestRequest:
      type: object
      description: >-
        Body for ``POST /api/v2/chats/<thread_id>/attachments/kb/``.


        Attaches Knowledge Base files into the chat. Kept as CLONE (a fresh

        ``ChatAttachment`` is created from each KB file with
        ``is_from_kb=True``)

        for back-compat with the legacy chat-upload behaviour — unlike the link

        endpoint, which shares one doc across chats.
      properties:
        kb_file_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: KnowledgeBase file PKs to clone into the chat as attachments.
      required:
        - kb_file_ids
    ChatAttachmentUploadResponse:
      type: object
      description: >-
        ``201`` response for ``POST /api/v2/chats/<thread_id>/attachments/``.


        Lynx processing is dispatched in the background, so the ``created`` rows

        come back with ``processing_status='pending'``; the SPA polls the list
        (or

        subscribes to the per-document stream in Task 16) for completion.
      properties:
        created:
          type: array
          items:
            $ref: '#/components/schemas/ChatAttachment'
        skipped_duplicates:
          type: array
          items:
            $ref: '#/components/schemas/SkippedDuplicate'
        skipped_unsupported:
          type: array
          items:
            $ref: '#/components/schemas/SkippedUnsupported'
      required:
        - created
        - skipped_duplicates
        - skipped_unsupported
    ChatAttachment:
      type: object
      description: >-
        Response shape for a single chat attachment (document).


        Used by the list endpoint, the upload response (``created`` rows), and

        anywhere the SPA renders a document chip. ``file.size`` is deliberately

        NOT surfaced — reading it hits the storage backend, which would mean one

        blocking GCS round-trip per row in a list. The SPA gets the size from
        the

        unified document-detail surface (Task 16) when it actually needs it.


        Two computed fields:
            has_schema: whether a ``StructVersion`` is pinned for schema-guided
                extraction (``extraction_struct_version`` is set).
            is_linked: whether this doc is LINKED into the chat being serialized
                (its home chat is a different chat) rather than uploaded directly.
                Computed from ``context["chat_pk"]`` — defaults to ``False`` when
                no chat context is supplied (e.g. the upload response, where every
                row is a fresh home-chat document).
      properties:
        id:
          type: integer
          readOnly: true
        file_name:
          type: string
          readOnly: true
        file_type:
          type: string
          readOnly: true
        processing_status:
          allOf:
            - $ref: '#/components/schemas/ProcessingStatusEnum'
          readOnly: true
          description: |-
            Lynx processing pipeline status: pending → completed/failed

            * `pending` - Pending
            * `completed` - Completed
            * `failed` - Failed
        processing_progress:
          type: integer
          readOnly: true
          description: Processing completion percentage 0-100
        processing_stage:
          type: string
          readOnly: true
          description: >-
            Current processing stage name, or the failure reason on a FAILED
            attachment
        page_count:
          type: integer
          readOnly: true
          description: Number of pages in the original document
        has_schema:
          type: boolean
          description: True when a schema (StructVersion) is pinned for extraction.
          readOnly: true
        extraction_struct_version_id:
          type:
            - integer
            - 'null'
          description: >-
            StructVersion that produced this attachment's extraction_result.
            NULL for non-batch attachments or pre-versioning records.
          readOnly: true
        target_language:
          type: string
          readOnly: true
          description: ISO language code for translation target (e.g. 'en', 'ar')
        is_from_kb:
          type: boolean
          readOnly: true
          description: Whether this attachment came from Knowledge Base
        kb_file_id:
          type:
            - integer
            - 'null'
          readOnly: true
          description: Original Knowledge Base file ID if from KB
        lynx_document_id:
          type:
            - string
            - 'null'
          readOnly: true
          description: Lynx document ID after processing (extraction + chunking + indexing)
        is_linked:
          type: boolean
          description: >-
            True when the doc is linked into ``context['chat_pk']`` from
            elsewhere.


            A direct (home) attachment has ``chat_id == chat_pk``; a linked-in
            doc

            keeps its original home ``chat_id`` (the link lives in

            ``ChatAttachmentLink``), so ``chat_id != chat_pk`` marks it linked.
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
      required:
        - created_at
        - extraction_struct_version_id
        - file_name
        - file_type
        - has_schema
        - id
        - is_from_kb
        - is_linked
        - kb_file_id
        - lynx_document_id
        - page_count
        - processing_progress
        - processing_stage
        - processing_status
        - target_language
    SkippedDuplicate:
      type: object
      description: |-
        A file skipped during upload/KB-attach because it was already present.

        Duplicates are detected by the ``(chat, checksum)`` unique constraint —
        the same bytes can't be attached to a chat twice.
      properties:
        file_name:
          type: string
          description: Name of the skipped file.
        reason:
          type: string
          description: Why it was skipped (currently always 'duplicate').
      required:
        - file_name
        - reason
    SkippedUnsupported:
      type: object
      description: >-
        A file rejected by the AD-437 upload gate (extension or size).


        The chat surfaces gate every upload through

        ``DocumentProcessingService.create_and_process``; a file whose extension
        is

        not in the (toggle-aware) accepted set, or that exceeds
        ``MAX_UPLOAD_SIZE``,

        is reported here as a per-file skip rather than failing the whole
        request.
      properties:
        file_name:
          type: string
          description: Name of the rejected file.
        reason:
          type: string
          description: 'Why it was rejected: ''unsupported_type'' or ''too_large''.'
      required:
        - file_name
        - reason
    ProcessingStatusEnum:
      enum:
        - pending
        - completed
        - failed
      type: string
      description: |-
        * `pending` - Pending
        * `completed` - Completed
        * `failed` - Failed
  securitySchemes:
    extractApiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        Organisation API key from Settings → API / `/api/keys/`. The secret is
        shown once. Send `Authorization: Bearer sk-abacus-…`. One active key
        per organisation. Ingest (`/api/v2/ingest/*`) refuses API keys — that
        surface is Auth0-only with `ingest:read` / `ingest:write` scopes.
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Auth0 access token for a signed-in user. Send `Authorization: Bearer
        <token>`.

        The SPA and desktop agent use this. Prefer an organisation API key for

        server-to-server integrations.
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid
      description: |
        Django session cookie from a browser login. Present so the web app can
        call `/api/v2` without a header. Do not rely on this for integrations.

````