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

# 设置空闲关机

> 设置实例空闲关机

# 设置空闲关机

为指定实例设置空闲关机功能。当实例在指定时间窗口内的 GPU 利用率和显存利用率均未超过阈值时，系统自动关机；可选同时销毁按量计费实例。

## 请求参数

<ParamField body="idle_period_minutes" type="integer" required>
  连续空闲时间，单位为分钟。仅支持 `0`、`10`、`30`、`60`、`120`；传 `0` 表示取消空闲关机
</ParamField>

<ParamField body="instance_uuid" type="string" required>
  实例 UUID。实例必须属于当前 API Key 对应的用户
</ParamField>

<ParamField body="destroy" type="boolean">
  触发自动关机时是否同时销毁实例，默认 `false`。订阅制实例不支持设为 `true`；当 `idle_period_minutes=0` 时，服务端会将其按 `false` 处理
</ParamField>

<ParamField body="idle_gpu_threshold" type="integer">
  GPU 利用率空闲阈值，范围 `0`～`100`。默认 `0`，表示使用平台全局阈值；`100` 表示跳过 GPU 利用率检查
</ParamField>

<ParamField body="idle_fb_threshold" type="integer">
  显存利用率空闲阈值，范围 `0`～`100`。默认 `0`，表示使用平台全局阈值；`100` 表示跳过显存利用率检查
</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/set_idle_close"
  headers = {
      "Authorization": "Bearer your_api_key",
      "Content-Type": "application/json"
  }

  # 设置空闲60分钟后自动关机
  data = {
      "instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
      "idle_period_minutes": 60,
      "destroy": False,
      "idle_gpu_threshold": 10,
      "idle_fb_threshold": 10
  }

  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/set_idle_close';
  const headers = {
      'Authorization': 'Bearer your_api_key',
      'Content-Type': 'application/json'
  };

  // 设置空闲60分钟后自动关机
  const data = {
      instance_uuid: 'inst_12345678-1234-1234-1234-123456789012',
      idle_period_minutes: 60,
      destroy: false,
      idle_gpu_threshold: 10,
      idle_fb_threshold: 10
  };

  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/set_idle_close" \
    -H "Authorization: Bearer your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
      "idle_period_minutes": 60,
      "destroy": false,
      "idle_gpu_threshold": 10,
      "idle_fb_threshold": 10
    }'
  ```
</CodeGroup>

## 响应示例

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

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

## 注意事项

* 系统按分钟检查正在运行的实例；只有指定时间窗口内每张 GPU 的利用率和显存利用率都没有超过对应阈值，才判定为空闲
* `idle_gpu_threshold=0`、`idle_fb_threshold=0` 表示使用平台全局阈值，不代表阈值为 0%
* 阈值设为 `100` 会跳过对应指标检查；请谨慎使用，两个阈值都为 `100` 时，实例达到空闲时间后会直接被判定为空闲
* `destroy=true` 仅适用于非订阅制实例。销毁操作会释放实例，不能作为普通关机恢复


## OpenAPI

````yaml cpn-ai.openapi.json POST /api/open/v2/instance/set_idle_close
openapi: 3.0.1
info:
  title: center-ai
  description: ''
  version: 1.0.0
servers:
  - url: https://www.chenyu.cn
    description: 生产环境
security: []
tags:
  - name: 工作流管理
    description: 工作流市场、运行提交和执行查询接口
  - name: 外部模型任务
    description: 外部模型任务提交、查询、取消和事件记录接口
paths:
  /api/open/v2/instance/set_idle_close:
    post:
      tags:
        - 实例管理
      summary: 设置空闲关机
      description: 设置实例在持续低 GPU 和显存利用率达到指定时间后自动关机，传 idle_period_minutes=0 可取消。
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - instance_uuid
                - idle_period_minutes
              properties:
                instance_uuid:
                  type: string
                  description: 实例 UUID
                idle_period_minutes:
                  type: integer
                  enum:
                    - 0
                    - 10
                    - 30
                    - 60
                    - 120
                  description: 连续空闲时间，单位分钟。0 表示取消空闲关机
                destroy:
                  type: boolean
                  default: false
                  description: 自动关机时是否同时销毁实例。订阅制实例不支持 true；取消空闲关机时会强制按 false 处理
                idle_gpu_threshold:
                  type: integer
                  minimum: 0
                  maximum: 100
                  default: 0
                  description: GPU 利用率空闲阈值，0 使用平台全局阈值，100 跳过 GPU 利用率检查
                idle_fb_threshold:
                  type: integer
                  minimum: 0
                  maximum: 100
                  default: 0
                  description: 显存利用率空闲阈值，0 使用平台全局阈值，100 跳过显存利用率检查
      responses:
        '200':
          description: 设置结果
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - msg
                properties:
                  code:
                    type: integer
                    description: 响应码，0 表示成功
                  msg:
                    type: string
                    description: 响应信息
      deprecated: false
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API Key，格式：Bearer your_api_key

````