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

# Branch Conversation

> Fork a conversation at a completed user turn.

Creates a NEW thread whose message history is the parent's prefix up to
``from_turn`` and whose workspace (document / preferences / todos /
artifacts) is copied as-of that turn. The service manages its own
sessions because the LangGraph checkpointer seeding must happen between
two committed transactions.

Args:
    payload:   ``from_turn`` (>= 0; 0 forks from the empty start) and an
               optional ``reason`` label.
    user:      The authenticated user (must own the conversation).
    thread_id: The conversation to fork.

Returns:
    ``BranchCreateResponse`` with the new thread id and branch metadata.

Raises:
    HTTPException 400: ``from_turn`` at or before the thread's own branch point.
    HTTPException 403: The conversation belongs to another user.
    HTTPException 404: Unknown conversation, or ``from_turn`` beyond the latest turn.
    HTTPException 409: The snapshot needed to reconstruct the workspace is missing.
    HTTPException 502: Checkpointer seeding failed (branch fully rolled back).



## OpenAPI

````yaml /openapi.json post /api/conversations/{thread_id}/branch
openapi: 3.1.0
info:
  title: HAI-Co² API
  description: Human-AI Co-Construction reference implementation.
  version: 0.1.0
servers:
  - url: https://haico.gr
    description: Production
  - url: https://dev.haico.gr
    description: Development
  - url: http://localhost:8000
    description: Local development
security: []
paths:
  /api/conversations/{thread_id}/branch:
    post:
      tags:
        - Conversations
      summary: Branch Conversation
      description: |-
        Fork a conversation at a completed user turn.

        Creates a NEW thread whose message history is the parent's prefix up to
        ``from_turn`` and whose workspace (document / preferences / todos /
        artifacts) is copied as-of that turn. The service manages its own
        sessions because the LangGraph checkpointer seeding must happen between
        two committed transactions.

        Args:
            payload:   ``from_turn`` (>= 0; 0 forks from the empty start) and an
                       optional ``reason`` label.
            user:      The authenticated user (must own the conversation).
            thread_id: The conversation to fork.

        Returns:
            ``BranchCreateResponse`` with the new thread id and branch metadata.

        Raises:
            HTTPException 400: ``from_turn`` at or before the thread's own branch point.
            HTTPException 403: The conversation belongs to another user.
            HTTPException 404: Unknown conversation, or ``from_turn`` beyond the latest turn.
            HTTPException 409: The snapshot needed to reconstruct the workspace is missing.
            HTTPException 502: Checkpointer seeding failed (branch fully rolled back).
      operationId: branch_conversation_api_conversations__thread_id__branch_post
      parameters:
        - name: thread_id
          in: path
          required: true
          schema:
            type: string
            maxLength: 255
            minLength: 1
            title: Thread Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BranchCreateRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BranchCreateResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    BranchCreateRequest:
      properties:
        from_turn:
          type: integer
          minimum: 0
          title: From Turn
          description: >-
            Parent turn index to branch from. 0 forks from the empty start (used
            to retry/edit the very first turn).
        reason:
          anyOf:
            - type: string
              maxLength: 500
            - type: 'null'
          title: Reason
          description: Optional branch label
        workspace:
          anyOf:
            - $ref: '#/components/schemas/BranchWorkspaceOverride'
            - type: 'null'
          description: >-
            Displayed workspace to seed the branch with (restored-preview edits
            included). Omit to seed from the as-of-turn snapshot.
      type: object
      required:
        - from_turn
      title: BranchCreateRequest
      description: Payload for forking a conversation at a completed user turn.
    BranchCreateResponse:
      properties:
        thread_id:
          type: string
          title: Thread Id
        parent_thread_id:
          type: string
          title: Parent Thread Id
        branch_point_turn:
          type: integer
          title: Branch Point Turn
        title:
          type: string
          title: Title
      type: object
      required:
        - thread_id
        - parent_thread_id
        - branch_point_turn
        - title
      title: BranchCreateResponse
      description: Response returned after a branch thread has been fully created.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    BranchWorkspaceOverride:
      properties:
        preferences:
          anyOf:
            - items:
                $ref: '#/components/schemas/BranchPreferenceSeed'
              type: array
              maxItems: 200
            - type: 'null'
          title: Preferences
        todos:
          anyOf:
            - items:
                $ref: '#/components/schemas/BranchTodoSeed'
              type: array
              maxItems: 500
            - type: 'null'
          title: Todos
        objective:
          anyOf:
            - type: string
              maxLength: 5000
            - type: 'null'
          title: Objective
        document:
          anyOf:
            - $ref: '#/components/schemas/BranchDocumentSeed'
            - type: 'null'
      type: object
      title: BranchWorkspaceOverride
      description: >-
        The displayed workspace to seed a branch with, overriding the snapshot.


        Sent when forking from a restored preview the user has edited, so the
        branch

        starts from exactly what they see (their edits — including a lock —
        included)

        instead of the raw as-of-turn snapshot. Any field left unset falls back
        to

        the resolved snapshot; ``position`` is intentionally not accepted (the

        backend re-derives it from list order).
    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
    BranchPreferenceSeed:
      properties:
        title:
          type: string
          maxLength: 500
          title: Title
        subtitle:
          anyOf:
            - type: string
              maxLength: 2000
            - type: 'null'
          title: Subtitle
        kind:
          type: string
          enum:
            - hard
            - soft
          title: Kind
          default: soft
        locked:
          type: boolean
          title: Locked
          default: false
      type: object
      required:
        - title
      title: BranchPreferenceSeed
      description: One preference to seed into a branch (from the displayed preview).
    BranchTodoSeed:
      properties:
        text:
          type: string
          maxLength: 2000
          title: Text
        done:
          type: boolean
          title: Done
          default: false
        depth:
          type: integer
          maximum: 20
          minimum: 0
          title: Depth
          default: 0
      type: object
      required:
        - text
      title: BranchTodoSeed
      description: One todo to seed into a branch (from the displayed preview).
    BranchDocumentSeed:
      properties:
        title:
          anyOf:
            - type: string
              maxLength: 500
            - type: 'null'
          title: Title
        content:
          anyOf:
            - type: string
            - type: 'null'
          title: Content
      type: object
      title: BranchDocumentSeed
      description: Document to seed into a branch; empty ``content`` creates no document.
  securitySchemes:
    HTTPBearer:
      type: http
      description: >-
        A personal access token (`haico_pat_...`), created under Profile → API
        keys. Send it as `Authorization: Bearer <key>`. The browser session JWT
        is also accepted but is an internal mechanism and is not part of the
        public contract.
      scheme: bearer

````