> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/character-crafting-apis/mindview-api.md).

# Mindview API

{% hint style="danger" %}
此 API 仅适用于专业版及以上套餐。
{% endhint %}

## 获取 MindView 的提示词

<mark style="color:绿色;">`POST`</mark> `https://api.convai.com/character/chatHistory/get_prompt`

以以下两种方式之一获取 MindView 的提示数据：

1. **会话模式** (`session_id`）：从存储的交互记录中读取提示数据。
2. **角色模式** (`character_id` 仅）：从当前角色配置生成静态提示数据。

#### 请求头

| 名称                                              | 类型  | 描述                                            |
| ----------------------------------------------- | --- | --------------------------------------------- |
| CONVAI-API-KEY<mark style="color:红色;">\*</mark> | 字符串 | 为每位用户提供的唯一 api-key。登录您的 Convai 账户后，可在钥匙图标下找到。 |

#### 请求正文

| 名称            | 类型  | 描述                                         |
| ------------- | --- | ------------------------------------------ |
| session\_id   | 字符串 | 会话标识符。若提供，API 将以会话模式运行。                    |
| character\_id | 字符串 | 角色标识符。用于 `session_id` 未提供。                 |
| offset        | 整数  | 可选。仅与 `session_id`一起使用。默认 `-1` 返回最新的提示词记录。 |

> 至少需要以下之一： `session_id` 或 `character_id` 为必需。

{% tabs %}
{% tab title="200：成功（会话模式响应）" %}

```json
{
  "prompt_id": "f2f8a75e-...",
  "prompt": "[{\"role\":\"system\",\"content\":\"...\"}]",
  "model": "gpt-4o-mini",
  "temperature": 0.7,
  "max_tokens": 512,
  "top_p": 1.0,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.0,
  "stop": null,
  "session_id": "sess_123",
  "mindview": "{\"static_prompt\": {...}, \"dynamic_prompt\": {...}}"
}
```

{% endtab %}

{% tab title="200：成功（角色模式响应）" %}

```json
{
  "mindview": "{\"static_prompt\": {...}, \"dynamic_prompt\": {...}}",
  "model": "gpt-4o-mini"
}
```

{% endtab %}

{% tab title="400：错误请求" %}

```json
{
  "ERROR": "必须提供 session_id 或 character_id 之一",
  "Reference ID": "<transaction_id>"
}
```

```json
{
  "ERROR": "offset 必须是有效整数",
  "Reference ID": "<transaction_id>"
}
```

```json
{
  "ERROR": "Offset 大于记录数",
  "Reference ID": "<transaction_id>"
}
```

{% endtab %}
{% endtabs %}

以下是一些示例代码，用于演示该端点的请求格式 -->

#### 会话模式（`session_id`)

{% tabs %}
{% tab title="Python" %}

```python
import json
import requests

url = "https://api.convai.com/character/chatHistory/get_prompt"

headers = {
    "CONVAI-API-KEY": "<Your-API-Key>",
    "Content-Type": "application/json"
}

payload = {
    "session_id": "<Your-Session-ID>",
    "offset": -1
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)
```

{% endtab %}

{% tab title="cURL" %}

```shell
curl -X POST "https://api.convai.com/character/chatHistory/get_prompt" \
  -H "CONVAI-API-KEY: <Your-API-Key>" \
  -H "Content-Type: application/json" \
  -d '{"session_id":"<Your-Session-ID>","offset":-1}'
```

{% endtab %}
{% endtabs %}

#### 角色模式（`character_id`)

{% tabs %}
{% tab title="Python" %}

```python
import json
import requests

url = "https://api.convai.com/character/chatHistory/get_prompt"

headers = {
    "CONVAI-API-KEY": "<Your-API-Key>",
    "Content-Type": "application/json"
}

payload = {
    "character_id": "<Your-Character-ID>"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)
```

{% endtab %}

{% tab title="cURL" %}

```shell
curl -X POST "https://api.convai.com/character/chatHistory/get_prompt" \
  -H "CONVAI-API-KEY: <Your-API-Key>" \
  -H "Content-Type: application/json" \
  -d '{"character_id":"<Your-Character-ID>"}'
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
实现说明：

* 如果两者都 `session_id` 和 `character_id` 都提供，则使用会话模式。
* 在当前实现中， `mindview` 和 `提示词` 字段会序列化为 JSON 字符串。
  {% endhint %}


---

# 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:

```
GET https://docs.convai.com/api-docs/zh/api-can-kao/core-api-reference/character-crafting-apis/mindview-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
