查询算力单元列表
更新时间:2025-01-13
功能介绍
用于筛选算力单元列表信息。
使用说明
本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程。
权限说明
调用本文API,需符合以下权限要求,权限介绍及分配,请查看角色与权限控制列表、账号创建与权限分配。需具有以下任一权限:
- 完全控制千帆大模型平台的权限:QianfanFullControlAccessPolicy
- 运维操作千帆大模型平台预测服务的权限:QianfanServiceOperateAccessPolicy
- 只读访问千帆大模型平台预测服务的权限:QianfanServiceReadAccessPolicy
SDK调用
调用示例
import os
from qianfan import resources
# 通过环境变量初始化认证信息
# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"
resp = resources.console.utils.call_action(
# 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
"/v2/computeunit",
# 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
"DescribeComputeUnits",
# 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
{
"region": "bj",
"paymentTiming": "Prepaid",
"type": "gpu-1"
}
)
print(resp.body)
package main
import (
"context"
"fmt"
"os"
"github.com/baidubce/bce-qianfan-sdk/go/qianfan"
)
func main() {
// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
ca := qianfan.NewConsoleAction()
res, err := ca.Call(context.TODO(),
// 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
"/v2/computeunit",
// 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
"DescribeComputeUnits",
// 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
map[string]interface{}{
"region": "bj",
"paymentTiming": "Prepaid",
"type": "gpu-1",
})
if err != nil {
panic(err)
}
fmt.Println(string(res.Body))
}
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.console.ConsoleResponse;
import com.baidubce.qianfan.util.CollUtils;
import com.baidubce.qianfan.util.Json;
import java.util.Map;
public class Dome {
public static void main(String args[]){
// 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
ConsoleResponse<Map<String, Object>> response = qianfan.console()
// 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
.route("/v2/computeunit")
// 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
.action("DescribeComputeUnits")
// 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
// Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
// 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
.body(CollUtils.mapOf(
"region", "bj",
"paymentTiming", "Prepaid",
"type", "gpu-1"
))
.execute();
System.out.println(Json.serialize(response));
}
}
import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";
// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');
async function main() {
//base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
//action:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
//data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
const res = await consoleAction({base_api_route: '/v2/computeunit', action: 'DescribeComputeUnits', data: {
"region": "bj",
"paymentTiming": "Prepaid",
"type": "gpu-1"
});
console.log(res);
}
main();
返回示例
{
"requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
"result": {
"computeUnitInstanceList": [
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-12T12:29:08Z",
"expiredTime": "2025-01-12T12:29:08Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
},
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-11T06:21:56Z",
"expiredTime": "2025-01-11T06:21:56Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
}
]
}
{
"requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
"result": {
"computeUnitInstanceList": [
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-12T12:29:08Z",
"expiredTime": "2025-01-12T12:29:08Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
},
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-11T06:21:56Z",
"expiredTime": "2025-01-11T06:21:56Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
}
]
}
{
"requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
"result": {
"computeUnitInstanceList": [
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-12T12:29:08Z",
"expiredTime": "2025-01-12T12:29:08Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
},
{
"instanceId": "unit-xxx",
"region": "bj",
"status": "Released",
"type": "gpu-1",
"totalComputeUnits": 2,
"usedComputeUnits": 0,
"paymentTiming": "Prepaid",
"startTime": "2024-12-11T06:21:56Z",
"expiredTime": "2025-01-11T06:21:56Z",
"reservationLength": 1,
"reservationTimeUnit": "MONTH",
"creator": "xxx"
}
]
}
{
requestId: '1bef3f87-c5b2-4419-936b-50f9884f10d4',
result: {
computeUnitInstanceList: [
{
instanceId: 'unit-xxx',
region: 'bj',
status: 'Released',
type: 'gpu-1',
totalComputeUnits: 2,
usedComputeUnits: 0,
paymentTiming: 'Prepaid',
startTime: '2024-12-12T12:29:08Z',
expiredTime: '2025-01-12T12:29:08Z',
reservationLength: 1,
reservationTimeUnit: 'MONTH',
creator: 'xxx'
},
{
instanceId: 'unit-xxx',
region: 'bj',
status: 'Released',
type: 'gpu-1',
totalComputeUnits: 2,
usedComputeUnits: 0,
paymentTiming: 'Prepaid',
startTime: '2024-12-11T06:21:56Z',
expiredTime: '22025-01-11T06:21:56Z',
reservationLength: 1,
reservationTimeUnit: 'MONTH',
creator: 'xxx'
}
]
}
请求参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
paymentTiming | string | 否 | 付费类型,可选值如下: · Prepaid:表示预付费 · Postpaid:表示后付费 |
region | string | 否 | 资源地域,可选值如下: · bj:北京 · bd:保定 |
type | string | 否 | 资源类型,可选值如下: · CPU:cpu · 加速卡I型:gpu-1 · 加速卡Ⅱ型:gpu-2 · 加速卡Ⅲ型:gpu-3 · 加速卡Ⅳ型:gpu-4 · 加速卡Ⅴ型:gpu-5 · 加速卡Ⅵ型:gpu-6 |
返回参数
名称 | 类型 | 描述 |
---|---|---|
requestId | string | 请求ID |
result | object | 请求结果 |
result说明
名称 | 类型 | 描述 |
---|---|---|
computeUnitInstanceList | list<computeUnitInstance> | 实例列表 |
computeUnitInstance说明
名称 | 类型 | 描述 |
---|---|---|
instanceId | string | 实例ID |
region | string | 资源地域,具体值如下: · bj:北京 · bd:保定 · sz:苏州 · gz:广州 · yq:阳泉 · global:全局 |
status | string | 资源状态,具体值如下: · Creating:创建中 · CreateFailed:创建失败 · Running:使用中 · Releasing:释放中 · Released:已释放 · Reconfiguring:变配中 · ReconfigureFailed:变配失败 |
type | string | 资源类型,具体值如下: · CPU:cpu · 加速卡I型:gpu-1 · 加速卡Ⅱ型:gpu-2 · 加速卡Ⅲ型:gpu-3 · 加速卡Ⅳ型:gpu-4 · 加速卡Ⅴ型:gpu-5 · 加速卡Ⅵ型:gpu-6 |
totalComputeUnits | int | 算力单元总数 |
usedComputeUnits | int | 已用算力单元数 |
paymentTiming | string | 资源付费类型,具体值如下: · Prepaid:预付费 · Postpaid:后付费 |
startTime | string | 算力单元实例的开始时间 |
expiredTime | string | 算力单元实例的到期时间 |
releaseTime | string | 自动释放时间,说明:当资源付费类型为后付费且有设置自动释放时间时,返回该字段 |
reservationLength | int | 实例时长,说明:当资源付费类型为预付费,即paymentTiming=Prepaid时,返回该字段 |
reservationTimeUnit | string | 实例时长单位,说明:当资源付费类型为预付费,即paymentTiming=Prepaid时,返回该字段 |
creator | string | 资源创建人 |
autoRenew | object | 自动续费设置信息,说明:当资源付费类型为预付费且有设置自动续费规则时,返回该字段 |
autoRenew说明
名称 | 类型 | 描述 |
---|---|---|
renewTime | int | 续费时长 |
renewTimeUnit | string | 续费时长单位,具体值如下: · MONTH:月 · YEAR:年 |