Skip to content

API Reference

NiteMoon AI Platform provides a complete RESTful API, supporting programmatic access to all core features.

Basic Information

API Endpoints

EnvironmentURLDescription
Developmenthttp://localhost:8000/bootLocal development
Testinghttps://test-api.nitemoon.cnTesting environment
Productionhttps://api.nitemoon.cnProduction environment

Authentication

All API requests require an authentication token in the header:

http
Authorization: Bearer your_access_token

Obtain a token:

http
POST /auth/login
Content-Type: application/json

{
  "username": "admin",
  "password": "admin123"
}

Response:

json
{
  "code": 200,
  "data": {
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expiresIn": 86400
  }
}

Request Format

  • Content-Type: application/json
  • Character encoding: UTF-8

Response Format

json
{
  "code": 200,
  "msg": "success",
  "data": {}
}

Error Codes

Error CodeDescription
200Success
400Invalid request parameters
401Unauthorized
403Forbidden
404Resource not found
500Internal server error

Chat API

Create Conversation

http
POST /api/chat/create
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "appId": 1,
  "userId": 1001
}

Response:

json
{
  "code": 200,
  "data": {
    "conversationId": "conv_123456",
    "createdAt": "2024-01-01T00:00:00Z"
  }
}

Send Message (Streaming)

http
POST /api/chat/send
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "conversationId": "conv_123456",
  "message": "How do I configure a RAG knowledge base?"
}

Response (SSE stream):

data: {"type":"token","content":"To"}
data: {"type":"token","content":" configure"}
data: {"type":"token","content":" a RAG"}
data: {"type":"token","content":" knowledge base"}
data: {"type":"done","usage":{"promptTokens":100,"completionTokens":50}}

Get Conversation History

http
GET /api/chat/history?conversationId=conv_123456
Authorization: Bearer your_access_token

Response:

json
{
  "code": 200,
  "data": [
    {
      "role": "user",
      "content": "How do I configure a RAG knowledge base?",
      "timestamp": "2024-01-01T00:00:00Z"
    },
    {
      "role": "assistant",
      "content": "The steps to configure a RAG knowledge base are as follows...",
      "timestamp": "2024-01-01T00:00:01Z"
    }
  ]
}

Knowledge Base API

Create Knowledge Base

http
POST /api/knowledge-base/create
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "name": "Product Documentation",
  "description": "Product-related documents"
}

Upload Document

http
POST /api/document/upload
Content-Type: multipart/form-data
Authorization: Bearer your_access_token

knowledgeBaseId: 1
file: (binary)

Query Knowledge Base

http
POST /api/rag/query
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "knowledgeBaseId": 1,
  "query": "How do I configure a RAG knowledge base?",
  "topK": 5,
  "similarityThreshold": 0.7
}

Response:

json
{
  "code": 200,
  "data": {
    "answer": "The steps to configure a RAG knowledge base are as follows...",
    "sources": [
      {
        "content": "RAG knowledge base configuration guide...",
        "similarity": 0.85,
        "documentId": 1
      }
    ]
  }
}

Workflow API

Create Workflow

http
POST /api/workflow/create
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "name": "Smart Customer Service Workflow",
  "description": "Customer service scenario workflow",
  "nodes": [
    {
      "id": "start",
      "type": "START",
      "config": {}
    },
    {
      "id": "llm",
      "type": "LLM",
      "config": {
        "model": "gpt-4",
        "prompt": "You are a professional customer service assistant"
      }
    },
    {
      "id": "end",
      "type": "END",
      "config": {}
    }
  ],
  "edges": [
    {"source": "start", "target": "llm"},
    {"source": "llm", "target": "end"}
  ]
}

Execute Workflow

http
POST /api/workflow/execute
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "workflowId": 1,
  "input": {
    "userQuery": "How do I configure a RAG knowledge base?"
  }
}

Response (SSE stream):

data: {"nodeId":"start","status":"completed"}
data: {"nodeId":"llm","status":"running","token":"To"}
data: {"nodeId":"llm","status":"completed","output":"The steps to configure a RAG knowledge base..."}
data: {"nodeId":"end","status":"completed"}
data: {"type":"done","usage":{"totalTokens":150}}

Knowledge Graph API

Create Knowledge Graph

http
POST /api/kg/create
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "name": "Product Knowledge Graph",
  "description": "Product-related knowledge network"
}

Build Knowledge Graph

http
POST /api/kg/build
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "kgId": 1,
  "documentId": 1
}

Query Knowledge Graph

http
POST /api/kg/query
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "kgId": 1,
  "query": "What technical components does Product A depend on?"
}

Response:

json
{
  "code": 200,
  "data": {
    "answer": "Product A depends on the following technical components...",
    "entities": [
      {"name": "Product A", "type": "PRODUCT"},
      {"name": "Spring Boot", "type": "TECHNOLOGY"}
    ],
    "relations": [
      {"source": "Product A", "target": "Spring Boot", "type": "USES"}
    ]
  }
}

Digital Human API

Create Digital Human

http
POST /api/human/create
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "name": "Assistant",
  "voice": "zh-CN-Neural",
  "ttsProvider": "volcengine"
}

Text-to-Speech

http
POST /api/tts/synthesize
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "humanId": 1,
  "text": "Hello, how can I help you?"
}

Response: Audio file (audio/wav)

AI Excel API

Generate Excel

http
POST /api/aiexcel/generate
Content-Type: application/json
Authorization: Bearer your_access_token

{
  "request": "Help me generate a financial report for this month, including revenue, expenses, and profit"
}

Response:

json
{
  "code": 200,
  "data": {
    "fileId": "file_123456",
    "fileName": "Financial_Report_202401.xlsx",
    "downloadUrl": "/api/file/download/file_123456"
  }
}

WebSocket API

Connection URL

ws://localhost:8000/boot/ws/chat?token=your_access_token

Message Format

Send message:

json
{
  "type": "chat",
  "conversationId": "conv_123456",
  "content": "Hello"
}

Receive message:

json
{
  "type": "token",
  "content": "Hello"
}
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();

// Chat
ChatResponse response = client.chat()
    .appId(1)
    .message("Hello")
    .send();

// Knowledge base query
RAGResponse ragResponse = client.rag()
    .knowledgeBaseId(1)
    .query("How to configure RAG?")
    .execute();

JavaScript SDK

bash
npm install nitemoon-sdk
javascript
import { NitemoonClient } from 'nitemoon-sdk';

const client = new NitemoonClient({
  baseUrl: 'https://api.nitemoon.cn',
  apiKey: 'your_api_key'
});

// Chat
const response = await client.chat({
  appId: 1,
  message: 'Hello'
});

// Knowledge base query
const ragResponse = await client.rag({
  knowledgeBaseId: 1,
  query: 'How to configure RAG?'
});

Python SDK

bash
pip install nitemoon-sdk
python
from nitemoon import NitemoonClient

client = NitemoonClient(
    base_url='https://api.nitemoon.cn',
    api_key='your_api_key'
)

# Chat
response = client.chat(
    app_id=1,
    message='Hello'
)

# Knowledge base query
rag_response = client.rag(
    knowledge_base_id=1,
    query='How to configure RAG?'
)

Copyright © 2023-2026 nitemoon.cn All Rights Reserved