创建知识库
接口说明
创建知识库,并返回后续上传、已上传文件状态、可读取文件和删除接口使用的 knowledgeBaseId。
接口信息
| 字段 | 值 |
|---|---|
| 方法 | POST |
| 路径 | /openapi/v2/knowledge-bases |
| Operation ID | createKnowledgeBase |
| 鉴权 | Bearer OpenAPI key |
入参
这个接口没有路径参数或查询参数。
请求体
application/json
| 字段 | 必填 | 类型 | 示例 | 说明 |
|---|---|---|---|---|
name | 是 | string | Product Docs | 资源名称,最多 255 个 UTF-8 字节。 |
description | 否 | string | null | Product documentation | 可选描述,最多 16384 个 UTF-8 字节。 |
请求示例
bash
curl -X POST "https://openapi.example.com/openapi/v2/knowledge-bases" \
-H "Authorization: Bearer <openapi-key>" \
-H "Content-Type: application/json" \
--data '{
"name": "Product Docs",
"description": "Product documentation"
}'成功响应
201
返回刚刚创建的知识库。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
knowledgeBase | 是 | object | 知识库记录。 |
成功响应示例
json
{
"knowledgeBase": {
"knowledgeBaseId": "knowledge-base-11111111-1111-4111-8111-111111111111",
"name": "Product Docs",
"description": "Product documentation",
"activeContentRevision": 0,
"resourceRevision": 1,
"createdAt": "2026-06-17T00:00:00.000Z",
"updatedAt": "2026-06-17T00:00:00.000Z"
}
}错误码
下表列出这个接口已声明的全部错误响应。
| HTTP 状态 | 错误码 | 说明 |
|---|---|---|
| 401 | UNAUTHORIZED | Bearer API key 缺失、格式错误、未知、已撤销或已删除。 |
| 413 | PAYLOAD_TOO_LARGE | 请求体或待读取文件超过当前接口允许的大小。 |
| 422 | VALIDATION_ERROR | 请求未通过校验。 |
| 429 | RATE_LIMITED | 请求超过当前配置的速率限制。 |
| 500 | INTERNAL_ERROR | API 遇到内部错误。 |
| 503 | DATABASE_REPOSITORY_UNAVAILABLE | 当前接口所需的数据暂时不可用。 |