> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/api/api-doc-en/api-reference/dui-hua-widget.md).

# Conversation Widget

### Get a specific Web Chat <a href="#web-chat" id="web-chat"></a>

GET `/api/web-chats/{id}/`

#### Parameters

| Parameter Name | Required | Type   | Description                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this web chat. |

#### Code Examples

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# API Call Example (Shell)
curl -X GET "https://api.maiagent.ai/api/web-chats/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Please make sure to replace YOUR_API_KEY and verify the request data before execution.
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/web-chats/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('Successfully retrieved response:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('An error occurred with the request:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/web-chats/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("Successfully retrieved response:")
    print(response.json())
except Exception as e:
    print("An error occurred during the request:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = 'https://api.maiagent.ai/api/web-chats/550e8400-e29b-41d4-a716-446655440000/';
    $response = $client->get("https://api.maiagent.ai/api/web-chats/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Successfully retrieved response:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Response Schema Example**

```typescript
{
  "id": string (uuid)
  "name": string
  "avatar"?: string (uri) // optional
  "logo"?: string (uri) // optional
  "description"?: string // optional
  "cover"?: string (uri) // optional
  "backUrl"?: string // optional
  "isActive"?: boolean // optional
  "enableSpeech": boolean
  "displayGreeting": string
  "displayConversationStarters": [
    string
  ]
  "theme": {
  {
    "primaryColor"?: string // optional
    "navbarTextColor"?: string // optional
    "conversationBackgroundColor"?: string // optional
    "chatbotMessageTextColor"?: string // optional
    "userMessageTextColor"?: string // optional
    "chatbotMessageBackgroundColor"?: string // optional
    "userMessageBackgroundColor"?: string // optional
    "chatbotMessageBackgroundShadowEnabled"?: boolean // optional
    "userMessageBackgroundShadowEnabled"?: boolean // optional
  }
  }
  "darkTheme": {
  {
    "primaryColor"?: string // optional
    "navbarTextColor"?: string // optional
    "conversationBackgroundColor"?: string // optional
    "chatbotMessageTextColor"?: string // optional
    "userMessageTextColor"?: string // optional
    "chatbotMessageBackgroundColor"?: string // optional
    "userMessageBackgroundColor"?: string // optional
    "chatbotMessageBackgroundShadowEnabled"?: boolean // optional
    "userMessageBackgroundShadowEnabled"?: boolean // optional
  }
  }
  "enableFileUpload"?: boolean // optional
  "enableDisplayCitations"?: boolean // optional
  "enableDisplayToolResults"?: boolean // optional
  "enableShareConversation"?: boolean // optional
  "enableLocation"?: boolean // optional
  "enableShowPoweredBy"?: boolean // optional
  "poweredByLogo"?: string (uri) // optional
  "enableAnonymous"?: boolean // optional
  "accessType": 
  {
  }
  "enableThemeModeToggle"?: boolean // optional
  "defaultThemeMode"?:  // optional
  {
  }
  "enableDownloadCitations"?: boolean // optional
  "customDomain"?:  // optional
  {
    "id": string (uuid)
    "domain": string
    "status": 
    {
    }
  }
  "enableDisplayChatbotAvatar"?: boolean // optional
  "enableDisplayChatbotName"?: boolean // optional
  "inbox": object
}
```

**Response Example Value**

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "name": "Test doc",
  "avatar": "https://example.com/static/images/default-chatbot-avatar.png",
  "logo": null,
  "description": "",
  "cover": null,
  "backUrl": "",
  "isActive": true,
  "enableSpeech": false,
  "displayGreeting": null,
  "displayConversationStarters": [],
  "theme": {
    "primaryColor": "#3854d8",
    "dialogColor": "#ddeaf6",
    "navbarTextColor": "#ffffff"
  },
  "enableFileUpload": true,
  "enableDisplayCitations": true,
  "enableShareConversation": false,
  "enableLocation": false,
  "enableShowPoweredBy": true,
  "poweredByLogo": null,
  "accessType": "web",
  "inbox": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Test doc",
    "signAuth": {
      "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
      "signSource": {
        "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
        "accessType": "keycloak"
      },
      "signParams": {
        "keycloak": {
          "url": "example.com",
          "realm": "example",
          "clientId": "example"
        }
      }
    }
  }
}
```

***

### Get LLM Usage Statistics <a href="#llm" id="llm"></a>

GET `/api/chatbots/{chatbotPk}/llm-usage-statistics/`

#### Parameters

| Parameter Name    | Required | Type   | Description                               |
| ----------------- | -------- | ------ | ----------------------------------------- |
| `chatbotPk`       | ✅        | string | A UUID string identifying this Chatbot ID |
| `endDate`         | ❌        | string | End date, format: YYYY-MM-DD              |
| `startDate`       | ✅        | string | Start date, format: YYYY-MM-DD            |
| `timeGranularity` | ✅        | string | Time granularity (day/month)              |

#### Code Examples

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# API Call Example (Shell)
curl -X GET "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/llm-usage-statistics/?endDate=example&startDate=example&timeGranularity=day" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Please replace YOUR_API_KEY and verify the request data before execution.
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/llm-usage-statistics/?endDate=example&startDate=example&timeGranularity=day", config)
  .then(response => {
    console.log('Successfully retrieved response:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('An error occurred with the request:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/llm-usage-statistics/?endDate=example&startDate=example&timeGranularity=day"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("Successfully got response:")
    print(response.json())
except Exception as e:
    print("Request failed:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/llm-usage-statistics/?endDate=example&startDate=example&timeGranularity=day", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response retrieved successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Error during request: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Response Schema Example**

```typescript
[
  {
    "chatbotId": string (uuid)
    "wordsCount"?: integer (int64) // Optional
    "llmModelId": string
    "llmModelName": string
    "llmModelProvider": string
    "date": string (date)
    "totalWordsCount": integer // Calculate the total word count for a specific date and organization
    "llmDetails": [ // Get all model records for the same date and organization
      object
    ]
  }
]
```

**Response Example Value**

```json
[
  [
    {
      "totalWordsCount": 511,
      "month": "2025-03-01",
      "llmDetails": [
        {
          "chatbotId": "5b646600-f6e0-4f07-aec7-0207a26c0a9b",
          "wordsCount": 511,
          "llmModelId": "d4282719-f50e-4a82-88d0-953e202a3383",
          "llmModelName": "GPT-4o-2024-08-06",
          "llmModelProvider": "openai"
        }
      ]
    }
  ]
]
```

**Status Code: 400**

**Response Schema Example**

```typescript
{
  "detail"?: string // Optional
  "valid_types"?: [ // Optional
    string
  ]
}
```

**Response Example Value**

```json
[
  [
    {
      "totalWordsCount": 511,
      "month": "2025-03-01",
      "llmDetails": [
        {
          "chatbotId": "5b646600-f6e0-4f07-aec7-0207a26c0a9b",
          "wordsCount": 511,
          "llmModelId": "d4282719-f50e-4a82-88d0-953e202a3383",
          "llmModelName": "GPT-4o-2024-08-06",
          "llmModelProvider": "openai"
        }
      ]
    }
  ]
]
```

***

### Get AI Assistant Statistics <a href="#ai" id="ai"></a>

GET `/api/chatbots/{chatbotPk}/statistics/`

#### Parameters

| Parameter Name    | Required | Type   | Description                               |
| ----------------- | -------- | ------ | ----------------------------------------- |
| `chatbotPk`       | ✅        | string | A UUID string identifying this Chatbot ID |
| `datetimeFrom`    | ❌        | string | Start time                                |
| `datetimeTo`      | ❌        | string | End time                                  |
| `timeGranularity` | ❌        | string | Time granularity (hour/day/month)         |

#### Code Examples

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# API Call Example (Shell)
curl -X GET "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/statistics/?datetimeFrom=example&datetimeTo=example&timeGranularity=example" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Please replace YOUR_API_KEY and verify the request data before execution.
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/statistics/?datetimeFrom=example&datetimeTo=example&timeGranularity=example", config)
  .then(response => {
    console.log('Successfully received response:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('An error occurred with the request:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/statistics/?datetimeFrom=example&datetimeTo=example&timeGranularity=example"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("Successfully retrieved response:")
    print(response.json())
except Exception as e:
    print("An error occurred with the request:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/statistics/?datetimeFrom=example&datetimeTo=example&timeGranularity=example", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Successfully received response:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'An error occurred with the request: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Response Schema Example**

```typescript
[
  {
    "datetime": string (timestamp)
    "messagesCount"?: integer // Optional
    "conversationsCount"?: integer // Optional
    "avgMessagesPerConversation": number (double)
    "avgLikesPerFeedback": number (double)
  }
]
```

**Response Example Value**

```json
[
  {
    "datetime": "Response String",
    "messagesCount": 456,
    "conversationsCount": 456,
    "avgMessagesPerConversation": 456,
    "avgLikesPerFeedback": 456
  }
]
```

***

### Enable or Disable Evaluation for a Specific AI Assistant <a href="#ai" id="ai"></a>

PATCH `/api/chatbots/{id}/enable-evaluation/`

#### Parameters

| Parameter Name | Required | Type   | Description                             |
| -------------- | -------- | ------ | --------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this Chatbot. |

#### Request Body

**Request Parameters**

| Field            | Type    | Required | Description |
| ---------------- | ------- | -------- | ----------- |
| enableEvaluation | boolean | No       |             |

**Request Structure Example**

```typescript
{
  "enableEvaluation"?: boolean // Optional
}
```

**Request Example Value**

```json
{
  "enableEvaluation": true
}
```

#### Code Examples

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# API Call Example (Shell)
curl -X PATCH "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/enable-evaluation/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "enableEvaluation": true
  }'

# Please replace YOUR_API_KEY and verify the request data before execution.
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request payload
const data = {
    "enableEvaluation": true
  };

axios.patch("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/enable-evaluation/", data, config)
  .then(response => {
    console.log('Successfully received response:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('An error occurred with the request:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/enable-evaluation/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# Request payload
data = {
      "enableEvaluation": true
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("Successfully got response:")
    print(response.json())
except Exception as e:
    print("Request failed:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/enable-evaluation/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "enableEvaluation": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Response Schema Example**

```typescript
{
  "enableEvaluation"?: boolean // Optional
}
```

**Response Example Value**

```json
{
  "enableEvaluation": false
}
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/api/api-doc-en/api-reference/dui-hua-widget.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
