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

# Attach a batch

> Attach a visible batch as Extract chat context.

Adds a visible batch as chat context. The grid is rebuilt on the next turn — no sync step. Attaching is free; the next user message is the chat charge.


## OpenAPI

````yaml POST /api/v2/chats/{thread_id}/batch-attachments/
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}/batch-attachments/:
    post:
      tags:
        - v2/chats
      summary: Attach a batch to a chat as LLM context
      description: >-
        Creates a ChatBatchAttachment join row so the Excel Graph's
        BatchExtractionProvider includes this batch in the chat's context
        window. The batch must be visible to the caller via _visible_batch_qs
        (owner, mod, superuser, approved org-library share, or active
        direct-share acceptance). Duplicates return 400 -- to re-attach, detach
        first.
      operationId: v2_chats_batch_attachments_create
      parameters:
        - in: path
          name: thread_id
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatBatchAttachmentCreateRequestRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatBatchAttachment'
          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:
    ChatBatchAttachmentCreateRequestRequest:
      type: object
      description: |-
        Body for ``POST /api/v2/chats/<thread_id>/batch-attachments/``.

        Fields:
            batch_id: PK of the ``Batch`` to attach. The view validates that
                the batch is visible to the request user via
                :func:`documents.views._visible_batch_qs` (shared batches via
                an approved org-library or active direct-share acceptance
                count as visible).
            context_mode: Render mode for ``BatchExtractionProvider``.
                Defaults to ``"full"`` (entire effective grid; batches over
                the size limit still downshift to a summary). ``"summary"``
                renders schema + a small row sample + a pointer to the
                ``query_batch_data`` SQL tool; ``"schema_only"`` renders
                schema + pointer with no rows. All three modes are honored
                at render time (AD-351 DuckDB batch analytics).
      properties:
        batch_id:
          type: integer
          minimum: 1
          description: PK of the Batch to attach to this chat.
        context_mode:
          allOf:
            - $ref: '#/components/schemas/ContextModeEnum'
          default: full
          description: >-
            Render mode for BatchExtractionProvider. 'full' (default) renders
            the entire grid into chat context (batches over the size limit still
            downshift to a summary); 'summary' renders schema + a small row
            sample + a query_batch_data SQL pointer; 'schema_only' renders
            schema + pointer with no rows.


            * `full` - full

            * `summary` - summary

            * `schema_only` - schema_only
      required:
        - batch_id
    ChatBatchAttachment:
      type: object
      description: |-
        Response shape for chat <-> batch attachment endpoints.

        Surfaces enough metadata for the SPA's "Attached batches" panel to
        render without a follow-up ``/api/v2/batches/`` lookup:
        ``batch_name``, ``batch_status``, the attaching user's email, and
        the render mode.

        The model docstring on ``ChatBatchAttachment`` documents the unlink
        semantics -- the join row CASCADE-deletes with chat or batch but
        never deletes the chat/batch itself, so this serializer's view of
        ``batch`` is always live.
      properties:
        id:
          type: integer
          readOnly: true
        batch_id:
          type: integer
          readOnly: true
        batch_name:
          type: string
          readOnly: true
        batch_status:
          type: string
          readOnly: true
        attached_at:
          type: string
          format: date-time
          readOnly: true
        attached_by_email:
          type:
            - string
            - 'null'
          description: |-
            Surface the attaching user's email or ``None`` if user was deleted.

            ``attached_by`` is ``SET_NULL`` on user delete -- we keep the join
            row alive even after the user is gone, so this returns ``None``
            when the attacher account no longer exists.
          readOnly: true
        context_mode:
          type: string
          readOnly: true
          description: >-
            Render mode for BatchExtractionProvider. 'full' renders the entire
            grid (batches over the size limit still downshift to summary);
            'summary' renders schema + a small sample + a query_batch_data SQL
            pointer; 'schema_only' renders schema + pointer with no rows.
      required:
        - attached_at
        - attached_by_email
        - batch_id
        - batch_name
        - batch_status
        - context_mode
        - id
    ContextModeEnum:
      enum:
        - full
        - summary
        - schema_only
      type: string
      description: |-
        * `full` - full
        * `summary` - summary
        * `schema_only` - schema_only
  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.

````