Chats

Chats are a fundamental part of Doctrine, allowing users to have conversations with their documents. On this page, we'll dive into the different Chat endpoints you can use to manage Chats programmatically. We'll look at how to create, update, delete, and query chats.

Properties

  • Name
    id
    Type
    string
    Description

    Unique identifier for the chat.

  • Name
    createdAt
    Type
    DateTime
    Description

    Timestamp of when the chat was created. It is created by default at the time of creation.

  • Name
    name
    Type
    string
    Description

    The name of the chat.

  • Name
    userId
    Type
    string
    Description

    The unique identifier of the user who created the chat.

  • Name
    organizationId
    Type
    string
    Description

    The unique identifier of the organization associated with the chat.

  • Name
    documentId
    Type
    string
    Description

    The unique identifier of the document associated with the chat. This is an optional field.

  • Name
    partitionId
    Type
    string
    Description

    The unique identifier of the partition associated with the chat. This is an optional field.

  • Name
    public
    Type
    boolean
    Description

    A boolean indicating whether the chat is public or not.

  • Name
    title
    Type
    string
    Description

    The title of the chat. This is an optional field.

  • Name
    logoUrl
    Type
    string
    Description

    The URL of the logo associated with the chat. This is an optional field.

  • Name
    brandSettings
    Type
    Json
    Description

    Brand settings associated with the chat in the form of a JSON object. This is an optional field.


GET/api/chat/:id

Get a chat

This endpoint allows you to retrieve a single chat by its unique identifier, along with its messages.

Required attributes

  • Name
    id
    Type
    string
    Description

    The unique identifier of the chat you want to retrieve.

Request

GET
/api/chat/{chatId}
curl -G https://doctrine.app/api/chat/{chatId} \
  -H "Authorization: Bearer {token}"

Response

{
    "id": "cljkeep9f0002332ox29hf6gp",
    "createdAt": "2023-07-01T19:30:34.463Z",
    "userId": "user_2DJLgLH0pKb3waM1IDb8tvxZeCh",
    "organizationId": "org_2OqDZQgHxncrBewRtL63l349HPA",
    "documentId": "doc_2OqDZQgHxncrBewRtL63l349HPA",
    "partitionId": null,
    "public": true,
    "title": "Sample title",
    "logoUrl": "https://doctrine.app/logo.png",
    "brandSettings": { ... },
    "messages": [
        {
            "id": "msg_1",
            "message": "Hello, world!",
            "isSystem": false, // True means the message was sent by the AI.
            "organizationId": "dddd",
            "chatId": "cljkeep9f0002332ox29hf6gp",
            "organizationId": "org_2OqDZQgHxncrBewRtL63l349HPA",
            "createdAt": "2023-07-01T19:31:00.000Z",
            "userId": "user_2DJLgLH0pKb3waM1IDb8tvxZeCh",
            "sourceDocuments": [
              {
                "metadata": { "id": "doc_Id", "content": "Relevant content", "_distance": 0.28 },
                "pageContent": "Relevant content from the page where the message was found."
              }
            ]
        },
        // More messages...
    ]
}


GET/api/chat

List all chats

This endpoint allows you to retrieve a paginated list of all your chats. By default, a maximum of ten chats are shown per page.

Optional attributes

  • Name
    limit
    Type
    integer
    Description

    Limit the number of chats returned.

  • Name
    skip
    Type
    integer
    Description

    Skip x records, useful for pagination.

  • Name
    sortBy
    Type
    string
    Description

    Sort the chats by a specific field. The default is "createdAt".

  • Name
    searchValue
    Type
    string
    Description

    Search for chats by name.

Request

GET
/api/chat
curl -G https://doctrine.app/api/chat \
  -H "Authorization: Bearer {token}" \
  -d skip=0 \
  -d limit=10

Response


  [
      {
          "id": "WAz8eIbvDR60rouK",
          "name": "Sample chat",
          "createdAt": "2023-07-03T10:20:16.298Z",
          "userId": "user_2DJLgLH0pKb3waM1IDb8tvxZeCh",
          "organizationId": "org_2OqDZQgHxncrBewRtL63l349HPA",
          "public": true,
          "title": "Sample title",
          "logoUrl": "https://doctrine.app/logo.png",
          "brandSettings": { ... }
      },
      {
          "id": "hSIhXBhNe8X1d8Et"
          // ...
      }
  ]


POST/api/chat

Create a chat

This endpoint allows you to create a new chat.

Optional attributes

  • Name
    title
    Type
    string
    Description

    The title of the chat.

  • Name
    documentId
    Type
    string
    Description

    The unique identifier of the document you'd like to chat with.

  • Name
    partitionId
    Type
    string
    Description

    The unique identifier of the partition you'd like to chat with.

  • Name
    userId
    Type
    string
    Description

    The unique identifier of the user who is chatting, this helps maintain multiple chat sessions with different users.

  • Name
    logoUrl
    Type
    string
    Description

    If you are embedding the chat in your website, you can set a logo URL to be displayed in the chat header.

  • Name
    public
    Type
    boolean
    Description

    A boolean indicating whether the chat is public or not. Public chats can be embedded or shown anywhere, with no need for authentication.

Request

PUT
/api/chat/{chatId}
curl -X POST https://doctrine.app/api/chat/{chatId} \
  -H "Authorization: Bearer {token}" \
  -d title="New chat!"

Response

{
    "id": "cljkeep9f0002332ox29hf6gp",
    "createdAt": "2023-07-01T19:30:34.463Z",

    "userId": "user_2DJLgLH0pKb3waM1IDb8tvxZeCh",
    "organizationId": "org_2OqDZQgHxncrBewRtL63l349HPA",
    "documentId": "doc_2OqDZQgHxncrBewRtL63l349HPA",
    "partitionId": null,
    "public": true,
    "title": "Sample title",
    "logoUrl": "https://doctrine.app/logo.png",
    "brandSettings": { ... }
}


POST/api/chat/:id/private

Send a message to a chat

This endpoint allows you to send a message to a private chat. The response will be a message object.

Required attributes

  • Name
    id
    Type
    string
    Description

    The unique identifier of the chat you want to send a message to.

  • Name
    message
    Type
    string
    Description

    The content of the message you want to send.

  • Name
    userId
    Type
    string
    Description

    The unique identifier of the user who is sending the message, this is optional - if you do not pass it we will set it to the authenticated user (based on API key).

Request

POST
/api/chat/{chatId}/message
curl -X POST https://doctrine.app/api/chat/{chatId}/message \
  -H "Authorization: Bearer {token}" \
  -d message="Hello, world!" \
  -d userId="{userId}"

Response

{
    "id": "msg_1",
    "message": "Hello, world!",
    "isSystem": false,
    "organizationId": "org_2OqDZQgHxncrBewRtL63l349HPA",
    "chatId": "cljkeep9f0002332ox29hf6gp",
    "createdAt": "2023-07-01T19:31:00.000Z",
    "userId": "user_2DJLgLH0pKb3waM1IDb8tvxZeCh",
    "sourceDocuments": [
      {
        "metadata": { "id": "doc_Id", "content": "Relevant content", "_distance": 0.28 },
        "pageContent": "Relevant content from the page where the message was found."
      }
    ]
}


DELETE/chat/:id

Delete a chat

This endpoint allows you to delete chats.

Request

DELETE
/chat/{chatId}
curl -X DELETE https://doctrine.app/api/chat/{chatId} \
  -H "Authorization: Bearer {token}"