> ## Documentation Index
> Fetch the complete documentation index at: https://chenyu.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 快速开始

> 5分钟快速上手晨羽智云

# 快速开始

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

## 准备工作

在开始之前，请确保您已经：

<Steps>
  <Step title="注册账户">
    访问 [晨羽智云官网](https://www.chenyu.cn) 注册账户
  </Step>

  <Step title="获取API Key">
    访问控制台，在"API Key"页面创建您的API密钥
  </Step>

  <Step title="账户充值">
    为您的账户充值，确保有足够余额创建实例
  </Step>
</Steps>

## 第一步：选择资源

### 1.1 获取可用Pod列表

首先，我们需要查看当前可用的Pod资源：

```bash theme={null}
curl -X GET "https://www.chenyu.cn/api/open/v2/pod/list"
```

### 1.2 选择GPU型号

查看平台支持的GPU型号：

```bash theme={null}
curl -X GET "https://www.chenyu.cn/api/open/v2/gpu/list" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## 第二步：创建实例

使用选定的资源创建您的第一个实例：

<CodeGroup>
  ```bash cURL theme={null}
  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
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://www.chenyu.cn/api/open/v2/instance/create_by_pod"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json"
  }

  data = {
      "pod_uuid": "pod_12345678-1234-1234-1234-123456789012",
      "pod_tag": "latest",
      "gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
      "gpu_nums": 1
  }

  response = requests.post(url, headers=headers, json=data)
  instance_info = response.json()
  if instance_info['code'] == 0:
      print(f"实例UUID: {instance_info['data']['instance_uuid']}")
  else:
      print(f"创建失败: {instance_info['msg']}")
  ```
</CodeGroup>

## 第三步：监控实例状态

创建实例后，监控其启动状态：

```bash theme={null}
curl -X GET "https://www.chenyu.cn/api/open/v2/instance/list" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

等待实例状态变为 `2`（运行中）后，您就可以开始使用了。

## 完整示例

以下是一个完整的Python脚本示例，展示如何自动化创建和管理实例：

<CodeGroup>
  ```python Python SDK theme={null}
  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("❌ 获取资源信息失败")
  ```
</CodeGroup>

## 常见问题

<AccordionGroup>
  <Accordion title="实例创建失败怎么办？" icon="question">
    1. 检查账户余额是否充足
    2. 确认选择的Pod和GPU型号是否可用
    3. 检查API Key是否正确
    4. 查看错误信息中的具体原因
  </Accordion>

  <Accordion title="如何选择合适的GPU型号？" icon="microchip">
    * **A100 40GB**: 适合大规模深度学习训练，内存充足
    * **RTX 4090**: 适合推理和中小规模训练，性价比高
  </Accordion>

  <Accordion title="实例启动很慢怎么办？" icon="clock">
    实例启动时间取决于多个因素：

    * 镜像大小：较大的镜像需要更长时间下载
    * 网络状况：网络繁忙时可能影响启动速度
    * 资源可用性：高峰期可能需要等待资源分配

    通常实例启动时间在1-3分钟之间。
  </Accordion>

  <Accordion title="如何优化成本？" icon="dollar-sign">
    * 及时停止不使用的实例
    * 选择合适的GPU型号，避免过度配置
    * 使用定时开关机功能
    * 监控资源使用情况，避免浪费
  </Accordion>
</AccordionGroup>

## 下一步

恭喜！您已经成功创建并启动了第一个GPU实例。接下来您可以：

<CardGroup cols={2}>
  <Card title="功能介绍" icon="book-open" href="/userguide/introduction">
    深入了解平台的各项功能和最佳实践
  </Card>

  <Card title="API参考" icon="code" href="/api-reference/introduction">
    查看完整的API文档，实现更复杂的自动化
  </Card>

  <Card title="计费说明" icon="credit-card" href="/userguide/billing">
    了解详细的计费规则和成本优化策略
  </Card>

  <Card title="技术支持" icon="headset" href="mailto:admin@chenyu.com">
    遇到问题？联系我们的技术支持团队
  </Card>
</CardGroup>

***

<Tip>
  **专业提示** - 建议在正式使用前先创建一个小型实例进行测试，熟悉平台操作后再扩展到生产环境。
</Tip>
