外部 API
ollmo 提供 API Key 鉴权的外部接口,用于编程式访问知识库、检索与对话。
鉴权
所有外部 API 请求需携带 X-API-Key 请求头:
curl -H "X-API-Key: <your-api-key>" \
http://localhost:8080/api/v1/external/knowledge-bases
API Key 在 Web 界面「设置 → API Key」中创建与吊销。
接口一览
基础路径:/api/v1/external
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /knowledge-bases | 列出知识库 |
| POST | /knowledge-bases | 创建知识库 |
| GET | /knowledge-bases/:kbId | 知识库详情 |
| PUT | /knowledge-bases/:kbId | 更新知识库 |
| DELETE | /knowledge-bases/:kbId | 删除知识库 |
| GET | /knowledge-bases/:kbId/documents | 文档列表 |
| POST | /knowledge-bases/:kbId/documents | 上传文档 |
| POST | /knowledge-bases/:kbId/search | 混合检索 |
| GET | /conversations | 会话列表 |
| POST | /conversations/:id/messages/stream | 流式对话(SSE) |
示例:检索
curl -X POST http://localhost:8080/api/v1/external/knowledge-bases/<kbId>/search \
-H "X-API-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{"query": "ollmo 支持哪些文件格式?", "top_k": 5}'
示例:流式对话
curl -N -X POST http://localhost:8080/api/v1/external/conversations/<id>/messages/stream \
-H "X-API-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{"content": "你好"}'
响应为 SSE 事件流,逐 token 返回。