前往 开放平台 创建密钥。密钥只显示一次,请仅保存在服务端。开发 / 生产环境请拆分密钥。
优先对接知识库检索 + 对话。可直接使用 HTTP;SDK 示例见下方或 登录后打开开发者门户。工作流 / 插件 / 多模态为后置能力。
推荐认证头:Authorization: Bearer <API_KEY>(部分接口兼容 X-API-Key)。请处理 401/403/429/502/504。
# 上传文件并处理 curl -X POST "/api/v1/upload" \ -H "X-API-Key: sk-your-key" \ -F "file=@document.pdf" \ -F "prompt=请总结要点"
上传是异步处理的,使用返回的 task_id 轮询状态,完成后获取结果。
开放平台 API 使用 X-API-Key 进行认证。所有 API 请求都需要在 Header 中携带此密钥。
X-API-Key Header 传入,用于开发者集成,管理组件、对话、会话等。X-API-Key: sk-your-api-key-here
选择你熟悉的语言 SDK,快速接入 API。所有 SDK 内置重试、超时、错误处理。
上传文件并提交处理任务。支持音频、视频、文档、图片等格式。文件大小限制 100MB。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| file | File | 必填 | 上传的文件(multipart/form-data) |
| prompt | string | 可选 | 处理提示词,如"请总结要点" |
curl -X POST "/api/v1/upload" \ -H "X-API-Key: sk-your-key" \ -F "file=@recording.mp3" \ -F "prompt=请总结要点"
{
"task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "pending",
"message": "文件已上传,正在处理"
}
查询任务处理状态。状态包括:pending(等待)、processing(处理中)、done(完成)、error(失败)。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| task_id | string | 必填 | 上传接口返回的任务 ID |
curl "/api/v1/tasks/{task_id}" \ -H "X-API-Key: sk-your-key"
{
"task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "done",
"progress": 100,
"file_name": "recording.mp3",
"task_type": "transcribe",
"created_at": "2026-06-22T10:30:00Z"
}
获取任务的完整处理结果。仅当任务状态为 done 时可调用。
curl "/api/v1/tasks/{task_id}/result" \ -H "X-API-Key: sk-your-key"
{
"task_id": "a1b2c3d4...",
"status": "done",
"result": "会议纪要:1. 讨论了Q3目标...",
"tokens_used": 1520,
"model": "gpt-4o"
}
列出所有任务记录,支持分页。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| limit | int | 可选 | 返回数量,默认 20,最大 100 |
| offset | int | 可选 | 偏移量,用于分页 |
curl "/api/v1/tasks?limit=20" \ -H "X-API-Key: sk-your-key"
获取当前用户的所有知识库,支持分页。
curl "/api/v1/knowledge/bases?page=1&page_size=20" \ -H "X-API-Key: sk-your-key"
{
"knowledge_bases": [{"id": 1, "name": "产品文档", "doc_count": 15, ...}],
"total": 3, "page": 1, "page_size": 20
}创建一个新的知识库。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 必填 | 知识库名称 |
| description | string | 可选 | 描述 |
| kb_type | string | 可选 | 类型:text / database,默认 text |
curl -X POST "/api/v1/knowledge/bases" \ -H "X-API-Key: sk-your-key" -H "Content-Type: application/json" \ -d '{"name": "产品文档", "description": "产品相关文档"}'
获取指定知识库的详细信息。
删除指定知识库及其所有文档。
获取知识库中的文档列表,支持分页。
curl "/api/v1/knowledge/bases/1/documents" \ -H "X-API-Key: sk-your-key"
在知识库中搜索相关内容,返回匹配的文本片段及相似度分数。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| query | string | 必填 | 搜索关键词 |
| top_k | int | 可选 | 返回结果数量,默认 5 |
curl -X POST "/api/v1/knowledge/bases/1/search" \ -H "X-API-Key: sk-your-key" -H "Content-Type: application/json" \ -d '{"query": "退货政策", "top_k": 5}'
{
"results": [
{"content": "自收到商品之日起7天内可申请退货...", "score": 0.92, "filename": "退货政策.pdf"}
],
"query": "退货政策"
}获取当前用户的对话列表,支持分页。
curl "/api/v1/conversations" -H "X-API-Key: sk-your-key"
创建新对话。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | string | 可选 | 对话标题 |
| kb_id | int | 可选 | 绑定知识库 ID |
获取指定对话的消息历史。
在对话中发送消息并获取 AI 回复(基于绑定知识库的 RAG 对话)。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| message | string | 必填 | 用户消息 |
| kb_id | int | 可选 | 指定知识库(覆盖对话默认绑定) |
curl -X POST "/api/v1/conversations/1/chat" \ -H "X-API-Key: sk-your-key" -H "Content-Type: application/json" \ -d '{"message": "你们的退货政策是什么?"}'
上传聊天附件(图片/文档/音频/视频),返回附件信息用于后续消息发送。支持的格式:图片(jpg/png/gif/webp)、文档(pdf/doc/docx/xls/xlsx/ppt/pptx/txt/md/csv)、音频(mp3/wav/ogg/m4a)、视频(mp4/webm/mov)。最大50MB。
Content-Type: multipart/form-data
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| file | file | 必填 | 要上传的文件 |
{
"url": "/static/chat_attachments/abc123.pdf",
"filename": "报告.pdf",
"content_type": "application/pdf",
"size": 102400,
"category": "document",
"text_preview": "文档提取的文本内容(前2000字)..."
}
// 1. 先上传附件
const formData = new FormData();
formData.append('file', file);
const attResp = await fetch('/api/chat/upload', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_TOKEN' },
body: formData
});
const attachment = await attResp.json();
// 2. 发送消息时带上附件
const chatResp = await fetch('/api/chat/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_TOKEN' },
body: JSON.stringify({
query: '请分析这个文件',
kb_id: 1,
attachments: [attachment]
})
});
获取当前用户可用的模型列表。
获取所有可用的模型供应商。
获取当前用户的工作流列表。
运行指定的工作流,传入输入数据获取执行结果。
获取已安装的插件列表。
获取当前用户的数据源列表。
触发指定数据源的同步任务。
分析图片内容,支持场景识别、文字提取、物体检测等。
将文字转换为语音,返回 Base64 编码的音频数据。
列出当前用户的所有嵌入组件配置。
curl "/api/v1/embed/configs" \ -H "X-API-Key: sk-your-key"
[
{
"id": 1,
"title": "AI 助手",
"embed_token": "TF0Js8J0X7k...",
"is_enabled": true,
"total_sessions": 42,
"total_messages": 156
}
]
创建一个新的嵌入组件配置。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | string | 可选 | 组件标题,默认 "AI 助手" |
| kb_id | int | 可选 | 绑定知识库 ID,不绑定则用户可切换 |
| theme_color | string | 可选 | 主题色,默认 "#6366f1" |
| welcome_message | string | 可选 | 欢迎语 |
curl -X POST "/api/v1/embed/configs" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -d '{"title": "客服助手", "theme_color": "#10b981"}'
获取指定嵌入组件的完整配置信息。
curl "/api/v1/embed/configs/{config_id}" \ -H "X-API-Key: sk-your-key"
更新嵌入组件配置。只需传入要修改的字段。
curl -X PUT "/api/v1/embed/configs/{config_id}" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -d '{"title": "新标题", "theme_color": "#ef4444"}'
删除指定的嵌入组件配置。关联的会话和消息将一并删除。
curl -X DELETE "/api/v1/embed/configs/{config_id}" \ -H "X-API-Key: sk-your-key"
列出指定组件的所有会话记录,支持分页。
curl "/api/v1/embed/configs/{config_id}/sessions?limit=20" \ -H "X-API-Key: sk-your-key"
获取指定会话的消息历史记录。
curl "/api/v1/embed/configs/{config_id}/sessions/{session_id}/messages" \ -H "X-API-Key: sk-your-key"
发起 RAG 对话(非流式)。基于绑定的知识库进行检索增强生成,返回完整回答。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| embed_id | int | 必填 | 嵌入组件配置 ID(通过 GET /embed/configs 获取) |
| message | string | 必填 | 用户消息内容 |
| kb_id | int | 可选 | 指定知识库 ID(覆盖组件默认绑定) |
| session_id | string | 可选 | 会话 ID,不传则自动创建 |
| attachments | array | 可选 | 附件列表,每项包含 url/filename/content_type/size/category/text_preview(先通过上传接口获取) |
curl -X POST "/api/v1/embed/chat" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -d '{ "embed_id": 1, "message": "你们的退货政策是什么?", "kb_id": 5 }'
{
"reply": "我们的退货政策如下:自收到商品之日起7天内...",
"session_id": "sess_abc123",
"sources": [
{ "filename": "退货政策.pdf", "score": 0.92 }
],
"tokens_used": 320
}
发起 RAG 流式对话(SSE)。与 /embed/chat 参数相同,但响应为 Server-Sent Events 流。
curl -X POST "/api/v1/embed/chat/stream" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -H "Accept: text/event-stream" \ -d '{"embed_id": 1, "message": "你好"}'
data: {"type": "chunk", "content": "你好"}
data: {"type": "chunk", "content": "!有什么"}
data: {"type": "chunk", "content": "可以帮您?"}
data: {"type": "sources", "sources": [{"filename": "FAQ.pdf", "score": 0.89}]}
data: {"type": "done", "session_id": "sess_abc123", "tokens_used": 128}
将文字转换为语音,返回音频流。支持多种语言和音色。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| text | string | 必填 | 要转换的文本内容 |
| voice | string | 可选 | 音色名称,默认 "zh-CN-XiaoxiaoNeural" |
| speed | float | 可选 | 语速,范围 0.5-2.0,默认 1.0 |
curl -X POST "/api/v1/embed/tts" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -d '{"text": "你好,有什么可以帮您?"}' \ --output speech.mp3
上传附件文件(图片/文档/音频/视频),返回附件信息用于聊天消息。最大20MB。支持 jpg/png/gif/webp/pdf/doc/docx/xls/xlsx/txt/md/csv/mp3/wav/mp4/webm 等格式。
{
"url": "/static/embed/abc123.pdf",
"filename": "报告.pdf",
"content_type": "application/pdf",
"size": 102400,
"category": "document",
"text_preview": "文档提取的文本内容..."
}
curl -X POST "/api/embed/widget/TOKEN/upload" \ -F "file=@report.pdf"
对消息进行评分(点赞/点踩),用于质量追踪和模型优化。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| message_id | int | 必填 | 消息 ID |
| rating | int | 必填 | 评分:1(赞)或 -1(踩) |
| feedback | string | 可选 | 文字反馈 |
curl -X POST "/api/v1/embed/rate" \ -H "X-API-Key: sk-your-key" \ -H "Content-Type: application/json" \ -d '{"message_id": 123, "rating": 1, "feedback": "回答很准确"}'