API文档
夜月AI应用平台 提供完整的RESTful API,支持所有核心功能的程序化访问。
基础信息
API端点
| 环境 | 地址 | 说明 |
|---|---|---|
| 开发环境 | http://localhost:8000/boot | 本地开发 |
| 测试环境 | https://test-api.nitemoon.cn | 测试环境 |
| 生产环境 | https://api.nitemoon.cn | 生产环境 |
认证方式
所有API请求需要在Header中携带认证令牌:
http
Authorization: Bearer your_access_token获取令牌:
http
POST /auth/login
Content-Type: application/json
{
"username": "admin",
"password": "admin123"
}响应:
json
{
"code": 200,
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 86400
}
}请求格式
- Content-Type: application/json
- 字符编码: UTF-8
响应格式
json
{
"code": 200,
"msg": "success",
"data": {}
}错误码
| 错误码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未认证 |
| 403 | 无权限 |
| 404 | 资源不存在 |
| 500 | 服务器内部错误 |
对话API
创建对话
http
POST /api/chat/create
Content-Type: application/json
Authorization: Bearer your_access_token
{
"appId": 1,
"userId": 1001
}响应:
json
{
"code": 200,
"data": {
"conversationId": "conv_123456",
"createdAt": "2024-01-01T00:00:00Z"
}
}发送消息(流式)
http
POST /api/chat/send
Content-Type: application/json
Authorization: Bearer your_access_token
{
"conversationId": "conv_123456",
"message": "如何配置RAG知识库?"
}响应(SSE流):
data: {"type":"token","content":"配置"}
data: {"type":"token","content":"RAG"}
data: {"type":"token","content":"知识库"}
data: {"type":"token","content":"的步骤"}
data: {"type":"done","usage":{"promptTokens":100,"completionTokens":50}}获取对话历史
http
GET /api/chat/history?conversationId=conv_123456
Authorization: Bearer your_access_token响应:
json
{
"code": 200,
"data": [
{
"role": "user",
"content": "如何配置RAG知识库?",
"timestamp": "2024-01-01T00:00:00Z"
},
{
"role": "assistant",
"content": "配置RAG知识库的步骤如下...",
"timestamp": "2024-01-01T00:00:01Z"
}
]
}知识库API
创建知识库
http
POST /api/knowledge-base/create
Content-Type: application/json
Authorization: Bearer your_access_token
{
"name": "产品文档",
"description": "产品相关文档"
}上传文档
http
POST /api/document/upload
Content-Type: multipart/form-data
Authorization: Bearer your_access_token
knowledgeBaseId: 1
file: (binary)查询知识库
http
POST /api/rag/query
Content-Type: application/json
Authorization: Bearer your_access_token
{
"knowledgeBaseId": 1,
"query": "如何配置RAG知识库?",
"topK": 5,
"similarityThreshold": 0.7
}响应:
json
{
"code": 200,
"data": {
"answer": "配置RAG知识库的步骤如下...",
"sources": [
{
"content": "RAG知识库配置文档...",
"similarity": 0.85,
"documentId": 1
}
]
}
}工作流API
创建工作流
http
POST /api/workflow/create
Content-Type: application/json
Authorization: Bearer your_access_token
{
"name": "智能客服工作流",
"description": "客服场景工作流",
"nodes": [
{
"id": "start",
"type": "START",
"config": {}
},
{
"id": "llm",
"type": "LLM",
"config": {
"model": "gpt-4",
"prompt": "你是一个专业的客服助手"
}
},
{
"id": "end",
"type": "END",
"config": {}
}
],
"edges": [
{"source": "start", "target": "llm"},
{"source": "llm", "target": "end"}
]
}执行工作流
http
POST /api/workflow/execute
Content-Type: application/json
Authorization: Bearer your_access_token
{
"workflowId": 1,
"input": {
"userQuery": "如何配置RAG知识库?"
}
}响应(SSE流):
data: {"nodeId":"start","status":"completed"}
data: {"nodeId":"llm","status":"running","token":"配置"}
data: {"nodeId":"llm","status":"completed","output":"配置RAG知识库的步骤..."}
data: {"nodeId":"end","status":"completed"}
data: {"type":"done","usage":{"totalTokens":150}}知识图谱API
创建知识图谱
http
POST /api/kg/create
Content-Type: application/json
Authorization: Bearer your_access_token
{
"name": "产品知识图谱",
"description": "产品相关知识网络"
}构建知识图谱
http
POST /api/kg/build
Content-Type: application/json
Authorization: Bearer your_access_token
{
"kgId": 1,
"documentId": 1
}查询知识图谱
http
POST /api/kg/query
Content-Type: application/json
Authorization: Bearer your_access_token
{
"kgId": 1,
"query": "产品A依赖哪些技术组件?"
}响应:
json
{
"code": 200,
"data": {
"answer": "产品A依赖以下技术组件...",
"entities": [
{"name": "产品A", "type": "PRODUCT"},
{"name": "Spring Boot", "type": "TECHNOLOGY"}
],
"relations": [
{"source": "产品A", "target": "Spring Boot", "type": "USES"}
]
}
}数字人API
创建数字人
http
POST /api/human/create
Content-Type: application/json
Authorization: Bearer your_access_token
{
"name": "小助手",
"voice": "zh-CN-Neural",
"ttsProvider": "volcengine"
}语音合成
http
POST /api/tts/synthesize
Content-Type: application/json
Authorization: Bearer your_access_token
{
"humanId": 1,
"text": "你好,有什么可以帮助你的?"
}响应:音频文件(audio/wav)
AI Excel API
生成Excel
http
POST /api/aiexcel/generate
Content-Type: application/json
Authorization: Bearer your_access_token
{
"request": "帮我生成一份本月的财务报表,包含收入、支出、利润"
}响应:
json
{
"code": 200,
"data": {
"fileId": "file_123456",
"fileName": "财务报表_202401.xlsx",
"downloadUrl": "/api/file/download/file_123456"
}
}WebSocket API
连接地址
ws://localhost:8000/boot/ws/chat?token=your_access_token消息格式
发送消息:
json
{
"type": "chat",
"conversationId": "conv_123456",
"content": "你好"
}接收消息:
json
{
"type": "token",
"content": "你"
}json
{
"type": "done",
"usage": {
"promptTokens": 100,
"completionTokens": 50
}
}SDK
Java SDK
xml
<dependency>
<groupId>cn.nitemoon</groupId>
<artifactId>nitemoon-sdk</artifactId>
<version>1.0.0</version>
</dependency>java
NitemoonClient client = NitemoonClient.builder()
.baseUrl("https://api.nitemoon.cn")
.apiKey("your_api_key")
.build();
// 对话
ChatResponse response = client.chat()
.appId(1)
.message("你好")
.send();
// 知识库查询
RAGResponse ragResponse = client.rag()
.knowledgeBaseId(1)
.query("如何配置RAG?")
.execute();JavaScript SDK
bash
npm install nitemoon-sdkjavascript
import { NitemoonClient } from 'nitemoon-sdk';
const client = new NitemoonClient({
baseUrl: 'https://api.nitemoon.cn',
apiKey: 'your_api_key'
});
// 对话
const response = await client.chat({
appId: 1,
message: '你好'
});
// 知识库查询
const ragResponse = await client.rag({
knowledgeBaseId: 1,
query: '如何配置RAG?'
});Python SDK
bash
pip install nitemoon-sdkpython
from nitemoon import NitemoonClient
client = NitemoonClient(
base_url='https://api.nitemoon.cn',
api_key='your_api_key'
)
# 对话
response = client.chat(
app_id=1,
message='你好'
)
# 知识库查询
rag_response = client.rag(
knowledge_base_id=1,
query='如何配置RAG?'
)