设置空闲关机
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/set_idle_close \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"instance_uuid": "<string>",
"destroy": false,
"idle_gpu_threshold": 0,
"idle_fb_threshold": 0
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/set_idle_close"
payload = {
"instance_uuid": "<string>",
"destroy": False,
"idle_gpu_threshold": 0,
"idle_fb_threshold": 0
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instance_uuid: '<string>',
destroy: false,
idle_gpu_threshold: 0,
idle_fb_threshold: 0
})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/set_idle_close', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/instance/set_idle_close",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'instance_uuid' => '<string>',
'destroy' => false,
'idle_gpu_threshold' => 0,
'idle_fb_threshold' => 0
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/set_idle_close"
payload := strings.NewReader("{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/instance/set_idle_close")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/set_idle_close")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>"
}实例管理
设置空闲关机
设置实例空闲关机
POST
/
api
/
open
/
v2
/
instance
/
set_idle_close
设置空闲关机
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/set_idle_close \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"instance_uuid": "<string>",
"destroy": false,
"idle_gpu_threshold": 0,
"idle_fb_threshold": 0
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/set_idle_close"
payload = {
"instance_uuid": "<string>",
"destroy": False,
"idle_gpu_threshold": 0,
"idle_fb_threshold": 0
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instance_uuid: '<string>',
destroy: false,
idle_gpu_threshold: 0,
idle_fb_threshold: 0
})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/set_idle_close', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/instance/set_idle_close",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'instance_uuid' => '<string>',
'destroy' => false,
'idle_gpu_threshold' => 0,
'idle_fb_threshold' => 0
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/set_idle_close"
payload := strings.NewReader("{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/instance/set_idle_close")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/set_idle_close")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance_uuid\": \"<string>\",\n \"destroy\": false,\n \"idle_gpu_threshold\": 0,\n \"idle_fb_threshold\": 0\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>"
}设置空闲关机
为指定实例设置空闲关机功能。当实例在指定时间窗口内的 GPU 利用率和显存利用率均未超过阈值时,系统自动关机;可选同时销毁按量计费实例。请求参数
integer
required
连续空闲时间,单位为分钟。仅支持
0、10、30、60、120;传 0 表示取消空闲关机string
required
实例 UUID。实例必须属于当前 API Key 对应的用户
boolean
触发自动关机时是否同时销毁实例,默认
false。订阅制实例不支持设为 true;当 idle_period_minutes=0 时,服务端会将其按 false 处理integer
GPU 利用率空闲阈值,范围
0~100。默认 0,表示使用平台全局阈值;100 表示跳过 GPU 利用率检查integer
显存利用率空闲阈值,范围
0~100。默认 0,表示使用平台全局阈值;100 表示跳过显存利用率检查响应参数
integer
响应码
string
响应信息
代码示例
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']}")
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 -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
}'
响应示例
{
"code": 0,
"msg": "设置成功"
}
{
"code": -1,
"msg": "实例不存在或状态异常"
}
注意事项
- 系统按分钟检查正在运行的实例;只有指定时间窗口内每张 GPU 的利用率和显存利用率都没有超过对应阈值,才判定为空闲
idle_gpu_threshold=0、idle_fb_threshold=0表示使用平台全局阈值,不代表阈值为 0%- 阈值设为
100会跳过对应指标检查;请谨慎使用,两个阈值都为100时,实例达到空闲时间后会直接被判定为空闲 destroy=true仅适用于非订阅制实例。销毁操作会释放实例,不能作为普通关机恢复
Authorizations
API Key,格式:Bearer your_api_key
Body
application/json
实例 UUID
连续空闲时间,单位分钟。0 表示取消空闲关机
Available options:
0, 10, 30, 60, 120 自动关机时是否同时销毁实例。订阅制实例不支持 true;取消空闲关机时会强制按 false 处理
GPU 利用率空闲阈值,0 使用平台全局阈值,100 跳过 GPU 利用率检查
Required range:
0 <= x <= 100显存利用率空闲阈值,0 使用平台全局阈值,100 跳过显存利用率检查
Required range:
0 <= x <= 100⌘I