> 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/custom-llm-api.md). Agents can also search and read this documentation through its [MCP server](https://docs.convai.com/api-docs/~gitbook/mcp).

# 自定义 LLM API

在 Convai 上管理你的私有 LLM 集成。通过简单的 API 端点安全地注册、更新或删除与 OpenAI 兼容的自定义模型。

{% hint style="danger" %}
自定义 LLM 集成仅适用于企业版套餐。
{% endhint %}

## 简介

以下 **Convai 自定义 LLM 模型 API** 允许开发者和企业在 Convai 平台上注册和管理自己的 **自定义大型语言模型（LLM）** 。借助这些端点，您可以连接私有的、兼容 OpenAI 的 LLM，控制访问权限，并管理注册、更新和移除等生命周期事件。

所有端点均使用 **POST** 请求，并且都接受和返回 **JSON** 对象。

{% embed url="<https://youtu.be/OKXXqby0bcs>" %}

***

## 基础 URL

```
https://api.convai.com
```

***

## 身份验证

每个请求都必须在标头中包含您的 Convai API 密钥。否则，请求会返回 **401 Unauthorized**.

| 标头                 | 说明        | 示例                           |
| ------------------ | --------- | ---------------------------- |
| **CONVAI-API-KEY** | 每个请求都必须提供 | `245a4u6864dj6848516l2dr6df` |

缺少或无效密钥时的错误示例：

```json
{
  "status": "error",
  "message": "Unauthorized: missing or invalid CONVAI-API-KEY",
  "transactionID": "..."
}
```

***

## 通用响应字段

所有端点的响应都采用以下基本结构。

| 字段                |  类型 |          说明         |
| ----------------- | :-: | :-----------------: |
| **status**        | 字符串 | "success" 或 "error" |
| **message**       | 字符串 |       便于理解的摘要       |
| **transactionID** | 字符串 |      用于追踪的唯一标识符     |
| **...**           |  —  |        端点专属数据       |

***

## 端点参考

| #                                        | 方法和路径                         | 用途                     |
| ---------------------------------------- | ----------------------------- | ---------------------- |
| [**2.1 注册模型**](#id-2.1-register-a-model) | `POST /llm-models/register`   | 注册新的自定义模型              |
| [**2.2 更新模型**](#id-2.2-update-a-model)   | `POST /llm-models/update`     | 更新现有的自定义模型             |
| [**2.3 注销模型**](#id-2.2-update-a-model)   | `POST /llm-models/deregister` | 移除已注册的模型               |
| [**2.4 列出模型**](#id-2.4-list-models)      | `POST /llm-models/list`       | 列出与您的 API 密钥关联的所有自定义模型 |

***

### 2.1 注册模型

**端点：**

<mark style="color:绿色;">`POST`</mark> `https://api.convai.com/llm-models/register`

#### 请求正文

<table><thead><tr><th width="211.6666259765625">字段</th><th width="93">类型</th><th width="124.3331298828125" align="center" valign="middle">必填</th><th align="center">备注</th></tr></thead><tbody><tr><td><strong>model_group_name</strong></td><td>字符串</td><td align="center" valign="middle">✓</td><td align="center">唯一且不可变的标识符</td></tr><tr><td><strong>model_name</strong></td><td>字符串</td><td align="center" valign="middle">✓</td><td align="center">模型名称，例如 "gpt-4o-mini"</td></tr><tr><td><strong>api_key</strong></td><td>字符串</td><td align="center" valign="middle">✓</td><td align="center">远程 LLM 端点的密钥</td></tr><tr><td><strong>is_uncensored</strong></td><td>布尔值</td><td align="center" valign="middle">✓</td><td align="center">如果不受越狱限制，则为 True</td></tr><tr><td><strong>display_name</strong></td><td>字符串</td><td align="center" valign="middle">—</td><td align="center">可选的 UI 标签（默认为组名称）</td></tr><tr><td><strong>base_url</strong></td><td>字符串</td><td align="center" valign="middle">—</td><td align="center">兼容 OpenAI 的端点（默认值： <code>https://api.openai.com/v1</code>)</td></tr></tbody></table>

#### cURL 示例

{% tabs %}
{% tab title="MacOS/Linux" %}

```bash
curl -X POST https://api.convai.com/llm-models/register \
  -H "Content-Type: application/json" \
  -H "CONVAI-API-KEY: YOUR_API_KEY" \
  -d '{
        "model_group_name": "my-turbo",
        "model_name": "gpt-4o-mini",
        "api_key": "sk-proxy-123",
        "is_uncensored": false,
        "display_name": "Turbo (Private)",
        "base_url": "https://api.openai.com/v1"
      }'
```

{% endtab %}

{% tab title="Windows" %}
{% code overflow="wrap" %}

```powershell
curl -X POST "https://api.convai.com/llm-models/register" -H "Content-Type: application/json" -H "CONVAI-API-KEY: YOUR_API_KEY" -d "{\"model_group_name\": \"my-turbo\", \"model_name\": \"gpt-4o-mini\", \"api_key\": \"sk-proxy-123\", \"is_uncensored\": false, \"display_name\": \"Turbo (Private)\", \"base_url\": \"https://api.openai.com/v1\"}"
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### 成功响应（200 OK）

```json
{
  "status": "success",
  "model_group_name": "my-turbo",
  "model_name": "gpt-4o-mini",
  "display_name": "Turbo (Private)",
  "message": "Model 'my-turbo' registered successfully",
  "transactionID": "14b0cf96-5230-4b0f-a971-2f4f4f6d5e6a"
}
```

#### 可能的错误

| 代码  | 消息       | 原因      |
| --- | -------- | ------- |
| 400 | 缺少必填字段   | 验证失败    |
| 409 | 模型组名称已存在 | 标识符重复   |
| 500 | 数据库错误    | 服务器内部错误 |

***

### 2.2 更新模型

**端点：**

<mark style="color:绿色;">`POST`</mark> `https://api.convai.com/llm-models/update`

#### 请求正文

| 字段                     |  类型 |  必填 |     备注     |
| ---------------------- | :-: | :-: | :--------: |
| **model\_group\_name** | 字符串 |  ✓  |   要更新的模型   |
| **display\_name**      | 字符串 |  —  |   新的易读名称   |
| **base\_url**          | 字符串 |  —  | 更新后的端点 URL |
| **api\_key**           | 字符串 |  —  |  新的 API 密钥 |
| **is\_uncensored**     | 布尔值 |  —  |   切换内容审查   |

至少需要提供一个可选字段。

#### cURL 示例

{% tabs %}
{% tab title="MacOS/Linux" %}

```bash
curl -X POST https://api.convai.com/llm-models/update \
  -H "Content-Type: application/json" \
  -H "CONVAI-API-KEY: YOUR_API_KEY" \
  -d '{
        "model_group_name": "my-turbo",
        "display_name": "Turbo v2",
        "api_key": "sk-proxy-456"
      }'
```

{% endtab %}

{% tab title="Windows" %}
{% code overflow="wrap" %}

```powershell
curl -X POST "https://api.convai.com/llm-models/update" -H "Content-Type: application/json" -H "CONVAI-API-KEY: YOUR_API_KEY" -d "{\"model_group_name\": \"my-turbo\", \"display_name\": \"Turbo v2\", \"api_key\": \"sk-proxy-456\"}"
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### 成功响应（200 OK）

```json
{
  "status": "success",
  "message": "模型 'my-turbo' 已成功更新",
  "updated_fields": ["display_name", "api_key"],
  "transactionID": "5c0b6c67-97e4-4d78-9d5c-2a3de9d9c8ee"
}
```

#### 可能的错误

| 代码  | 消息        | 原因          |
| --- | --------- | ----------- |
| 404 | 未找到模型     | 模型名称无效或未获授权 |
| 409 | 显示名称已存在   | 用户标签重复      |
| 400 | 没有有效字段可更新 | 缺少可更新字段     |

***

### 2.3 注销模型

**端点：**

<mark style="color:绿色;">`POST`</mark> `https://api.convai.com/llm-models/deregister`

#### 请求正文

| 字段                     |  类型 |  必填 |
| ---------------------- | :-: | :-: |
| **model\_group\_name** | 字符串 |  ✓  |

#### cURL 示例

{% tabs %}
{% tab title="MacOS/Linux" %}

```bash
curl -X POST https://api.convai.com/llm-models/deregister \
  -H "Content-Type: application/json" \
  -H "CONVAI-API-KEY: YOUR_API_KEY" \
  -d '{ "model_group_name": "my-turbo" }'
```

{% endtab %}

{% tab title="Windows" %}
{% code overflow="wrap" %}

```powershell
curl -X POST "https://api.convai.com/llm-models/deregister" -H "Content-Type: application/json" -H "CONVAI-API-KEY: YOUR_API_KEY" -d "{\"model_group_name\": \"my-turbo\"}"
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### 成功响应（200 OK）

```json
{
  "status": "success",
  "message": "模型 'my-turbo' 已成功注销",
  "transactionID": "b11ac4f7-4cd3-4f43-8a79-3c942a14a8c9"
}
```

#### 可能的错误

| 代码  | 消息    | 原因           |
| --- | ----- | ------------ |
| 404 | 未找到模型 | 模型不存在或不属于请求者 |

***

### 2.4 列出模型

**端点：**

<mark style="color:绿色;">`POST`</mark> `https://api.convai.com/llm-models/list`

此端点无需请求正文。

#### cURL 示例

{% tabs %}
{% tab title="MacOS/Linux" %}

```bash
curl -X POST https://api.convai.com/llm-models/list \
  -H "Content-Type: application/json" \
  -H "CONVAI-API-KEY: YOUR_API_KEY"
```

{% endtab %}

{% tab title="Windows" %}
{% code overflow="wrap" %}

```powershell
curl -X POST "https://api.convai.com/llm-models/list" -H "Content-Type: application/json" -H "CONVAI-API-KEY: YOUR_API_KEY"
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### 成功响应（200 OK）

```json
{
  "status": "success",
  "models": [
    {
      "model_group_name": "my-turbo",
      "model_name": "gpt-4o-mini",
      "display_name": "Turbo (Private)",
      "base_url": "https://api.openai.com/v1",
      "is_uncensored": false,
      "category": "Private",
      "created_at": "2025-07-08T09:41:38.123Z"
    },
    {
      "model_group_name": "raw-mixtral",
      "model_name": "mixtral-8x22b-base",
      "display_name": "Mixtral Raw",
      "base_url": "https://llm.my-org.net/v1",
      "is_uncensored": true,
      "category": "Private",
      "created_at": "2025-05-21T14:02:05.551Z"
    }
  ],
  "count": 2,
  "transactionID": "2caa4b99-eda9-46e2-a9ee-b4f251afcb1f"
}
```

***

## 3. 错误参考（所有端点）

| HTTP 代码 | 常见原因            |
| ------- | --------------- |
| **400** | 参数缺失或格式错误       |
| **401** | API 密钥无效或缺失     |
| **404** | 未找到模型，或模型不属于该用户 |
| **409** | 组名或显示名称重复       |
| **429** | 超出速率限制          |
| **500** | 服务器内部错误         |

错误示例：

```json
{
  "status": "error",
  "message": "未找到模型 'x' 或访问被拒绝",
  "transactionID": "..."
}
```

***

## 4. 使用说明和最佳实践

{% hint style="danger" %}
Convai 目前仅支持 **兼容 OpenAI 的端点**。\
大多数主流提供商（OpenAI、Google、Cohere、Hugging Face、vLLM、SGlang）都支持此格式。
{% endhint %}

{% hint style="warning" %}
**model\_group\_name** 是 **不可变的**；请谨慎选择（例如， `llama3.1-70b-companyX` 而不是使用通用名称）。
{% endhint %}

{% hint style="warning" %}
**display\_name** 值必须 **对每位用户而言唯一**.
{% endhint %}

{% hint style="warning" %}
在使用 **注销** 某个模型之前，请确保所有正在使用该模型的角色都已切换到其他模型，否则它们将无法正常工作。
{% endhint %}

***

## 总结

此 **自定义 LLM API** 提供了一种简化的方式，可在 Convai 中集成、管理和控制自定义 LLM 端点。通过使用唯一标识符、安全的 API 密钥以及兼容 OpenAI 的 URL，您可以确保模型部署稳定且私密，满足您的使用场景需求。


---

# 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/custom-llm-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.
