快速开始

欢迎使用晨羽智云!本指南将帮助您在5分钟内创建并启动您的第一个GPU实例。

准备工作

在开始之前,请确保您已经:
1

注册账户

访问 晨羽智云官网 注册账户
2

获取API Key

访问控制台,在”API Key”页面创建您的API密钥
3

账户充值

为您的账户充值,确保有足够余额创建实例

第一步:选择资源

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("❌ 获取资源信息失败")

常见问题

下一步

恭喜!您已经成功创建并启动了第一个GPU实例。接下来您可以:
专业提示 - 建议在正式使用前先创建一个小型实例进行测试,熟悉平台操作后再扩展到生产环境。