通过Pod创建实例
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/create_by_pod \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"pod_uuid": "<string>",
"pod_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/create_by_pod"
payload = {
"pod_uuid": "<string>",
"pod_tag": "<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({pod_uuid: '<string>', pod_tag: '<string>', gpu_uuid: '<string>', gpu_nums: 123})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/create_by_pod', 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_pod",
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([
'pod_uuid' => '<string>',
'pod_tag' => '<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_pod"
payload := strings.NewReader("{\n \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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_pod")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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_pod")
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 \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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
}
}实例管理
通过Pod创建实例
使用指定的Pod创建GPU实例
POST
/
api
/
open
/
v2
/
instance
/
create_by_pod
通过Pod创建实例
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/create_by_pod \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"pod_uuid": "<string>",
"pod_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_nums": 123
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/create_by_pod"
payload = {
"pod_uuid": "<string>",
"pod_tag": "<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({pod_uuid: '<string>', pod_tag: '<string>', gpu_uuid: '<string>', gpu_nums: 123})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/create_by_pod', 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_pod",
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([
'pod_uuid' => '<string>',
'pod_tag' => '<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_pod"
payload := strings.NewReader("{\n \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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_pod")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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_pod")
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 \"pod_uuid\": \"<string>\",\n \"pod_tag\": \"<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
}
}通过Pod创建实例
使用应用市场中的Pod创建一个新的GPU实例。请求参数
string
required
Pod uuid,可通过查询应用市场Pod接口获取
string
Pod版本标签,默认使用最新版本
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_pod"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
data = {
"pod_uuid": "pod_12345678-1234-1234-1234-123456789012",
"pod_tag": "v2.0",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_nums": 1
}
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"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_pod';
const headers = {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
};
const data = {
pod_uuid: 'pod_12345678-1234-1234-1234-123456789012',
pod_tag: 'v2.0',
gpu_uuid: 'gpu_87654321-4321-4321-4321-210987654321',
gpu_nums: 1
};
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(`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_pod" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"pod_uuid": "pod_12345678-1234-1234-1234-123456789012",
"pod_tag": "v2.0",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_nums": 1
}'
响应示例
{
"code": 0,
"msg": "success",
"data": {
"instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
"status": 1,
"title": "PyTorch深度学习实例",
"create_time": 1703145600,
"start_time": 1703145660,
"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
}
}
⌘I