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

# Query Knowledge Base

> Send a question to the specified knowledge base and receive a response. Optionally pass a conversation history for the assistant to take into consideration while generating responses.



## OpenAPI

````yaml https://api-prod.interactly.ai/api-docs/common/api.json post /kb/v1/knowledge-bases/{id}/query
openapi: 3.1.0
info:
  title: Interactly API
  description: API for building interactly.ai services
  version: 1.1.0
  contact:
    name: Interactly
    url: https://interactly.ai
    email: developers@interactly.ai
servers:
  - url: https://api-prod.interactly.ai
    description: API Server
security: []
paths:
  /kb/v1/knowledge-bases/{id}/query:
    post:
      tags:
        - Knowledge Bases
      summary: Query Knowledge Base
      description: >-
        Send a question to the specified knowledge base and receive a response.
        Optionally pass a conversation history for the assistant to take into
        consideration while generating responses.
      parameters:
        - name: id
          in: path
          required: true
          description: The ID of the knowledge base to train.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: >-
                    Optional parameter - The GPT model to use for generating
                    responses
                  default: gpt-4o
                  enum:
                    - gpt-4o
                    - gpt-4o-mini
                prompt:
                  type: string
                  description: >-
                    [DEPRECATED. USE "messages" instead] The query prompt to
                    send to the knowledge base.
                  deprecated: true
                messages:
                  type: array
                  items:
                    $ref: '#/components/schemas/KnowledgeBaseQueryMessageDTO'
                  description: >-
                    A list of messages to query with. Note that "messages" and
                    "prompt" cannot be used together. If both are found in the
                    request, "messages" takes precedence and "prompt" is
                    ignored.
                temperature:
                  type: number
                  minimum: 0
                  maximum: 2
                  example: 0.1
                  description: >-
                    Temperature controls the randomness in the output of the
                    underlying language model; while lower values produce
                    predictable and factual replies, higher values allow the
                    model to be creative and reword the responses.
                seed:
                  type: integer
                  example: 42
                  description: >-
                    Seed initializes the random number generator in the
                    underlying language model, ensuring reproducible outputs for
                    the same prompt and settings.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    Determines whether to stream the generated response back
                    instead of returning it all at once. When stream = true, the
                    response is a list of JSON objects of the form {"response":
                    string} separated by newline characters
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  response:
                    type: string
                    example: string
                    description: The response from the knowledge base.
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  details:
                    type: string
                    description: Error message.
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Authentication error message.
                  message:
                    type: string
                    description: Error message.
        '404':
          description: Knowledge base not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Error message indicating the knowledge base was not found.
      security:
        - bearer: []
components:
  schemas:
    KnowledgeBaseQueryMessageDTO:
      type: object
      description: >-
        An input message to the knowledge base model. At least one message with
        "role"="user" is required. A snapshot of the past questions and answers
        can be passed to allow the model to infer the context of the
        conversation. The messages are expected to appear in the array in their
        chronological order.
      properties:
        role:
          type: string
          example: user
          description: >-
            Use "role" = "user" for incoming queries, and "role" = "assistant"
            to provide the past responses from the knowledge base assistant
          enum:
            - user
            - assistant
        content:
          type: string
          example: What are the services offered?
      required:
        - role
        - content
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: Bearer
      type: http
      description: >-
        Retrieve your API Key from [Dashboard API Keys
        Section](https://dashboard.interactly.ai/api-keys).

````