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

# Link an existing document

> Link an existing visible document into a chat.

References a document you can already see — no clone, no re-extraction. A foreign id is **404**, not 403.


## OpenAPI

````yaml POST /api/v2/chats/{thread_id}/attachments/link/
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/link/:
    post:
      tags:
        - v2/chats
      summary: Link existing document(s) into a chat
      description: >-
        LINKs existing documents into the chat (Decision 8: LINK, not CLONE —
        the doc's markdown / extraction / ES chunks are reused as-is and edits
        propagate to every chat that references it). Sources may be raw
        ``ChatAttachment`` PKs and/or ``BatchDocument`` PKs. Sources resolve
        inside the caller's own tenant (plus their own documents, which survive
        an org move), then visibility runs through
        ``policy.can_view_chat_attachment`` (owner / org-mod / approved
        org-library share / active direct-share): a document in another tenant
        is 404 — indistinguishable from an unknown id, so PKs are not enumerable
        — a document in the caller's own tenant that they may not see is 403,
        and a self-link (doc already in this chat) is 400. Idempotent —
        re-linking an already-linked doc returns the existing row.
      operationId: v2_chats_attachments_link_create
      parameters:
        - in: path
          name: thread_id
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatAttachmentLinkRequestRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatAttachmentLinkResponse'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '403':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    ChatAttachmentLinkRequestRequest:
      type: object
      description: >-
        Body for ``POST /api/v2/chats/<thread_id>/attachments/link/``.


        Links existing documents into the chat (Decision 8: LINK, not CLONE —
        the

        doc's markdown / extraction / ES chunks are reused as-is, edits
        propagate).

        Sources may be given as raw ``ChatAttachment`` PKs and/or
        ``BatchDocument``

        PKs (a batch row's underlying ``attachment``). At least one list must be

        non-empty.
      properties:
        source_attachment_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: ChatAttachment PKs to link into the chat.
        source_batch_document_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: >-
            BatchDocument PKs whose underlying ChatAttachment is linked into the
            chat.
    ChatAttachmentLinkResponse:
      type: object
      description: '``201`` response for the link endpoint — the created/existing link rows.'
      properties:
        links:
          type: array
          items:
            $ref: '#/components/schemas/ChatAttachmentLinkItem'
      required:
        - links
    ChatAttachmentLinkItem:
      type: object
      description: |-
        A single ``ChatAttachmentLink`` row in the link response.

        Surfaces the source document's name + processing status (via the
        ``attachment`` FK) so the SPA can render the linked chip without a
        follow-up document lookup.
      properties:
        id:
          type: integer
          readOnly: true
        attachment_id:
          type: integer
          readOnly: true
        file_name:
          type: string
          readOnly: true
        processing_status:
          type: string
          readOnly: true
        attached_at:
          type: string
          format: date-time
          readOnly: true
      required:
        - attached_at
        - attachment_id
        - file_name
        - id
        - processing_status
  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.

````