> 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/chat-history-delete-api.md).

# 聊天历史删除 API

{% hint style="danger" %}
此 API 仅向部分客户开放。
{% endhint %}

## 删除角色的会话

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

#### 请求头

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

#### 请求体

| 名称                                      | 类型  | 说明            |
| --------------------------------------- | --- | ------------- |
| charID<mark style="color:红色;">\*</mark> | 字符串 | 你的角色 ID。      |
| 会话ID<mark style="color:红色;">\*</mark>   | 列表  | 要删除的会话 ID 列表。 |

{% tabs %}
{% tab title="200：成功" %}

```json
{
  "status": "删除成功"
}
```

{% endtab %}

{% tab title="401 API 密钥验证失败" %}

```json
{
    "ERROR": "提供的 API 密钥无效。"
}
```

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import requests
import json

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

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

# 为 JSON 负载创建一个字典
payload = { 
    "charID": "<Your-Character-Id>",
    "sessionIDs": ["<your-session-id-1>",] 
}

# 将负载转换为 JSON
json_payload = json.dumps(payload)

response = requests.post(url, headers=headers, data=json_payload)

print(response.json())
```

{% endcode %}
{% endtab %}

{% tab title="cURL" %}

```sh
curl -X POST "https://api.convai.com/character/chatHistory/delete" \
     -H "CONVAI-API-KEY: <Your-API-Key>" \\
     -H "Content-Type: application/json" \
     -d '{"charID": "<Your-Character-Id>", "sessionIDs": ["<your-session-id-1>"]}'
```

{% endtab %}
{% endtabs %}


---

# 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/chat-history-delete-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.
