6.8 KiB
name, description
| name | description |
|---|---|
| mj-api-skill | Help AI integrate with Mujian OpenAPI - an OpenAI-compatible API for accessing LLM capabilities within the Mujian platform. |
Mujian OpenAPI Integration Skill
Help developers integrate with the Mujian (幕间) OpenAPI, which follows OpenAI API specifications to provide LLM access within the Mujian platform.
When to use
Use this skill when the user:
- Wants to integrate Mujian OpenAPI into their project
- Asks about calling Mujian's LLM API (chat completions, model list)
- Needs help with Mujian JS-SDK initialization
- Wants to implement streaming or non-streaming chat with Mujian
- Mentions "幕间" or "mujian" in the context of API integration
Platform Overview
Mujian OpenAPI uses OpenAI-standard protocols to access online LLM capabilities. It is restricted to:
- Creator local debugging
- Works shared within the Mujian platform (third-party platform uploads cannot access it)
SDK Setup
Browser (UMD)
Add the SDK script in <head> (place it early to ensure loading before dependent code):
<script
src="https://cdn.jsdmirror.com/npm/@mujian/js-sdk@latest/dist/umd/lite.js"
type="text/javascript"
></script>
Initialize and retrieve API config:
window.$mujian_lite.init().then(() => {
console.log('API Base URL:', window.$mujian_lite.openapi.baseURL);
console.log('API Key:', window.$mujian_lite.openapi.apiKey);
}).catch((err) => {
console.error('SDK initialization failed:', err);
});
NPM Package (React, Vue, etc.)
npm install @mujian/js-sdk
import '@mujian/js-sdk/lite';
window.$mujian_lite.init().then(() => {
console.log('API Base URL:', window.$mujian_lite.openapi.baseURL);
console.log('API Key:', window.$mujian_lite.openapi.apiKey);
}).catch((err) => {
console.error('SDK initialization failed:', err);
});
SDK API Reference
| Name | Type | Description |
|---|---|---|
init() |
Promise<void> |
Initialize SDK and retrieve config. Must be called first. Idempotent (safe to call multiple times). |
openapi |
{ baseURL: string; apiKey: string } | undefined |
Available after init() resolves. Contains API endpoint and user-specific key. undefined before init completes. |
window.$mujian_lite is a global singleton, no manual instantiation needed.
Authentication
All requests require an Authorization header:
Authorization: Bearer <apiKey>
- In production (within Mujian platform): get
apiKeyfromwindow.$mujian_lite.openapi.apiKeyafter SDK init - In local development: manually copy API Key from Mujian "My" section
Base URL
| Environment | URL |
|---|---|
| Production | https://openapi.mujian.ai/v1 |
| Preview | https://openapi-preview.mujian.ai/v1 |
In production, use window.$mujian_lite.openapi.baseURL instead of hardcoding.
API Endpoints
GET /models
Returns available model IDs (OpenAI API compatible).
Supported models: deepseek-v3.2
const { baseURL, apiKey } = window.$mujian_lite.openapi;
fetch(`${baseURL}/models`, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
})
.then((res) => res.json())
.then((data) => console.log(data));
POST /chat/completions
OpenAI-compatible chat completion endpoint. Supports both streaming and non-streaming.
Non-streaming
const { baseURL, apiKey } = window.$mujian_lite.openapi;
fetch(`${baseURL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'deepseek-v3.2',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello' },
],
}),
})
.then((res) => res.json())
.then((data) => console.log(data));
Streaming
const { baseURL, apiKey } = window.$mujian_lite.openapi;
fetch(`${baseURL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'deepseek-v3.2',
stream: true,
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello' },
],
}),
})
.then((res) => {
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
function read() {
reader.read().then(({ done, value }) => {
if (done) return;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop();
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') return;
try {
const json = JSON.parse(data);
const content = json.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
} catch (e) {}
}
}
read();
});
}
read();
});
Local Development
For local debugging (outside the Mujian platform):
- Go to Mujian → "My" section → click "Copy" to get your API Key
- Use
https://openapi.mujian.ai/v1as BaseURL (or preview URL for preview env) - Hardcode the API Key and BaseURL in your code
- After local development is complete, switch to SDK-based method (
window.$mujian_lite.openapi) for production
<!doctype html>
<html>
<head>
<script>
fetch('https://openapi.mujian.ai/v1/models', {
headers: {
Authorization: 'Bearer YOUR_API_KEY_HERE',
},
})
.then((res) => res.json())
.then((data) => console.log(data));
</script>
</head>
<body></body>
</html>
Official Documentation
If the information in this skill is outdated or you encounter issues, refer to the latest official docs:
- Introduction & SDK Setup: https://docs.mujian.ai/creator/openapi/introduction.md
- API Endpoints: https://docs.mujian.ai/creator/openapi/endpoints.md
- Local Development: https://docs.mujian.ai/creator/openapi/local-dev.md
Instructions for AI
When helping users integrate Mujian OpenAPI:
- Determine the environment: local debugging or production (within Mujian platform)
- For local dev: guide them to manually get API Key and use hardcoded BaseURL
- For production: use the JS-SDK to initialize and get
baseURLandapiKeyfromwindow.$mujian_lite.openapi - Choose UMD (script tag) or NPM based on their project setup
- Implement the needed endpoint (models list or chat completions)
- For chat: ask if they need streaming or non-streaming, then provide the appropriate example
- Remind users that
openapiisundefinedbeforeinit()completes — always await initialization - Remind users that Mujian OpenAPI only works for creator local debugging or works shared within the Mujian platform