用于机器人的服务器 API
Millida Hosting 客户端 API:签发密钥、权限、服务器管理以及从您自己的机器人或脚本进行控制台流式传输。
更新于 2026年10月13日
控制面板能做的事,您自己的代码也能做:定时启动服务器、在 Discord 里显示状态、用机器人发送命令。
密钥
API 在所有付费方案上都可用——和文件、SFTP、团队访问在同一个地方。免费方案不签发密钥:密钥本质上就是同样的共享访问权限,只是给机器人用的。
“玩家与访问”栏目 → “API 密钥” → “签发”。请确认密钥被允许做什么——权限与共享访问完全相同。
密钥只显示一次:我们只保存它的指纹。如果丢失,请签发新密钥并吊销旧密钥。
密钥通过 Authorization: Bearer mhk_live_... 请求头传递。
方法
基础 URL——https://millida.net/v2/hosting/api。
| 方法 | 作用 | 所需权限 |
|---|---|---|
GET /server | 服务器信息卡 | console |
GET /status | 状态与在线人数 | console |
POST /start | 启动 | start |
POST /stop | 停止 | start |
POST /restart | 重启 | start |
POST /command | 向控制台发送命令 | console |
GET /console | 实时日志(SSE) | console |
GET /files?path= | 列出文件 | files |
GET /files/configs | 表单会读取哪些配置文件 | files |
GET /files/config?path= | 带类型的文件设置 | files |
POST /files/config | 修改文件设置 | files |
GET /backups | 列出备份 | backups |
POST /backups | 创建备份 | backups |
GET /antibot | 反机器人设置、后端与防火墙规则 | protection |
PUT /antibot | 修改防护设置 | protection |
GET /antibot/overview?range= | hour、day 或 week 内的连接与拒绝次数 | protection |
POST /antibot/backends | 添加后端 {"address":"host:port","label":"..."} | protection |
DELETE /antibot/backends/{id} | 移除后端 | protection |
POST /antibot/rules | 防火墙规则 {"kind":"allow"|"deny","cidr":"1.2.3.0/24"} | protection |
DELETE /antibot/rules/{id} | 移除规则 | protection |
POST /antibot/verify-domain/check | 检查验证页面域名的 DNS | protection |
示例:启动服务器并等待其上线
KEY="mhk_live_xxx"
API="https://millida.net/v2/hosting/api"
curl -sX POST "$API/start" -H "Authorization: Bearer $KEY"
until curl -s "$API/status" -H "Authorization: Bearer $KEY" | grep -q RUNNING; do
sleep 5
done
echo "server online"
备份在后台创建
POST /backups 会立即返回 {"id":"..."},而归档本身是在节点上打包的:几 GB 的世界需要几分钟。请在 GET /backups 中通过 status 字段查看是否就绪:pending——仍在打包,ready——已存入存储(此时才会出现真实的 sizeMb),failed——打包失败。
ID=$(curl -sX POST "$API/backups" -H "Authorization: Bearer $KEY" | jq -r .id)
until curl -s "$API/backups" -H "Authorization: Bearer $KEY" \
| jq -e --arg id "$ID" '.[] | select(.id==$id) | select(.status=="ready")' >/dev/null; do
sleep 15
done
echo "backup ready"
备份进行期间,无法在同一台服务器上创建第二个备份——节点一次只处理一个。
实时控制台
GET /console 返回 Server-Sent Events 流:每一行都以 data: 前缀到达。不需要 WebSocket——SSE 能穿过任何代理。
您需要了解的事项
- 密钥的每个操作都会记录在服务器日志中,作者显示为“API key N”。当人和机器人同时在运行服务器时,这正是您需要的。
- 速率限制按密钥计算,而不是按地址:更换 IP 无法绕过限制,办公室网络里的邻居也不会消耗您的额度。对正常的自动化来说额度很充裕,但每秒轮询一次状态就会触顶——每 10–15 秒一次就足够了。控制台流每分钟最多可打开十次:请保持一个连接,而不是为每条消息都新开一个。
- 密钥会立即失效,如果服务器被暂停或方案不再付费。这种情况无需手动吊销。
- 每台服务器最多五个密钥。 不需要的请吊销。
反机器人防护
GET /antibot 在两个字段中返回设置。config——服务器自身的设置;在它们存在之前为 null,此时服务器受默认设置保护(default 字段)。effective 始终存在:这些是当前生效的设置,或服务器在首次编辑后将开始使用的设置——请从中读取值。
PUT /antibot 只接受您想修改的字段:
curl -sX PUT "$API/antibot" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"preset":"balanced"}'
级别(preset):off、under_attack、balanced、aggressive、custom。级别会自行展开为各项检查的值,因此手动配置时请选择 custom 并发送检查项:checkCaptcha、checkPhysics、checkKeepAlive、checkTeleport、checkBrand、checkPing、checkTransfer、checkClientSettings——每一项为 off、under_attack 或 always。地址列表(vpnMode、datacenterMode、torMode)——off、log 或 block。地区过滤——geoMode(off、allow、deny)和 geoCountries(国家代码,例如 ["RU","BY"])。
转发密钥不通过 API 签发或修改:它只在面板中向所有者显示。
配置文件设置
GET /files/config?path=server.properties 返回解析后的文件——每一项都带有类型、当前值以及“需要重启”标记:
{
"path": "server.properties",
"format": "properties",
"options": [
{ "key": "pvp", "type": "boolean", "value": "true", "owner": "sync", "requiresRestart": false },
{ "key": "difficulty", "type": "select", "value": "normal", "values": ["peaceful", "easy", "normal", "hard"], "owner": "sync", "requiresRestart": false },
{ "key": "server-port", "type": "integer", "value": "25565", "owner": "platform", "requiresRestart": true }
]
}
owner 告诉您能对该项做什么:platform——值由托管方设置,编辑会被拒绝;sync——该项同时存在于面板和文件中;file——只有文件知道它。
写入只会修改您发送的键;文件中的其他内容保持不变:
curl -sX POST "$API/files/config" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"path":"server.properties","values":{"pvp":"false","difficulty":"hard"}}'
表单会读取 .properties、.yml/.yaml 和 .toml——包括面板完全不了解的插件配置:字段类型根据值推断。嵌套键用点号寻址:settings.bungeecord、advanced.compression-threshold。
整个文件仍可通过 GET/PUT /files/content?path= 访问——两条路径写入的是同一个地方。
Node.js 和 Python 现成客户端
下面是一个最小客户端:它会检查状态、启动服务器并向聊天发送消息。密钥来自 MILLIDA_KEY 环境变量——不要把它粘贴到会进入 git 的代码里。错误响应是带有 message 字段的 JSON;您的机器人应当记录这个字段。
Node.js 18+(内置 fetch):
const API = 'https://millida.net/v2/hosting/api';
const KEY = process.env.MILLIDA_KEY;
async function call(method, path, body) {
const res = await fetch(`${API}${path}`, {
method,
headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${await res.text()}`);
return res.status === 204 ? null : res.json();
}
const status = await call('GET', '/status');
if (status.status !== 'RUNNING') await call('POST', '/start');
await call('POST', '/command', { command: 'say Hello from the bot' });
Python 3 配合 requests 库,并读取实时控制台:
import os
import requests
API = "https://millida.net/v2/hosting/api"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['MILLIDA_KEY']}"
def call(method, path, body=None):
res = session.request(method, API + path, json=body, timeout=15)
res.raise_for_status()
return res.json() if res.content else None
status = call("GET", "/status")
if status["status"] != "RUNNING":
call("POST", "/start")
call("POST", "/command", {"command": "say Hello from the bot"})
with session.get(API + "/console", stream=True, timeout=None) as stream:
for line in stream.iter_lines(decode_unicode=True):
if line and line.startswith("data:"):
print(line[5:].strip())
