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

# Generate Document

> This endpoint offers different ways to generate a document. Find guides to document generation [here](/textgen/documents-standard).



## OpenAPI

````yaml /api-reference/auto-generated-openapi.yml post /interactions/{id}/documents/
openapi: 3.0.0
info:
  title: Corti API
  version: 2.0.0
servers:
  - url: https://api.{environment}.corti.app/v2/
    variables:
      environment:
        default: eu
        enum:
          - us
          - eu
security:
  - AuthorizationHeader:
      - bearer
tags:
  - name: Interactions
  - name: Facts
  - name: Documents
  - name: Codes
  - name: Recordings
  - name: Transcripts
paths:
  /interactions/{id}/documents/:
    post:
      tags:
        - Documents
      summary: Generate Document
      description: >-
        This endpoint offers different ways to generate a document. Find guides
        to document generation [here](/textgen/documents-standard).
      operationId: documents_create
      parameters:
        - $ref: '#/components/parameters/Tenant-Name'
        - $ref: '#/components/parameters/CommonInteractionId'
        - $ref: '#/components/parameters/X-Corti-Retention-Policy'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentsCreateRequest'
        required: true
      responses:
        '201':
          description: ' '
          headers:
            X-Corti-Retention-Policy:
              description: >
                Present and set to `acknowledged` if the request included
                `X-Corti-Retention-Policy: none`.
              schema:
                type: string
                enum:
                  - acknowledged
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentsGetResponse'
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: RFC9457
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: RFC9457
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: RFC9457
        '504':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: RFC9457
      x-codeSamples:
        - lang: text
          label: from Facts
          source: |-
            curl --request POST \
              --url https://api.{environment}.corti.app/v2/interactions/{id}/documents \
              --header 'Content-Type: application/json' \
              --data '{
              "context": [
                {
                  "type": "facts",
                  "data": [
                    {
                      "text": "<string>",
                      "group": "other",
                      "source": "core"
                    }
                  ]
                }
              ],
              "templateKey": "<string>",
              "name": "<string>",
              "outputLanguage": "<string>"
            }'
        - lang: text
          label: from Transcript
          source: |-
            curl --request POST \
              --url https://api.{environment}.corti.app/v2/interactions/{id}/documents \
              --header 'Content-Type: application/json' \
              --data '{
              "context": [
                {
                  "type": "transcript",
                  "data": {
                    "channel": 1,
                    "end": 129,
                    "participant": 123,
                    "start": 20,
                    "text": "<string>"
                  }
                }
              ],
              "templateKey": "<string>",
              "name": "<string>",
              "outputLanguage": "<string>"
            }'
        - lang: text
          label: assemble Template
          source: |-
            curl --request POST \
              --url https://api.{environment}.corti.app/v2/interactions/{id}/documents \
              --header 'Content-Type: application/json' \
              --data '{
              "context": [
                {
                  "type": "string",
                  "data": "<string>"
                  }
              ],
              "templateKey": "<string>",
              "template": {
               "sectionKeys": [
                  "<string>"
                ],
              "name": "<string>",
              "outputLanguage": "<string>"
            }'
        - lang: text
          label: from string
          source: |-
            curl --request POST \
              --url https://api.{environment}.corti.app/v2/interactions/{id}/documents \
              --header 'Content-Type: application/json' \
              --data '{
              "context": [
                {
                  "type": "string",
                  "data": "<string>"
                }
              ],
              "templateKey": "<string>",
              "name": "<string>",
              "outputLanguage": "<string>"
            }'
        - lang: csharp
          label: C# .NET SDK
          source: |
            using Corti;

            var client = new CortiClient(
                "TENANT_NAME",
                CortiClientEnvironment.Eu,
                new CortiClientAuth.ClientCredentials("client_id", "client_secret")
            );
            await client.Documents.CreateAsync(
                "f47ac10b-58cc-4372-a567-0e02b2c3d479",
                new DocumentsCreateRequestWithTemplateKey
                {
                    Context = new List<DocumentsContext>()
                    {
                        new DocumentsContextWithFacts
                        {
                            Type = DocumentsContextWithFactsType.Facts,
                            Data = new List<FactsContext>() { new FactsContext { Text = "text" } },
                        },
                    },
                    TemplateKey = "templateKey",
                    OutputLanguage = "outputLanguage",
                }
            );
        - lang: javascript
          label: JavaScript SDK
          source: >
            import { CortiClient, CortiEnvironment } from "@corti/sdk";


            const client = new CortiClient({
                environment: CortiEnvironment.Eu,
                auth: {
                    clientId: "YOUR_CLIENT_ID",
                    clientSecret: "YOUR_CLIENT_SECRET"
                },
                tenantName: "YOUR_TENANT_NAME"
            });

            await
            client.documents.create("f47ac10b-58cc-4372-a567-0e02b2c3d479", {
                context: [{
                        type: "facts",
                        data: [{
                                text: "text"
                            }]
                    }],
                templateKey: "templateKey",
                outputLanguage: "outputLanguage"
            });
components:
  parameters:
    Tenant-Name:
      name: Tenant-Name
      in: header
      description: >-
        Identifies a distinct entity within Corti's multi-tenant system. Ensures
        correct routing and authentication of the request.
      required: true
      example: base
      schema:
        type: string
        description: >-
          Identifies a distinct entity within Corti's multi-tenant system.
          Ensures correct routing and authentication of the request.
        example: base
    CommonInteractionId:
      name: id
      in: path
      description: The unique identifier of the interaction. Must be a valid UUID.
      required: true
      schema:
        $ref: '#/components/schemas/UUID'
    X-Corti-Retention-Policy:
      name: X-Corti-Retention-Policy
      in: header
      description: >-
        With the optional header `X-Corti-Retention-Policy:none` the API will
        generate and return the document as expected, but the generated document
        will not be saved to the database. The response will include the header
        `X-Corti-Retention-Policy:acknowledged` to confirm that your retention
        preference was respected. If the header is omitted or set to any other
        value, the default retention policy will apply, and the document will be
        stored in the database.
      required: false
      schema:
        type: string
        enum:
          - none
  schemas:
    DocumentsCreateRequest:
      oneOf:
        - $ref: '#/components/schemas/DocumentsCreateRequestWithTemplateKey'
          title: Static Template
          description: >-
            Standard method for document generation: Use template key to
            generate document based on pre-defined template.
        - $ref: '#/components/schemas/DocumentsCreateRequestWithTemplate'
          title: Dynamic Template
          description: >-
            Advanced method for document generation: Define Sections in the
            request to build a template dynamically. See a detailed example
            [here](/templates/documents-advanced#assemble-a-template-with-extra-instructions).
    DocumentsGetResponse:
      type: object
      required:
        - id
        - name
        - templateRef
        - isStream
        - sections
        - createdAt
        - updatedAt
        - outputLanguage
        - usageInfo
      properties:
        id:
          $ref: '#/components/schemas/UUID'
          type: string
          format: uuid
          description: Unique ID of the generated document
        name:
          type: string
          description: Name of the generated document
        templateRef:
          type: string
          description: Reference for the used template
        isStream:
          type: boolean
        sections:
          type: array
          description: Individual document sections
          items:
            $ref: '#/components/schemas/DocumentsSection'
        createdAt:
          type: string
          format: date-time
          description: The original timestamp when the document was created.
        updatedAt:
          type: string
          format: date-time
          description: The timestamp when the document was last updated.
        outputLanguage:
          type: string
          description: >-
            The language in which the document will be generated. Check
            https://docs.corti.ai/about/languages for more.
        usageInfo:
          $ref: '#/components/schemas/CommonUsageInfo'
          type: object
    ErrorResponse:
      type: object
      required:
        - requestid
        - status
        - type
        - detail
      properties:
        requestid:
          type: string
        status:
          type: integer
        type:
          type: string
        detail:
          type: string
        validationErrors:
          type: array
          items:
            type: object
            additionalProperties:
              type: string
    UUID:
      type: string
      items: {}
      format: uuid
      example: f47ac10b-58cc-4372-a567-0e02b2c3d479
    DocumentsCreateRequestWithTemplateKey:
      type: object
      required:
        - context
        - templateKey
        - outputLanguage
      properties:
        context:
          type: array
          description: >-
            An array of context objects. Currently only accepts multiple objects
            when of type `transcript`. See
            [guide](/textgen/documents-standard#generate-document-from-transcript-as-input).
          minItems: 1
          items:
            $ref: '#/components/schemas/DocumentsContext'
        templateKey:
          type: string
          description: >-
            The key of the template referencing the sections for generating a
            document.
        name:
          type: string
          description: An optional name for the document.
        outputLanguage:
          type: string
          description: >-
            The language in which the document will be generated. Check
            [languages page](/about/languages) for more.
        disableGuardrails:
          type: boolean
          description: >-
            Set to true to disable guardrails during document generation,
            default is false.
        documentationMode:
          $ref: '#/components/schemas/TemplatesDocumentationModeEnum'
    DocumentsCreateRequestWithTemplate:
      type: object
      required:
        - context
        - template
        - outputLanguage
      properties:
        context:
          type: array
          description: >-
            An array of context objects. Currently only accepts multiple objects
            when of type `transcript`. See
            [guide](/textgen/documents-standard#generate-document-from-transcript-as-input).
          minItems: 1
          items:
            $ref: '#/components/schemas/DocumentsContext'
        template:
          $ref: '#/components/schemas/DocumentsTemplate'
          type: object
          description: >-
            Template details if the template should be generated during the
            request.
        name:
          type: string
          description: An optional name for the document.
        outputLanguage:
          type: string
          description: >-
            The language in which the document will be generated. Check
            [languages page](/about/languages) for more.
        disableGuardrails:
          type: boolean
          description: >-
            Set to true to disable guardrails during document generation,
            default is false.
        documentationMode:
          $ref: '#/components/schemas/TemplatesDocumentationModeEnum'
    DocumentsSection:
      type: object
      required:
        - key
        - name
        - text
        - sort
        - createdAt
        - updatedAt
      properties:
        key:
          type: string
          description: Document section key
        name:
          type: string
          description: >-
            Name or heading of the document section within the generated
            document
        text:
          type: string
          description: Contents of the document section within the generated document
        sort:
          type: integer
          description: Order of the document section within the generated document
        createdAt:
          type: string
          format: date-time
          description: The original timestamp when the document section was created.
        updatedAt:
          type: string
          format: date-time
          description: The timestamp when the document section was last updated.
    CommonUsageInfo:
      type: object
      description: Credits consumed for this request.
      required:
        - creditsConsumed
      properties:
        creditsConsumed:
          type: number
    DocumentsContext:
      oneOf:
        - $ref: '#/components/schemas/DocumentsContextWithFacts'
          title: Facts
        - $ref: '#/components/schemas/DocumentsContextWithTranscript'
          title: Transcript
        - $ref: '#/components/schemas/DocumentsContextWithString'
          title: String
    TemplatesDocumentationModeEnum:
      type: string
      description: >-
        Configures the approach and underlying system prompt that govern how the
        LLM generates documentation.
      example: global_sequential
      enum:
        - global_sequential
        - routed_parallel
    DocumentsTemplate:
      oneOf:
        - $ref: '#/components/schemas/DocumentsTemplateWithSections'
          title: Sections (overridable)
          description: Flexible sections to be used in document generation.
        - $ref: '#/components/schemas/DocumentsTemplateWithSectionKeys'
          title: Section keys
          description: Section keys to be used in document generation, without overrides.
    DocumentsContextWithFacts:
      type: object
      required:
        - type
        - data
      properties:
        type:
          type: string
          enum:
            - facts
          description: >-
            The type of context data that will be used in the request: `Facts`,
            `Transcript`, or `String`.
        data:
          type: array
          description: >-
            An array of facts. See
            [guide](/textgen/documents-standard##generate-document-from-facts-as-input).
          minItems: 1
          items:
            $ref: '#/components/schemas/FactsContext'
    DocumentsContextWithTranscript:
      type: object
      required:
        - type
        - data
      properties:
        type:
          type: string
          enum:
            - transcript
          description: >-
            The type of context data that will be used in the request: `Facts`,
            `Transcript`, or `String`.
        data:
          $ref: '#/components/schemas/CommonTranscriptRequest'
          type: object
          description: >-
            The transcript `data.text` object can accept the full transcript in
            one string, alternatively pass each transcript segment into a
            `context` object - [see
            guide](/textgen/documents-standard#generate-document-from-transcript-as-input).
    DocumentsContextWithString:
      type: object
      required:
        - type
        - data
      properties:
        type:
          type: string
          enum:
            - string
          description: >-
            The type of context data that will be used in the request: `Facts`,
            `Transcript`, or `String`.
        data:
          type: string
          description: >-
            String data can include any text to be reasoned over for document
            generation: Transcript text, facts, or other narrative information.
    DocumentsTemplateWithSections:
      type: object
      required:
        - sections
      properties:
        sections:
          type: array
          items:
            $ref: '#/components/schemas/DocumentsSectionOverride'
        description:
          type: string
          description: >-
            A brief description of the document that can help give the LLM some
            context.
        additionalInstructionsOverride:
          type: string
          description: Overrides and sets template-level additional instructions.
    DocumentsTemplateWithSectionKeys:
      type: object
      required:
        - sectionKeys
      properties:
        sectionKeys:
          type: array
          description: An array of section keys.
          items:
            type: string
        documentName:
          type: string
          description: The name of the document.
        additionalInstructions:
          type: string
          description: >-
            Any additional instructions to be considered during document
            generation.
    FactsContext:
      type: object
      required:
        - text
      properties:
        text:
          type: string
          description: The text of the fact.
        group:
          type: string
          description: The group to which the fact belongs.
          example: Others
        source:
          $ref: '#/components/schemas/CommonSourceEnum'
          description: >-
            Source 'core' indicates facts generated by the LLM, 'user' for facts
            added by the user, 'system' for system-derived facts (e.g. EHR).
    CommonTranscriptRequest:
      type: object
      required:
        - text
      properties:
        channel:
          type: integer
          description: The channel associated with this phrase/utterance.
        participant:
          type: integer
          description: The identifier of the participant.
        speakerId:
          type: integer
          description: Id to tag an identified speaker. Auto-increments.
        text:
          type: string
          description: The spoken phrase or utterance extracted from the audio.
        start:
          type: integer
          description: Start time in milliseconds for phrase/utterance.
        end:
          type: integer
          description: End time in milliseconds for phrase/utterance.
    DocumentsSectionOverride:
      type: object
      properties:
        key:
          type: string
          description: The key that references the section to use for document generation.
        nameOverride:
          type: string
          description: Overrides the section name used in document generation and response.
        writingStyleOverride:
          type: string
          description: >-
            Overrides the section's default writing style with your custom
            prompt.
        formatRuleOverride:
          type: string
          description: Overrides the section's default format rule with your custom prompt.
        additionalInstructionsOverride:
          type: string
          description: >-
            Overrides and sets the section-level additional instructions with
            your custom prompt.
        contentOverride:
          type: string
          description: >-
            Overrides the section's content prompt used for input assignment
            with documentationMode: routed_parallel, and section generation.
      required:
        - key
    CommonSourceEnum:
      type: string
      enum:
        - core
        - system
        - user
  securitySchemes:
    AuthorizationHeader:
      type: http
      description: Input your token
      scheme: bearer

````