> ## 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.

# 保存为镜像

> 将实例保存为私有镜像

# 保存为镜像

将指定实例的当前状态保存为私有镜像，便于后续创建相同配置的实例。

<Warning>
  仅在实例运行时可以保存镜像，保存镜像后，实例将会自动关机。
</Warning>

## 请求参数

<ParamField body="instance_uuid" type="string" required>
  实例uuid
</ParamField>

## 响应参数

<ResponseField name="code" type="integer">
  响应码
</ResponseField>

<ResponseField name="msg" type="string">
  响应信息
</ResponseField>

## 代码示例

<CodeGroup>
  ```python Python theme={null}
  import requests

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

  data = {
      "instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
      "image_name": "my-custom-image",
      "remark": "包含深度学习环境的自定义镜像"
  }

  response = requests.post(url, headers=headers, json=data)
  result = response.json()

  if result['code'] == 0:
      print("镜像保存成功")
  else:
      print(f"保存失败: {result['msg']}")
  ```

  ```javascript JavaScript theme={null}
  const axios = require('axios');

  const url = 'https://www.chenyu.cn/api/open/v2/instance/save_image';
  const headers = {
      'Authorization': 'Bearer your_api_key',
      'Content-Type': 'application/json'
  };

  const data = {
      instance_uuid: 'inst_12345678-1234-1234-1234-123456789012',
      image_name: 'my-custom-image',
      remark: '包含深度学习环境的自定义镜像'
  };

  axios.post(url, data, { headers })
      .then(response => {
          const result = response.data;
          
          if (result.code === 0) {
              console.log('镜像保存成功');
          } else {
              console.log(`保存失败: ${result.msg}`);
          }
      })
      .catch(error => {
          console.error('Error:', error.response.data);
      });
  ```

  ```curl cURL theme={null}
  curl -X POST "https://www.chenyu.cn/api/open/v2/instance/save_image" \
    -H "Authorization: Bearer your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
      "image_name": "my-custom-image",
      "remark": "包含深度学习环境的自定义镜像"
    }'
  ```
</CodeGroup>

## 响应示例

<CodeGroup>
  ```json 成功响应 theme={null}
  {
    "code": 0,
    "msg": "保存成功"
  }
  ```

  ```json 失败响应 theme={null}
  {
    "code": -1,
    "msg": "实例不存在或状态异常"
  }
  ```
</CodeGroup>

## 注意事项

* 保存镜像需要一定时间，请耐心等待
* 建议在实例关机状态下保存镜像以确保数据一致性
* 镜像名称需要唯一，不能与已有镜像重名
* 保存的镜像将出现在您的私有镜像列表中
