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

# Creates a Knowledge Base Chat Response for the given Messages.



## OpenAPI

````yaml /api-reference/openapi.yaml post /knowledge-bases/{knowledge_base_id}/chat
openapi: 3.0.3
info:
  title: Totoy API
  description: >-
    Explain documents in simple, plain or detailed language and create Knowledge
    Bases from your documents in 19 languages.
  termsOfService: https://www.totoy.ai
  contact:
    name: Totoy Support
    email: support@totoy.ai
  license:
    name: MIT
    url: https://raw.githubusercontent.com/totoy-ai/totoy-openapi/main/LICENSE
  version: 1.1.5
servers:
  - url: https://api.totoy.ai/v1
security:
  - ApiKeyAuth: []
tags:
  - name: Explanation
    description: >-
      Given a document in any language, an output language and one of three
      language levels, the assistant will return an `Explanation` for this
      document.
  - name: Knowledge Bases
    description: >-
      Create `Knowledge Bases` from document or text `Sources` and chat with an
      assistant about them in 19 languages.
  - name: Sources
    description: >-
      `Sources` are used to upload documents (.pdf, .jpg or .png) or plain texts
      that can be used with features like `Explanation` or `Knowledge Bases.`
  - name: Projects
    description: '`Projects` are used to group `Knowledge Bases` and `Explanations`.'
  - name: Organization
    description: Get information about your `Organization`.
paths:
  /knowledge-bases/{knowledge_base_id}/chat:
    post:
      tags:
        - Knowledge Bases
      summary: Creates a Knowledge Base Chat Response for the given Messages.
      operationId: chatWithKnowledgeBase
      parameters:
        - $ref: '#/components/parameters/knowledgeBaseIdParam'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/KnowledgeBaseChatRequest'
            examples:
              knowledge-base-chat-request-example-1:
                $ref: '#/components/examples/knowledge-base-chat-request-example-1'
              knowledge-base-chat-request-example-2:
                $ref: '#/components/examples/knowledge-base-chat-request-example-2'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgeBaseChatResponse'
              examples:
                knowledge-base-chat-response-example-1:
                  $ref: '#/components/examples/knowledge-base-chat-response-example-1'
                knowledge-base-chat-response-example-2:
                  $ref: '#/components/examples/knowledge-base-chat-response-example-2'
        4XX:
          $ref: '#/components/responses/general4XXResponse'
        5XX:
          $ref: '#/components/responses/general5XXResponse'
components:
  parameters:
    knowledgeBaseIdParam:
      name: knowledge_base_id
      in: path
      required: true
      schema:
        type: string
        maxLength: 28
        pattern: ^kb_[a-zA-Z0-9]{25}$
      description: Unique identifier for a `Knowledge Base`.
      examples:
        knowledge-base-id-example:
          $ref: '#/components/examples/knowledge-base-id-example'
  schemas:
    KnowledgeBaseChatRequest:
      title: KnowledgeBaseChatRequest
      type: object
      additionalProperties: false
      properties:
        output_language:
          $ref: '#/components/schemas/OutputLanguage'
        language_level:
          $ref: '#/components/schemas/LanguageLevel'
        messages:
          description: >-
            The conversation history. Provide at least one user message to start
            the conversation.
          type: array
          items:
            $ref: '#/components/schemas/Message'
          maxItems: 50
        markdown_response:
          description: >-
            Whether the response should be returned as Markdown formatted text.
            If 'false', the response will be returned in plain text.
          type: boolean
          default: true
          example: true
      required:
        - output_language
        - language_level
        - messages
    KnowledgeBaseChatResponse:
      title: KnowledgeBaseChatResponse
      type: object
      additionalProperties: false
      properties:
        project_id:
          description: The `Project` that the `Knowledge Base` is assigned to.
          maxLength: 28
          pattern: ^pj_[a-zA-Z0-9]{25}$
          type: string
          example: pj_avX7imfLaPcQnv5ckvGlOEBA9
        output_language:
          $ref: '#/components/schemas/OutputLanguage'
        language_level:
          $ref: '#/components/schemas/LanguageLevel'
        answer:
          $ref: '#/components/schemas/Message'
        markdown_response:
          description: Whether the response is a Markdown formatted text.
          type: boolean
          example: true
        knowledge_base_id:
          description: >-
            The unique identifier of the `Knowledge Base` that was used for the
            `Chat`.
          maxLength: 28
          pattern: ^kb_[a-zA-Z0-9]{25}$
          type: string
          example: kb_feMfJbeqbAEj4u8K5HqmKpUbY
      required:
        - project_id
        - output_language
        - language_level
        - answer
        - markdown_response
        - knowledge_base_id
    OutputLanguage:
      title: OutputLanguage
      description: >
        The ISO 639-1 code for the language in which the `Explanation` should be
        generated.

        Supported Languages:

        - ar: Arabic

        - bs: Bosnian

        - cs: Czech

        - de: German

        - es: Spanish

        - en: English

        - fa: Farsi

        - fr: French

        - hr: Croatian

        - hu: Hungarian

        - it: Italian

        - pl: Polish

        - ro: Romanian

        - sk: Slovak

        - sl: Slovenian

        - sr: Serbian

        - tl: Tagalog

        - tr: Turkish

        - uk: Ukrainian

        - zh: Mandarin
      type: string
      enum:
        - ar
        - bs
        - cs
        - de
        - es
        - en
        - fa
        - fr
        - hr
        - hu
        - it
        - pl
        - ro
        - sk
        - sl
        - sr
        - tl
        - tr
        - uk
        - zh
      example: en
    LanguageLevel:
      title: LanguageLevel
      description: >
        One of three language levels for the generated text:

        1. Simple Language: Answers are short and simple, using easy words and a
        clear structure.

        2. Plain Language: Answers are short and the assistant explains
        complicated terms.

        3. Detailed Language: Answers are not simplified and the assistant
        answers in detail.
      type: string
      enum:
        - simple
        - plain
        - detailed
      example: plain
    Message:
      title: Message
      description: >
        Represents a message within an `Explanation` or a `Knowledge Base Chat`.

        For `Explanations` - An `assistant` message is either an initial
        `Explanation` for the document when no messages were provided in the
        request or an answer to a user message in the provided conversation
        history.
      type: object
      additionalProperties: false
      properties:
        role:
          description: The entity that produced the message. One of `user` or `assistant`.
          type: string
          enum:
            - user
            - assistant
        content:
          description: The content of the message. The maximum length is 16,000 characters.
          type: string
          maxLength: 16000
        references:
          type: array
          items:
            $ref: '#/components/schemas/Reference'
          maxItems: 50
      required:
        - role
        - content
      example:
        role: assistant
        content: >-
          Hi!

          The co-founders of Totoy are Benedikt Hielscher, Francis Rafal, Marcel
          Koller, Michael Perger and Simon Hoffmann.[R1]
    Problem:
      title: Problem
      description: A Response Body for HTTP Problem Details in RFC 9457 format.
      type: object
      additionalProperties: false
      properties:
        type:
          description: A URI reference that identifies the problem type.
          type: string
          maxLength: 512
          example: https://docs.totoy.ai/probs/out-of-credit
        title:
          description: A short, human-readable summary of the problem type.
          type: string
          maxLength: 512
          example: You do not have enough credit.
        status:
          description: >-
            The HTTP status code generated by the origin server for this
            occurrence of the problem.
          type: integer
          format: int32
          example: 403
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          type: string
          maxLength: 4096
          example: You do not have enough credit to perform this operation.
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          type: string
          maxLength: 512
          example: /projects/pj_avX7imfLaPcQnv5ckvGlOEBA9
    Reference:
      title: Reference
      description: >
        Represents a reference to a `Source` that was used to generate the
        answer.

        The reference is used to provide backlinks to the original source and to
        provide context for the generated answer.
      type: object
      additionalProperties: false
      properties:
        text:
          description: String in the message content that needs to be replaced.
          type: string
          maxLength: 8
          example: '[R1]'
        source_id:
          description: What `Source` the generated answer depended on.
          maxLength: 29
          pattern: ^src_[a-zA-Z0-9]{25}$
          type: string
        page_number:
          description: >-
            The page number in the `Source` the generated answer depended on.
            Only applicable for documents.
          type: integer
          format: int32
          example: 5
          nullable: true
          minimum: 1
          maximum: 1000
        backlink:
          description: The backlink of the `Source`, so it can be called from the client.
          type: string
          maxLength: 512
          example: https://www.example.com/text.pdf
        custom_metadata:
          $ref: '#/components/schemas/CustomMetadata'
      required:
        - text
        - source_id
      example:
        text: '[R1]'
        source_id: src_oXiYDg8QOc9JsOk86idRXiywD
        page_number: 5
        backlink: https://www.totoy.ai/totoy-company-overview.pdf
        custom_metadata:
          internal_tag: general_documents
    CustomMetadata:
      title: CustomMetadata
      description: >-
        Custom optional metadata for a `Source` provided by a client. Up to 10
        key-value pairs.
      type: object
      additionalProperties: true
      maxProperties: 10
      example:
        internal_tag: general_documents
  examples:
    knowledge-base-chat-request-example-1:
      summary: Knowledge Base Chat Request Example 1
      description: >-
        An example for requesting a plain English answer to a question to a
        `Knowledge Base`.
      value:
        output_language: en
        language_level: plain
        markdown_response: true
        messages:
          - role: user
            content: Who are the co-founders of Totoy?
    knowledge-base-chat-request-example-2:
      summary: Knowledge Base Chat Request Example 2
      description: >-
        An example for requesting a plain English answer to a follow-up question
        to a `Knowledge Base`, based on the response to a previous question.
      value:
        output_language: en
        language_level: plain
        messages:
          - role: user
            content: Who are the co-founders of Totoy?
          - role: assistant
            content: >-
              Hi!

              The co-founders of Totoy are Benedikt Hielscher, Francis Rafal,
              Marcel Koller, Michael Perger and Simon Hoffmann.[R1]
            references:
              - text: '[R1]'
                source_id: src_oXiYDg8QOc9JsOk86idRXiywD
                page_number: 5
                backlink: https://www.totoy.ai/totoy-company-overview.pdf
                custom_metadata:
                  internal_tag: general_documents
          - role: user
            content: What are they trying to achieve?
        markdown_response: true
    knowledge-base-chat-response-example-1:
      summary: Knowledge Base Chat Response Example 1
      description: >-
        An example for a generated plain English answer to a question to a
        `Knowledge Base`.
      value:
        project_id: pj_avX7imfLaPcQnv5ckvGlOEBA9
        output_language: en
        language_level: plain
        answer:
          role: assistant
          content: >-
            Hi!

            The co-founders of Totoy are Benedikt Hielscher, Francis Rafal,
            Marcel Koller, Michael Perger and Simon Hoffmann.[R1]
          references:
            - text: '[R1]'
              source_id: src_oXiYDg8QOc9JsOk86idRXiywD
              page_number: 5
              backlink: https://www.totoy.ai/totoy-company-overview.pdf
              custom_metadata:
                internal_tag: general_documents
        knowledge_base_id: kb_feMfJbeqbAEj4u8K5HqmKpUbY
        markdown_response: true
    knowledge-base-chat-response-example-2:
      summary: Knowledge Base Chat Response Example 2
      description: >-
        An example for a generated plain English answer to a follow-up question
        to a `Knowledge Base` from Knowledge Base Chat Request Example 2.
      value:
        project_id: pj_avX7imfLaPcQnv5ckvGlOEBA9
        output_language: en
        language_level: plain
        answer:
          role: assistant
          content: >-
            They want to solve functional illiteracy[R1]. They want to achieve
            that by making complicated documents understandable for
            everyone.[R2]
          references:
            - text: '[R1]'
              source_id: src_oXiYDg8QOc9JsOk86idRXiywD
              page_number: 1
              backlink: https://www.totoy.ai/totoy-company-overview.pdf
              custom_metadata:
                internal_tag: general_documents
            - text: '[R2]'
              source_id: src_oXiYDg8QOc9JsOk86idRXiywD
              page_number: 2
              backlink: https://www.totoy.ai/totoy-company-overview.pdf
              custom_metadata:
                internal_tag: general_documents
        knowledge_base_id: kb_feMfJbeqbAEj4u8K5HqmKpUbY
        markdown_response: true
    knowledge-base-id-example:
      summary: Knowledge Base ID Example
      description: An example for a `knowledge_base_id`.
      value: kb_feMfJbeqbAEj4u8K5HqmKpUbY
  responses:
    general4XXResponse:
      description: Client Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    general5XXResponse:
      description: Server Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer

````