查询实例列表
curl --request GET \
--url https://www.chenyu.cn/api/open/v2/instance/list \
--header 'Authorization: Bearer <token>'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/list"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://www.chenyu.cn/api/open/v2/instance/list', 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/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/list"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://www.chenyu.cn/api/open/v2/instance/list")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"instance_list": [
{
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"server_url": [
{}
],
"server_map": [
{
"title": "<string>",
"url": "<string>",
"port_type": "<string>",
"protocol": "<string>",
"ssh_info": {
"host": "<string>",
"port": 123,
"username": "<string>",
"password": "<string>"
}
}
],
"save_image_status": 123,
"charging_type": 123,
"shutdown_regular": {
"shutdown_time": 123,
"enable": true
},
"image_uuid": "<string>",
"image_name": "<string>",
"image_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_name": "<string>",
"gpu_nums": 123
}
],
"total": 123
}
}实例管理
查询实例列表
查询用户的实例列表
GET
/
api
/
open
/
v2
/
instance
/
list
查询实例列表
curl --request GET \
--url https://www.chenyu.cn/api/open/v2/instance/list \
--header 'Authorization: Bearer <token>'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/list"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://www.chenyu.cn/api/open/v2/instance/list', 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/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/list"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://www.chenyu.cn/api/open/v2/instance/list")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"instance_list": [
{
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"server_url": [
{}
],
"server_map": [
{
"title": "<string>",
"url": "<string>",
"port_type": "<string>",
"protocol": "<string>",
"ssh_info": {
"host": "<string>",
"port": 123,
"username": "<string>",
"password": "<string>"
}
}
],
"save_image_status": 123,
"charging_type": 123,
"shutdown_regular": {
"shutdown_time": 123,
"enable": true
},
"image_uuid": "<string>",
"image_name": "<string>",
"image_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_name": "<string>",
"gpu_nums": 123
}
],
"total": 123
}
}查询实例列表
获取当前用户的所有实例列表,支持分页查询。在线测试: 您可以在右侧的API Playground中输入您的API Key,然后点击”Try it”按钮直接测试这个接口。API Key格式为
Bearer your_api_key。请求参数
此接口不需要任何请求参数。响应参数
integer
响应码
string
响应信息
object
返回数据
Show data
Show data
array
实例列表
Show instance_list
Show instance_list
string
实例uuid
integer
实例状态
0: 已创建1: 开机中(首次创建实例的开机;与24的区别是24为关机后的开机)2: 运行中3: 关机中4: 已关机21: 关机中22: 已关机23: 已关机(异常)24: 开机中27: 重启中
string
实例名称
integer
实例创建时间,秒级时间戳
integer
实例启动时间,秒级时间戳
array
开放服务url列表
array
integer
实例镜像保存状态
1: 上传中2: 上传成功3: 上传失败
integer
计费类型
string
实例使用的镜像uuid
string
实例使用的镜像名称
string
实例使用的镜像tag
string
实例使用的gpu uuid
string
实例使用的gpu名称
integer
实例使用的gpu数量
integer
总记录数量
代码示例
import requests
from datetime import datetime
url = "https://www.chenyu.cn/api/open/v2/instance/list"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
params = {
"page": 1,
"page_size": 10
}
response = requests.get(url, headers=headers, params=params)
result = response.json()
if result['code'] == 0:
print(f"总共有 {result['data']['total']} 个实例")
for instance in result['data']['instance_list']:
create_time = datetime.fromtimestamp(instance['create_time'])
print(f"实例名称: {instance['title']}")
print(f"实例UUID: {instance['instance_uuid']}")
print(f"状态: {instance['status']}")
print(f"GPU: {instance['gpu_name']} x{instance['gpu_nums']}")
print(f"镜像: {instance['image_name']}")
print(f"创建时间: {create_time.strftime('%Y-%m-%d %H:%M:%S')}")
if instance['server_url']:
print("服务地址:")
for url in instance['server_url']:
print(f" - {url}")
if instance.get('server_map'):
print("服务详情:")
for service in instance['server_map']:
print(f" - {service['title']}: {service['url']}")
if service.get('ssh_info'):
ssh = service['ssh_info']
print(f" SSH连接: {ssh['username']}@{ssh['host']}:{ssh['port']}")
print("---")
else:
print(f"查询失败: {result['msg']}")
const axios = require('axios');
const url = 'https://www.chenyu.cn/api/open/v2/instance/list';
const headers = {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
};
const params = {
page: 1,
page_size: 10
};
axios.get(url, { headers, params })
.then(response => {
const result = response.data;
if (result.code === 0) {
console.log(`总共有 ${result.data.total} 个实例`);
result.data.instance_list.forEach(instance => {
const createTime = new Date(instance.create_time * 1000);
console.log(`实例名称: ${instance.title}`);
console.log(`实例UUID: ${instance.instance_uuid}`);
console.log(`状态: ${instance.status}`);
console.log(`GPU: ${instance.gpu_name} x${instance.gpu_nums}`);
console.log(`镜像: ${instance.image_name}`);
console.log(`创建时间: ${createTime.toLocaleString()}`);
if (instance.server_url.length > 0) {
console.log('服务地址:');
instance.server_url.forEach(url => {
console.log(` - ${url}`);
});
}
if (instance.server_map && instance.server_map.length > 0) {
console.log('服务详情:');
instance.server_map.forEach(service => {
console.log(` - ${service.title}: ${service.url}`);
if (service.ssh_info) {
const ssh = service.ssh_info;
console.log(` SSH连接: ${ssh.username}@${ssh.host}:${ssh.port}`);
}
});
}
console.log('---');
});
} else {
console.log(`查询失败: ${result.msg}`);
}
})
.catch(error => {
console.error('Error:', error.response.data);
});
curl -X GET "https://www.chenyu.cn/api/open/v2/instance/list?page=1&page_size=10" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json"
响应示例
{
"code": 0,
"msg": "success",
"data": {
"instance_list": [
{
"instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
"status": 2,
"title": "我的PyTorch实例",
"create_time": 1703145600,
"start_time": 1703145660,
"server_url": [
"https://jupyter-inst123.chenyu.team",
"https://ssh-inst123.chenyu.team"
],
"server_map": [
{
"title": "Jupyter Lab",
"url": "https://jupyter-inst123.chenyu.team",
"port_type": "http",
"protocol": "tcp"
},
{
"title": "SSH Terminal",
"url": "ssh://ssh-inst123.chenyu.team:22",
"port_type": "ssh",
"protocol": "tcp",
"ssh_info": {
"host": "inst12345678123412341234123456789012.gzxx.chenyu.team",
"port": 22001,
"username": "root",
"password": "generated_password_123"
}
}
],
"save_image_status": 2,
"charging_type": 1,
"shutdown_regular": {
"shutdown_time": 1703232000,
"enable": true
},
"image_uuid": "img_87654321-4321-4321-4321-210987654321",
"image_name": "PyTorch 2.0 环境",
"image_tag": "v2.0",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_name": "NVIDIA RTX 4090",
"gpu_nums": 1
}
],
"total": 1
}
}
⌘I