快速开始
欢迎使用晨羽智云!本指南将帮助您在5分钟内创建并启动您的第一个GPU实例。
准备工作
在开始之前,请确保您已经:
获取API Key
访问控制台,在”API Key”页面创建您的API密钥
第一步:选择资源
1.1 获取可用Pod列表
首先,我们需要查看当前可用的Pod资源:
curl -X GET "https://www.chenyu.cn/api/open/v2/pod/list"
1.2 选择GPU型号
查看平台支持的GPU型号:
curl -X GET "https://www.chenyu.cn/api/open/v2/gpu/list" \
-H "Authorization: Bearer YOUR_API_KEY"
第二步:创建实例
使用选定的资源创建您的第一个实例:
curl -X POST "https://www.chenyu.cn/api/open/v2/instance/create_by_pod" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"pod_uuid": "pod_12345678-1234-1234-1234-123456789012",
"pod_tag": "latest",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_nums": 1
}'
第三步:监控实例状态
创建实例后,监控其启动状态:
curl -X GET "https://www.chenyu.cn/api/open/v2/instance/list" \
-H "Authorization: Bearer YOUR_API_KEY"
等待实例状态变为 2(运行中)后,您就可以开始使用了。
完整示例
以下是一个完整的Python脚本示例,展示如何自动化创建和管理实例:
import requests
import time
import json
class ChenyuClient:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://www.chenyu.cn/api/open/v2"
self.headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
def get_pods(self):
"""获取可用Pod列表"""
response = requests.get(f"{self.base_url}/pod/list", headers=self.headers)
return response.json()
def get_gpu_models(self):
"""获取GPU型号列表"""
response = requests.get(f"{self.base_url}/gpu/list", headers=self.headers)
return response.json()
def create_instance(self, pod_uuid, pod_tag, gpu_uuid, gpu_nums=1):
"""创建实例"""
data = {
"pod_uuid": pod_uuid,
"pod_tag": pod_tag,
"gpu_uuid": gpu_uuid,
"gpu_nums": gpu_nums
}
response = requests.post(f"{self.base_url}/instance/create_by_pod",
headers=self.headers, json=data)
return response.json()
def get_instance_list(self):
"""获取实例列表"""
response = requests.get(f"{self.base_url}/instance/list", headers=self.headers)
return response.json()
def wait_for_instance_ready(self, instance_uuid, timeout=300):
"""等待实例就绪"""
start_time = time.time()
while time.time() - start_time < timeout:
instances = self.get_instance_list()
if instances['code'] == 0:
for instance in instances['data']['instance_list']:
if instance['instance_uuid'] == instance_uuid:
if instance['status'] == 2: # 运行中
return True
elif instance['status'] in [21, 22]: # 关机中或已关机
return False
time.sleep(10)
return False
# 使用示例
if __name__ == "__main__":
# 初始化客户端
client = ChenyuClient("YOUR_API_KEY")
# 1. 获取可用Pod
pods = client.get_pods()
if pods['code'] == 0:
print("可用Pod列表:")
for pod in pods['data']['pod_list']:
print(f"- {pod['title']}")
# 2. 获取GPU型号
gpu_models = client.get_gpu_models()
if gpu_models['code'] == 0:
print("\n支持的GPU:")
for gpu in gpu_models['data']['gpu_list']:
print(f"- {gpu['gpu_name']} - {gpu['price']['hour']}元/小时")
# 3. 创建实例
if pods['code'] == 0 and gpu_models['code'] == 0:
pod_uuid = pods['data']['pod_list'][0]['uuid']
pod_tag = "latest" # 使用默认标签
gpu_uuid = gpu_models['data']['gpu_list'][0]['gpu_uuid']
result = client.create_instance(pod_uuid, pod_tag, gpu_uuid)
if result['code'] == 0:
instance_uuid = result['data']['instance_uuid']
print(f"\n实例创建成功!UUID: {instance_uuid}")
# 4. 等待实例就绪
print("等待实例启动...")
if client.wait_for_instance_ready(instance_uuid):
print("✅ 实例已就绪,可以开始使用!")
# 获取实例详细信息
instances = client.get_instance_list()
if instances['code'] == 0:
for instance in instances['data']['instance_list']:
if instance['instance_uuid'] == instance_uuid:
print(f"实例名称: {instance['title']}")
if instance['server_url']:
print("服务地址:")
for url in instance['server_url']:
print(f" - {url}")
else:
print("❌ 实例启动失败或超时")
else:
print(f"❌ 实例创建失败: {result['msg']}")
else:
print("❌ 获取资源信息失败")
常见问题
- 检查账户余额是否充足
- 确认选择的Pod和GPU型号是否可用
- 检查API Key是否正确
- 查看错误信息中的具体原因
- A100 40GB: 适合大规模深度学习训练,内存充足
- RTX 4090: 适合推理和中小规模训练,性价比高
实例启动时间取决于多个因素:
- 镜像大小:较大的镜像需要更长时间下载
- 网络状况:网络繁忙时可能影响启动速度
- 资源可用性:高峰期可能需要等待资源分配
通常实例启动时间在1-3分钟之间。
- 及时停止不使用的实例
- 选择合适的GPU型号,避免过度配置
- 使用定时开关机功能
- 监控资源使用情况,避免浪费
下一步
恭喜!您已经成功创建并启动了第一个GPU实例。接下来您可以:
专业提示 - 建议在正式使用前先创建一个小型实例进行测试,熟悉平台操作后再扩展到生产环境。