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

# Create a chat

> Create an Extract chat thread.

Opens an Extract thread. You can attach documents or a batch at create time. Creating the row is free; the first user message is the chat charge.


## OpenAPI

````yaml POST /api/v2/chats/
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/:
    post:
      tags:
        - v2/chats
      summary: Create an Extract chat
      description: >-
        Creates a new Extract chat owned by the caller. All body fields are
        optional — an empty body mints a fresh ``extract-workspace`` chat.
        ``batch_ids`` pre-attaches batches as LLM context; ``attachment_ids``
        LINKs existing documents (Decision 8 — shared, not cloned). The create
        is atomic: an invisible batch or document rolls the whole thing back
        with 403 (no orphan chat). A non-Extract ``workflow_type`` is rejected
        with 400.
      operationId: v2_chats_create
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCreateRequestRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatSummary'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '403':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    ChatCreateRequestRequest:
      type: object
      description: |-
        Body for ``POST /api/v2/chats/``.

        All fields optional — the minimal create is an empty body, which mints a
        fresh ``extract-workspace`` chat with a default title.

        Fields:
            workflow_type: Extract workflow slug. Validated against the Extract
                whitelist *in the view* (lazy import of
                ``documents.chat_views.ALLOWED_EXTRACT_WORKFLOWS`` to avoid pulling
                that heavy module into the serializer at import time). Unknown /
                non-Extract values (e.g. ``document-intelligence`` or a retired
                presentation-builder slug) are rejected with 400 — the chat surface
                is Extract-only. Defaults to ``extract-workspace`` when omitted.
            title: Optional chat title. When omitted the helper assigns the
                default ``"New Chat — <date>"``.
            batch_ids: Batches to pre-attach as LLM context. Each must be visible
                to the caller via ``_visible_batch_qs`` — an invisible batch rolls
                the whole create back (403, no orphan chat).
            attachment_ids: Existing documents to LINK into the new chat
                (Decision 8). Each must be visible via ``authz.policy.can_view_chat_attachment``
                — an invisible doc rolls the whole create back (403).
      properties:
        workflow_type:
          type: string
          minLength: 1
          description: >-
            Extract workflow slug (extract-workspace / extract-batch-analysis /
            extract-excel-assist). Defaults to 'extract-workspace'. Non-Extract
            values are rejected with 400.
          maxLength: 50
        title:
          type: string
          minLength: 1
          description: >-
            Optional chat title; defaults to an auto-generated 'New Chat —
            <date>'.
          maxLength: 255
        batch_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: >-
            Batch PKs to pre-attach as LLM context (must be visible to the
            caller).
        attachment_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: >-
            Existing document PKs to LINK into the new chat (must be visible to
            the caller).
    ChatSummary:
      type: object
      description: |-
        Response shape for a single chat (list item AND detail).

        A plain ``Serializer`` (not ``ModelSerializer``) because the
        ``*_count`` fields are queryset annotations, not model fields — the
        view layers them on via
        :func:`deckmonkey.api_v2.chats.views._annotated_chat_qs` (one query,
        no per-row N+1). DRF reads each field as an attribute off the model
        instance, so the annotations surface transparently alongside the
        real columns.

        Fields:
            id / thread_id / title / workflow_type / created_at / updated_at /
            is_active: straight off the ``Chat`` row.
            message_count: ``ChatMessage`` rows in the thread.
            batch_count: attached batches (``ChatBatchAttachment`` join rows).
            attachment_count: documents uploaded directly into this chat
                (``ChatAttachment`` rows whose ``chat`` is this chat).
            linked_count: documents linked in from another chat
                (``ChatAttachmentLink`` rows) — Decision 8 LINK semantics.
      properties:
        id:
          type: integer
          readOnly: true
        thread_id:
          type: string
          readOnly: true
        title:
          type: string
          readOnly: true
        workflow_type:
          type:
            - string
            - 'null'
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
        updated_at:
          type: string
          format: date-time
          readOnly: true
        is_active:
          type: boolean
          readOnly: true
        message_count:
          type: integer
          readOnly: true
        batch_count:
          type: integer
          readOnly: true
        attachment_count:
          type: integer
          readOnly: true
        linked_count:
          type: integer
          readOnly: true
      required:
        - attachment_count
        - batch_count
        - created_at
        - id
        - is_active
        - linked_count
        - message_count
        - thread_id
        - title
        - updated_at
        - workflow_type
  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.

````