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

# Generate Document

> Extract content from source documents, ingest, and orchestrate document generation using a template. Request is immediately queued as a background task and returns 202 Accepted. Poll `/api/v1/documents/status/{document_id}` for progress.

**Field aliases** (both forms accepted):
- `connector_data_id` = `document_set_key`
- `template_id` = `generic_mrt_id`
- `workspace_name` = `document_set_name`



## OpenAPI

````yaml /api-reference/openapi-v1.json post /api/v1/documents/generate
openapi: 3.0.0
info:
  title: Artos API
  description: API for document generation, template management, and document organization
  version: 1.0.0
  contact:
    name: Artos Support
    email: internal@artosai.com
servers:
  - url: https://api.artosai.com
    description: Production server
  - url: http://localhost:8000
    description: Local development server
security:
  - bearerAuth: []
paths:
  /api/v1/documents/generate:
    post:
      tags:
        - Documents
      summary: Generate Document
      description: >-
        Extract content from source documents, ingest, and orchestrate document
        generation using a template. Request is immediately queued as a
        background task and returns 202 Accepted. Poll
        `/api/v1/documents/status/{document_id}` for progress.


        **Field aliases** (both forms accepted):

        - `connector_data_id` = `document_set_key`

        - `template_id` = `generic_mrt_id`

        - `workspace_name` = `document_set_name`
      operationId: generateDocument
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateDocumentRequest'
            example:
              document_type: CSR
              file_paths:
                - org-id/documents/protocol.pdf
                - org-id/documents/study-report.pdf
              connector_data_id: project-2024-001
              workspace_name: Q1 CSR Documents
              template_id: template-uuid-123
              output_name: CSR_Final
      responses:
        '202':
          description: Request accepted for processing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskAcceptedResponse'
              example:
                message: >-
                  Request to generate document has been accepted and is being
                  processed in the background.
                task_id: document-uuid-456
        '400':
          description: Missing required parameters or document set not found
        '401':
          description: Authentication failure
        '500':
          description: Database operation failed
components:
  schemas:
    GenerateDocumentRequest:
      type: object
      description: >-
        Field aliases: `connector_data_id` = `document_set_key`, `template_id` =
        `generic_mrt_id`, `workspace_name` = `document_set_name`. Both the alias
        and field name are accepted.
      properties:
        document_type:
          type: string
          description: Type of document to generate (e.g., CSR, Protocol)
        file_paths:
          type: array
          items:
            type: string
          description: >-
            S3 object keys for source documents (e.g.,
            org-id/documents/protocol.pdf)
        connector_data_id:
          type: string
          description: 'Unique key for document set (field name: document_set_key)'
        workspace_name:
          type: string
          description: >-
            Human-readable name for the document set (field name:
            document_set_name)
        template_id:
          type: string
          description: 'ID of the template to use (field name: generic_mrt_id)'
        output_name:
          type: string
          description: Name for the generated output file (without .docx extension)
        selected_section_ids:
          oneOf:
            - type: array
              items:
                type: string
            - type: array
              items:
                type: object
          nullable: true
          description: Specific section IDs to include (optional)
        generic_mrt_outline_full:
          type: object
          nullable: true
          description: Full outline structure (optional)
        document_instructions:
          type: string
          nullable: true
          description: Document-level instructions (optional)
        style_guide_id:
          type: string
          nullable: true
          description: Style guide ID from the style_guides table (optional)
      required:
        - document_type
        - file_paths
        - connector_data_id
        - workspace_name
        - template_id
        - output_name
    TaskAcceptedResponse:
      type: object
      properties:
        message:
          type: string
          description: Status message
        task_id:
          type: string
          description: Document ID for polling status
      required:
        - message
        - task_id
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Bearer token authentication. Token provides organization-scoped access.

````