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

# Edit, draft, or restructure a document using natural language. Preserves tables, styling, and formatting.

> Synchronous AI chat that can rewrite specific paragraphs, add or remove table rows, restructure sections, generate new content from templates, or transform an entire document. Pass document_html only to load or replace the document; once a session holds a document the server persists it across turns, so omit it on follow-up turns. To replace the whole document with EXACT content you already hold, pass that content in document_html (a verbatim load — the AI never re-types it) or upload it via upload_document_base64; describing the content only in `message` makes the AI author it, which can drift from your text. Returns AI response text plus structural document changes (HTML edits, additions, deletions) with chunk IDs. One billable operation per document-modifying turn; very large multi-section edits bill one operation per 25 sections changed. For long-running edits or human-in-the-loop approval, use chat_async. Optional: model_tier (core/turbo/pro/max), thinking_depth (fast/balanced/deep), image_attachments for multimodal vision. RECOMMENDED for AI agents working with large documents (>20 pages): set response_mode='compact' to skip the full HTML in the response (the AI returns only per-section diffs in chunk_diffs) and save thousands of tokens per turn. To read sections in compact mode, just send a natural-language request like 'show me the force majeure section' — the AI returns the content in the reply text. Always use natural language to describe what you want; the AI handles all internal section lookups.



## OpenAPI

````yaml /openapi.json post /v1/chat
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/chat:
    post:
      tags:
        - v1
        - mcp
        - chat
      summary: >-
        Edit, draft, or restructure a document using natural language. Preserves
        tables, styling, and formatting.
      description: >-
        Synchronous AI chat that can rewrite specific paragraphs, add or remove
        table rows, restructure sections, generate new content from templates,
        or transform an entire document. Pass document_html only to load or
        replace the document; once a session holds a document the server
        persists it across turns, so omit it on follow-up turns. To replace the
        whole document with EXACT content you already hold, pass that content in
        document_html (a verbatim load — the AI never re-types it) or upload it
        via upload_document_base64; describing the content only in `message`
        makes the AI author it, which can drift from your text. Returns AI
        response text plus structural document changes (HTML edits, additions,
        deletions) with chunk IDs. One billable operation per document-modifying
        turn; very large multi-section edits bill one operation per 25 sections
        changed. For long-running edits or human-in-the-loop approval, use
        chat_async. Optional: model_tier (core/turbo/pro/max), thinking_depth
        (fast/balanced/deep), image_attachments for multimodal vision.
        RECOMMENDED for AI agents working with large documents (>20 pages): set
        response_mode='compact' to skip the full HTML in the response (the AI
        returns only per-section diffs in chunk_diffs) and save thousands of
        tokens per turn. To read sections in compact mode, just send a
        natural-language request like 'show me the force majeure section' — the
        AI returns the content in the reply text. Always use natural language to
        describe what you want; the AI handles all internal section lookups.
      operationId: chat
      parameters:
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UniversalChatRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    UniversalChatRequest:
      properties:
        message:
          type: string
          maxLength: 100000
          title: Message
          description: Your message to the AI assistant.
        session_id:
          type: string
          maxLength: 256
          pattern: ^[a-zA-Z0-9_\-\.]+$
          title: Session Id
          description: Unique session identifier. Reuse to continue a conversation.
        document_html:
          anyOf:
            - type: string
              maxLength: 50000000
            - type: 'null'
          title: Document Html
          description: >-
            Current document HTML. OMIT this when the session already holds the
            document — the server persists it across turns, so you don't re-send
            it every turn; pass it only to load new content or replace the
            document wholesale (a verbatim load — the AI never re-types content
            passed here). Include data-chunk-id attributes on elements to enable
            targeted AI edits.
        user_id:
          anyOf:
            - type: string
              maxLength: 256
            - type: 'null'
          title: User Id
          description: >-
            User identifier. Automatically set from authentication — typically
            omit this.
        image_attachments:
          anyOf:
            - items:
                $ref: '#/components/schemas/ImageAttachmentData'
              type: array
              maxItems: 20
            - type: 'null'
          title: Image Attachments
          description: Inline images for vision-based analysis (base64-encoded).
        model_tier:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Tier
          description: >-
            AI model to use: 'core' (default, fast), 'turbo' (fastest), 'pro'
            (advanced reasoning), 'max' (most capable).
        thinking_depth:
          anyOf:
            - type: string
            - type: 'null'
          title: Thinking Depth
          description: >-
            Reasoning depth: 'fast', 'balanced' (default), or 'deep'. Controls
            how much analysis the AI performs.
        approval_mode:
          anyOf:
            - type: string
            - type: 'null'
          title: Approval Mode
          description: >-
            Change review mode: 'approve_all' (default, auto-applies changes) or
            'ask_every_time' (pauses for your review).
        response_mode:
          anyOf:
            - type: string
              enum:
                - full
                - compact
            - type: 'null'
          title: Response Mode
          description: >-
            Response shape control. 'full' (default) returns the complete
            updated document HTML — required by web app editors and recommended
            for small documents (<20 pages). 'compact' (recommended for AI
            agents editing large documents) suppresses the full HTML and returns
            only per-section diffs (chunk_diffs) for changed sections, saving
            thousands of tokens per turn. To read sections in compact mode, just
            send a natural-language request like 'show me the force majeure
            section' — the AI returns the content in the chat reply text.
          default: full
        cursor_context:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cursor Context
          description: >-
            Editor cursor context at message time, used to default the insert
            location for new images, diagrams, or sections when the user's
            prompt doesn't name a position. Shape: {chunk_id: str,
            pos_in_chunk?: int, text_before?: str, text_after?: str}. Omit when
            the user typed in chat without focusing the editor first.
        document_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Id
          description: >-
            Target a specific open document by id (ids come from
            /v1/sessions/{session_id}/documents). Omit to target the focused
            document (default — unchanged single-document behaviour). When set,
            that document becomes the focus for this turn.
        window_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Window Id
          description: >-
            Optional identifier for the client window (set by the web app) so
            concurrent edits from two windows of the same chat are merged rather
            than overwritten. Agents/API may omit.
        cross_session_memory:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Cross Session Memory
          description: >-
            When true, the AI carries a private rolling memory of context across
            THIS account's chats (off by default). Per-request override of your
            saved Settings default.
        cross_session_search:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Cross Session Search
          description: >-
            When true, the AI may search your PAST chats and documents on demand
            to reuse prior work and open a found document (off by default).
            Per-request override of your saved Settings default; never affects
            the always-on search of the open document.
        cross_session_memory_key:
          anyOf:
            - type: string
              maxLength: 256
            - type: 'null'
          title: Cross Session Memory Key
          description: >-
            Optional per-request id of YOUR end-customer so the cross-session
            memory note is kept in a separate file per end-customer. Omit for
            one account-level note (the default / B2C).
        cross_session_scope:
          anyOf:
            - items:
                type: string
              type: array
              maxItems: 2000
            - type: 'null'
          title: Cross Session Scope
          description: >-
            Optional list of session ids to restrict cross-session SEARCH to
            (e.g. one end-customer's sessions). Omit to search all of this
            account's sessions. Only narrows within the API-key owner; ignored
            unless cross_session_search is on.
        touched_chunk_ids:
          anyOf:
            - items:
                type: string
              type: array
              maxItems: 50000
            - type: 'null'
          title: Touched Chunk Ids
          description: >-
            Optional list of chunk ids (data-chunk-id values) the user actually
            edited since the last sync, sent alongside document_html. When
            present, a chunk NOT in this list whose text is unchanged keeps its
            stored formatting byte-for-byte even if the client serialized it
            differently (protects styling from editor round-trip loss). Chunks
            in the list — and any chunk whose text changed — always take the
            submitted content. Omit for the default behavior (any differing
            chunk is treated as an edit).
        deleted_part_chunk_ids:
          anyOf:
            - items:
                type: string
              type: array
              maxItems: 50000
            - type: 'null'
          title: Deleted Part Chunk Ids
          description: >-
            Optional list of chunk ids (data-chunk-id values) of OUT-OF-FLOW
            part sections (page headers/footers, footnote/endnote bodies,
            comments) to delete explicitly, sent alongside document_html.
            Out-of-flow parts absent from document_html are always KEPT — an
            editor view not containing them is their normal state, never a
            deletion — so removing one requires naming its id here. Ids that are
            not stored out-of-flow parts are ignored (in-flow content keeps the
            default behavior). Omit when deleting nothing.
      type: object
      required:
        - message
        - session_id
      title: UniversalChatRequest
      description: Send a message to the AI assistant with optional document context.
      examples:
        - approval_mode: approve_all
          document_html: >-
            <div
            data-chunk-id="550e8400-e29b-41d4-a716-446655440000"><h2>Section
            3</h2><p>Terms and conditions...</p></div>
          message: Add a confidentiality clause to section 3
          model_tier: core
          session_id: session_abc123
    ChatResponse:
      properties:
        response:
          type: string
          title: Response
          description: AI assistant's response text.
        session_id:
          type: string
          title: Session Id
          description: Session identifier for this conversation.
        document_changes:
          anyOf:
            - $ref: '#/components/schemas/DocumentChanges'
            - type: 'null'
          description: >-
            Document modifications made by the AI. Present only when the
            document was changed.
        usage:
          anyOf:
            - $ref: '#/components/schemas/UsageInfo'
            - type: 'null'
          description: >-
            Operation usage data. Present for authenticated users with usage
            tracking.
        hint:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Hint
          description: >-
            Advisory guidance for API callers (additive; absent on most
            responses). Currently: prefer_chat_async_for_large_generations —
            this turn ran long enough that the same work submitted via POST
            /v1/chat/async would be safer (no gateway timeout risk) and reports
            progress.
      type: object
      required:
        - response
        - session_id
      title: ChatResponse
      description: AI response with optional document changes and usage data.
      examples:
        - document_changes:
            changes_summary: Document updated by AI
            updated_html: >-
              <div
              data-chunk-id="550e8400-e29b-41d4-a716-446655440000"><h2>Section
              3</h2><p>Updated content...</p></div>
            version_id: 7c9e6679-7425-40de-944b-e07fc1f90ae7
          response: >-
            I've added a confidentiality clause to section 3 covering
            non-disclosure obligations.
          session_id: session_abc123
          usage:
            monthly_limit: 500
            monthly_remaining: 458
            monthly_used: 42
            subscription_tier: free
            was_billable: true
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ImageAttachmentData:
      properties:
        id:
          type: string
          maxLength: 256
          title: Id
          description: Unique identifier for this image.
        name:
          type: string
          maxLength: 512
          title: Name
          description: Original filename of the image.
        base64Data:
          type: string
          maxLength: 50000000
          title: Base64Data
          description: Base64-encoded image data.
        mimeType:
          type: string
          maxLength: 128
          title: Mimetype
          description: MIME type (e.g., 'image/png', 'image/jpeg').
        size:
          type: integer
          maximum: 50000000
          title: Size
          description: File size in bytes.
      type: object
      required:
        - id
        - name
        - base64Data
        - mimeType
        - size
      title: ImageAttachmentData
      description: Inline image attachment for vision-based analysis.
    DocumentChanges:
      properties:
        updated_html:
          anyOf:
            - type: string
            - type: 'null'
          title: Updated Html
          description: >-
            Full updated document HTML with data-chunk-id attributes. Apply this
            to your editor to sync the document. Present in 'full' response mode
            (default); null in 'compact' mode.
        version_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Version Id
          description: Document version identifier. Changes on every modification.
        changes_summary:
          anyOf:
            - type: string
            - type: 'null'
          title: Changes Summary
          description: Human-readable summary of what was changed.
        requires_approval:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Requires Approval
          description: >-
            If true, changes need review via the approve endpoint before being
            applied.
        pending_changes:
          anyOf:
            - items:
                $ref: '#/components/schemas/PendingChange'
              type: array
            - type: 'null'
          title: Pending Changes
          description: >-
            Proposed changes awaiting approval. Present when requires_approval
            is true.
        changes:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Changes
          description: History of individual changes applied during this request.
        chunk_diffs:
          anyOf:
            - items:
                $ref: '#/components/schemas/PendingChange'
              type: array
            - type: 'null'
          title: Chunk Diffs
          description: >-
            Per-section before/after content for changes that were applied this
            turn. Present in 'compact' response mode (when updated_html is null)
            so the agent can verify what was modified without paying token cost
            for the full document. Same shape as pending_changes.
      additionalProperties: true
      type: object
      title: DocumentChanges
      description: Document modifications produced by the AI assistant.
    UsageInfo:
      properties:
        monthly_used:
          anyOf:
            - type: integer
            - type: 'null'
          title: Monthly Used
          description: Total operations used this billing cycle.
        monthly_limit:
          anyOf:
            - type: integer
            - type: 'null'
          title: Monthly Limit
          description: Maximum operations allowed per cycle. -1 means unlimited.
        monthly_remaining:
          anyOf:
            - type: integer
            - type: 'null'
          title: Monthly Remaining
          description: Operations remaining this cycle. -1 means unlimited.
        was_billable:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Was Billable
          description: Whether this request counted as a billable operation.
        ops_charged:
          anyOf:
            - type: integer
            - type: 'null'
          title: Ops Charged
          description: >-
            How many operations this request billed. A large multi-section edit
            can bill more than one (one per 25 sections edited), so monthly_used
            can increase by more than 1 between responses.
        quota_exhausted:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Quota Exhausted
          description: >-
            True when you have reached your plan's operation limit with no
            remaining balance — the current request still completes, but further
            billable requests pause until you upgrade or your billing cycle
            resets.
        subscription_tier:
          anyOf:
            - type: string
            - type: 'null'
          title: Subscription Tier
          description: 'Current subscription tier: ''free'', ''plus'', ''pro'', or ''enterprise''.'
        bucket_used:
          anyOf:
            - type: string
            - type: 'null'
          title: Bucket Used
          description: >-
            Which bucket this operation drew from: 'tier' or 'promo'. Null for
            non-billable ops.
        redemption_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Redemption Id
          description: Redemption grant this op drew from, when bucket_used is 'promo'.
        promotions:
          anyOf:
            - items:
                $ref: '#/components/schemas/ActivePromotionInfo'
              type: array
            - type: 'null'
          title: Promotions
          description: >-
            User's currently-active promotion grants, ordered by oldest-expiring
            first.
      additionalProperties: true
      type: object
      title: UsageInfo
      description: Operation usage data for the current billing cycle.
    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
    PendingChange:
      properties:
        change_id:
          type: string
          title: Change Id
          description: Unique identifier for this proposed change.
        operation:
          type: string
          title: Operation
          description: 'Type of change: ''edit'', ''create'', or ''delete''.'
        chunk_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Chunk Id
          description: Target document section ID being modified or deleted.
        document_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Id
          description: >-
            Identifier of the document (tab) this change applies to — lets
            multi-document integrators attribute each section diff to the right
            document.
        old_html:
          anyOf:
            - type: string
            - type: 'null'
          title: Old Html
          description: Previous HTML content of the section (for updates).
        new_html:
          anyOf:
            - type: string
            - type: 'null'
          title: New Html
          description: Proposed new HTML content (for updates and creates).
        ai_explanation:
          anyOf:
            - type: string
            - type: 'null'
          title: Ai Explanation
          description: AI-generated explanation of why this change was proposed.
      additionalProperties: true
      type: object
      required:
        - change_id
        - operation
      title: PendingChange
      description: A proposed document change awaiting user approval.
    ActivePromotionInfo:
      properties:
        redemption_id:
          type: string
          title: Redemption Id
          description: Unique identifier for this promotion grant.
        name:
          type: string
          title: Name
          description: Human-friendly promotion name (e.g., 'YC SUS India 2026 cohort').
        ops_remaining:
          type: integer
          title: Ops Remaining
          description: Operations still available in this promotion bucket.
        ops_granted:
          type: integer
          title: Ops Granted
          description: Total operations originally granted by this redemption.
        expires_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Expires At
          description: ISO 8601 expiry timestamp. Null if the credits never expire.
      additionalProperties: true
      type: object
      required:
        - redemption_id
        - name
        - ops_remaining
        - ops_granted
      title: ActivePromotionInfo
      description: >-
        A single active (drawable) promotion belonging to the authenticated
        user.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````