> 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 仅适用于 Professional 计划及更高级别的计划。
{% 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 密钥。登录 Convai 账户后，可在密钥图标下找到。 |

#### 请求正文

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

> 必须提供 `session_id` 或 `character_id` 中的至少一个。

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

```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：OK（角色模式响应）" %}

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

{% endtab %}

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

```json
{
  "ERROR": "Either session_id or character_id is required",
  "Reference ID": "<transaction_id>"
}
```

```json
{
  "ERROR": "offset must be a valid integer",
  "Reference ID": "<transaction_id>"
}
```

```json
{
  "ERROR": "Offset is greater than the number of records",
  "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` 和 `prompt` 字段会被序列化为 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
