通过镜像创建实例
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/create_by_image \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image_uuid": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/create_by_image"
payload = {
"image_uuid": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
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({image_uuid: '<string>', gpu_uuid: '<string>', gpu_nums: 123})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/create_by_image', 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/create_by_image",
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([
'image_uuid' => '<string>',
'gpu_uuid' => '<string>',
'gpu_nums' => 123
]),
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/create_by_image"
payload := strings.NewReader("{\n \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\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/create_by_image")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/create_by_image")
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 \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"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
}
}实例管理
通过镜像创建实例
使用指定的镜像创建GPU实例
POST
/
api
/
open
/
v2
/
instance
/
create_by_image
通过镜像创建实例
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/create_by_image \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image_uuid": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/create_by_image"
payload = {
"image_uuid": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
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({image_uuid: '<string>', gpu_uuid: '<string>', gpu_nums: 123})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/create_by_image', 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/create_by_image",
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([
'image_uuid' => '<string>',
'gpu_uuid' => '<string>',
'gpu_nums' => 123
]),
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/create_by_image"
payload := strings.NewReader("{\n \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\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/create_by_image")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/create_by_image")
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 \"image_uuid\": \"<string>\",\n \"gpu_uuid\": \"<string>\",\n \"gpu_nums\": 123\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"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
}
}通过镜像创建实例
使用个人镜像或算力市场镜像创建一个新的GPU实例。请求参数
string
required
镜像uuid,可通过查询镜像接口获取
string
required
GPU型号uuid
integer
required
使用GPU数量,可选值:1/2/4/8
响应参数
integer
响应码
string
响应信息
object
返回的实例数据
Show data
Show data
string
实例uuid
integer
实例状态
string
实例名称
integer
实例创建时间,秒级时间戳
integer
实例启动时间,秒级时间戳
integer
实例镜像保存状态
1: 上传中2: 上传成功3: 上传失败
integer
计费类型
string
实例使用的镜像uuid
string
实例使用的镜像名称
string
实例使用的镜像tag
string
实例使用的gpu uuid
string
实例使用的gpu名称
integer
实例使用的gpu数量
代码示例
import requests
from datetime import datetime
url = "https://www.chenyu.cn/api/open/v2/instance/create_by_image"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
data = {
"image_uuid": "img_12345678-1234-1234-1234-123456789012",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_nums": 2
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result['code'] == 0:
instance = result['data']
create_time = datetime.fromtimestamp(instance['create_time'])
print(f"实例创建成功!")
print(f"实例UUID: {instance['instance_uuid']}")
print(f"实例名称: {instance['title']}")
print(f"镜像名称: {instance['image_name']}")
print(f"GPU名称: {instance['gpu_name']}")
print(f"GPU数量: {instance['gpu_nums']}")
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}")
else:
print(f"创建失败: {result['msg']}")
const axios = require('axios');
const url = 'https://www.chenyu.cn/api/open/v2/instance/create_by_image';
const headers = {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
};
const data = {
image_uuid: 'img_12345678-1234-1234-1234-123456789012',
gpu_uuid: 'gpu_87654321-4321-4321-4321-210987654321',
gpu_nums: 2
};
axios.post(url, data, { headers })
.then(response => {
const result = response.data;
if (result.code === 0) {
const instance = result.data;
const createTime = new Date(instance.create_time * 1000);
console.log('实例创建成功!');
console.log(`实例UUID: ${instance.instance_uuid}`);
console.log(`实例名称: ${instance.title}`);
console.log(`镜像名称: ${instance.image_name}`);
console.log(`GPU名称: ${instance.gpu_name}`);
console.log(`GPU数量: ${instance.gpu_nums}`);
console.log(`创建时间: ${createTime.toLocaleString()}`);
if (instance.server_url.length > 0) {
console.log('服务访问地址:');
instance.server_url.forEach(url => {
console.log(` - ${url}`);
});
}
} else {
console.log(`创建失败: ${result.msg}`);
}
})
.catch(error => {
console.error('Error:', error.response.data);
});
curl -X POST "https://www.chenyu.cn/api/open/v2/instance/create_by_image" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"image_uuid": "img_12345678-1234-1234-1234-123456789012",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_nums": 2
}'
响应示例
{
"code": 0,
"msg": "success",
"data": {
"instance_uuid": "inst_87654321-4321-4321-4321-210987654321",
"status": 1,
"title": "自定义镜像实例",
"create_time": 1703145600,
"start_time": 1703145660,
"save_image_status": 2,
"charging_type": 1,
"shutdown_regular": {
"shutdown_time": 0,
"enable": false
},
"image_uuid": "image-uuid-123",
"image_name": "pytorch",
"image_tag": "2.0",
"gpu_uuid": "gpu-uuid-123",
"gpu_name": "RTX 4080",
"gpu_nums": 1
}
}
⌘I