跳转到内容

实例

每个账户同时只能有一个活跃实例。下面这些端点负责启动它、轮询它、拆掉它。

POST /api/notebook/request 会话或 API 密钥

分配一开始就返回——它不等实例就绪。轮询状态直到 readytrue

参数类型说明
imagestring选填容器镜像。必须是目录里启用的。默认用平台默认镜像。
instance_typestring选填jupytergradiostreamlitcomfyuivllmsglangopencodecustom。默认 jupyter
gpu_countinteger选填124。默认 1
disk_size_gbinteger选填从 100 GB 起,上限随 GPU 数量而定:1 卡 100,2 卡 150,4 卡 200。
resource_profilestring选填具名的 CPU 与内存配置。默认 auto
launch_verification_tokenstring选填仅在账户开启了启动验证时需要。
Terminal window
curl -X POST https://radeon-global.anruicloud.com/api/notebook/request \
-H "Authorization: Bearer $RADEON_API_KEY" \
-H "Content-Type: application/json" \
-d '{"instance_type": "jupyter", "gpu_count": 1, "disk_size_gb": 100}'
{
"status": "allocating",
"message": "Allocating resources for your instance...",
"email": "you@example.com"
}

以下情况返回 400 拒绝:GPU 数量不是 1、2 或 4;磁盘大小超出允许范围;镜像或实例类型未知或已禁用;你已经有一个活跃实例;或者你的额度余额低于请求的 GPU 数量。

GET /api/notebook/status 会话或 API 密钥

无参数——它报告调用方账户的实例。

{
"status": "ready",
"ready": true,
"message": "Your workspace is ready",
"instance_id": "u-1042-9c3f8ab1",
"instance_type": "jupyter",
"url": "https://radeon-global.anruicloud.com/instances/u-1042-9c3f8ab1/",
"app_port": 8888,
"ssh_host": "ssh.anruicloud.com",
"ssh_port": 32014,
"ssh_username": "root",
"ssh_command": "ssh root@ssh.anruicloud.com -p 32014",
"api_base_url": null,
"api_key": null,
"api_model": null
}
字段说明
statusnot_foundallocatingloadinginitializingpendingjupyter_startingrunningreadyfailedunknown
ready只有实例完全可用时才是 true。判断就看它,别看 status
message给人看的进度或失败说明。
instance_id标识符,形如 u-<user>-<hash>。会出现在 URL 里。
url在浏览器里打开实例的地址。需要会话 cookie。
phasereasondetail更底层的调度状态。启动卡住时有用。
ssh_hostssh_portssh_usernamessh_command容器跑起来之后填充,前提是模板开了 SSH。
api_base_urlapi_keyapi_model只有已就绪的 vllmsglang 实例才填充。独占端点的 URL 就是从这儿来的。

每隔几秒轮询一次。冷启动拉大镜像,或者 vLLM 实例下载权重,都可能要好几分钟。

DELETE /api/notebook/current 会话或 API 密钥
{
"success": true,
"message": "Instance destroyed",
"destroyed_count": 1
}

如果本来就没东西可销毁,返回 success: false"No active instance found"——这不是错误,调两次也没问题。

除非模板用了持久化存储,否则数据会随实例一起删掉。

import time, requests
BASE = "https://radeon-global.anruicloud.com"
H = {"Authorization": f"Bearer {KEY}"}
requests.post(f"{BASE}/api/notebook/request", headers=H,
json={"instance_type": "jupyter", "gpu_count": 1}).raise_for_status()
while True:
s = requests.get(f"{BASE}/api/notebook/status", headers=H).json()
if s["ready"]:
print("ready:", s["url"])
break
if s["status"] == "failed":
raise RuntimeError(s.get("message", "launch failed"))
print(s["status"], s.get("message", ""))
time.sleep(5)

一定要在 finally 里销毁。脚本崩了却留着实例在跑,额度就一直在烧。