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

# Rewind a chat session to before a specific user message — restores both the document and the conversation in one call.

> Rewinds a chat session to the state immediately before a specific user message. The document, conversation history, and supporting context all snap back to that point. The text of the reverted message is returned (compose_text) so the caller can edit and resend it. Messages from the reverted turn forward are soft-archived: hidden from active reads but retained for audit. The original conversation is preserved server-side; the restored conversation becomes the active timeline. Rejects with 409 if the session has a chat job in progress or awaiting approval — wait for the job to settle before reverting. Returns 422 if the message predates the revertability feature.



## OpenAPI

````yaml /openapi.json post /v1/sessions/{session_id}/revert
openapi: 3.1.0
info:
  title: Universal Document AI API
  description: AI-powered document editing with multi-tenant organization support
  version: 2.0.0
servers: []
security: []
paths:
  /v1/sessions/{session_id}/revert:
    post:
      tags:
        - v1
        - mcp
        - sessions
      summary: >-
        Rewind a chat session to before a specific user message — restores both
        the document and the conversation in one call.
      description: >-
        Rewinds a chat session to the state immediately before a specific user
        message. The document, conversation history, and supporting context all
        snap back to that point. The text of the reverted message is returned
        (compose_text) so the caller can edit and resend it. Messages from the
        reverted turn forward are soft-archived: hidden from active reads but
        retained for audit. The original conversation is preserved server-side;
        the restored conversation becomes the active timeline. Rejects with 409
        if the session has a chat job in progress or awaiting approval — wait
        for the job to settle before reverting. Returns 422 if the message
        predates the revertability feature.
      operationId: revert_session_to_message
      parameters:
        - name: session_id
          in: path
          required: true
          schema:
            type: string
            title: Session Id
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RevertRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RevertResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    RevertRequest:
      properties:
        turn_index:
          type: integer
          minimum: 0
          title: Turn Index
          description: >-
            Turn index of the user message to revert. The text of that message
            is returned in compose_text so the caller can re-edit and resend it.
            Every chat row at this turn or later is soft-archived (hidden from
            active reads but retained for audit).
        dry_run:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Dry Run
          description: >-
            When true, compute the per-document revert diff WITHOUT committing
            or archiving anything — used to render a preview before the user
            confirms.
          default: false
        window_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Window Id
          description: >-
            Optional identifier for the client window issuing the revert, used
            to coordinate concurrent reverts from multiple browser tabs.
      additionalProperties: true
      type: object
      required:
        - turn_index
      title: RevertRequest
      description: >-
        Rewind a chat session to the state immediately before a specific user
        message.
    RevertResponse:
      properties:
        session_id:
          type: string
          title: Session Id
          description: Session identifier.
        reverted_to_turn:
          type: integer
          title: Reverted To Turn
          description: >-
            Turn index that the active conversation now ends at (the AI reply
            preceding the reverted user message). -1 when the session is reset
            to its initial empty state (revert from the very first user
            message).
        compose_text:
          type: string
          title: Compose Text
          description: >-
            The text of the user message that was reverted. Clients should
            pre-fill the compose box with this so the user can edit and resend.
        document_state:
          anyOf:
            - $ref: '#/components/schemas/DocumentState'
            - type: 'null'
          description: Restored document state. Null when the session is reset to empty.
        editor_action:
          type: string
          title: Editor Action
          description: >-
            Client instruction: 'update' to load the restored document, or
            'clear' to reset the editor to empty.
          default: update
        archived_turn_count:
          type: integer
          title: Archived Turn Count
          description: >-
            Number of chat rows soft-archived by this revert (turns hidden from
            the UI but retained for audit).
        revert_changes:
          anyOf:
            - additionalProperties:
                items:
                  additionalProperties: true
                  type: object
                type: array
              type: object
            - type: 'null'
          title: Revert Changes
          description: >-
            Per-document (slug -> change-set) revert diff. Applying these merges
            the revert onto any concurrent live edits — a conflicting section is
            surfaced for you to resolve rather than replacing the whole
            document. On dry_run this is the preview; on a real revert it is
            what was committed.
        dry_run:
          type: boolean
          title: Dry Run
          description: >-
            Echoes the request's dry_run: when true nothing was
            committed/archived — this is a preview only.
          default: false
        redo_checkpoint_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Redo Checkpoint Id
          description: >-
            The identifier of the pre-revert state. Revert is non-destructive —
            passing this back to POST /sessions/{id}/redo (with the same
            turn_index) restores it and un-archives the rolled-back turns,
            undoing the revert. Null on a dry-run or a first-message reset.
      type: object
      required:
        - session_id
        - reverted_to_turn
        - compose_text
        - archived_turn_count
      title: RevertResponse
      description: >-
        Result of a session revert: restored document state and compose-box
        prefill.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DocumentState:
      properties:
        html_content:
          anyOf:
            - type: string
            - type: 'null'
          title: Html Content
          description: Full document HTML content with data-chunk-id attributes.
        document_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Id
          description: >-
            Session-local id (slug) of the focused document. Identifies the
            document on restore so a restored tab stays in sync with edits made
            to it in other sessions.
        version_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Version Id
          description: Document version identifier (UUID string).
        chunk_count:
          type: integer
          title: Chunk Count
          description: Number of content sections in the document.
          default: 0
        last_modified:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Modified
          description: ISO 8601 timestamp of the last modification.
        attachments:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Attachments
          description: >-
            Session attachments. Each item has: id (string), filename (string),
            file_extension (string), processing_status ('ready', 'processing',
            or 'failed').
        page_setup:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Page Setup
          description: >-
            Source page geometry of the focused document (width_in, height_in,
            margin_in{top,right,bottom,left}, orientation) when known, else
            null. The editor renders the page at this geometry on restore; null
            ⇒ US-Letter + 1in default.
      type: object
      title: DocumentState
      description: Current document state for session restoration.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````