查询算力单元实例列表
更新时间:2025-05-16
功能介绍
用于查询当前服务已使用的全部或特定算力单元实例列表。
使用说明
本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程。
权限说明
调用本文API,需符合以下权限要求,权限介绍及分配,请查看角色与权限控制列表、账号创建与权限分配。需具有以下任一权限:
- 完全控制千帆大模型平台的权限:QianfanFullControlAccessPolicy
 - 运维操作千帆大模型平台预测服务的权限:QianfanServiceOperateAccessPolicy
 - 只读访问千帆大模型平台预测服务的权限:QianfanServiceReadAccessPolicy
 
SDK调用
调用示例
1import os
2from qianfan  import resources
3
4# 通过环境变量初始化认证信息
5# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
6os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
7os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"
8
9resp = resources.console.utils.call_action(
10    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
11    "/v2/serviceresources", 
12    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
13    "DescribeComputeUnits", 
14    # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
15    {
16        "serviceId":"svco-48exxxa594",
17        "paymentTiming":"Prepaid"
18    }
19)
20
21print(resp.body)
        1package main
2
3import (
4	"context"
5	"fmt"
6    "os"
7
8	"github.com/baidubce/bce-qianfan-sdk/go/qianfan"
9)
10
11func main() {
12	 // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
13	os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
14	os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
15    
16	ca := qianfan.NewConsoleAction()
17    
18	res, err := ca.Call(context.TODO(),
19    // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
20    "/v2/serviceresources",
21    // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
22    "DescribeComputeUnits",
23    // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
24    map[string]interface{}{
25		"serviceId":       "svco-48exxxa594",
26		"paymentTiming": "Prepaid",
27	})
28	if err != nil {
29		panic(err)
30	}
31	fmt.Println(string(res.Body))
32	
33}
        1import com.baidubce.qianfan.Qianfan;
2import com.baidubce.qianfan.model.console.ConsoleResponse;
3import com.baidubce.qianfan.util.CollUtils;
4import com.baidubce.qianfan.util.Json;
5import java.util.Map;
6
7public class Dome {
8    public static void main(String args[]){
9        // 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
10        Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
11          
12        ConsoleResponse<Map<String, Object>> response = qianfan.console()
13                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
14                .route("/v2/serviceresources")
15                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
16                .action("DescribeComputeUnits")
17                // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
18                // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
19                // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
20                .body(CollUtils.mapOf(
21                        "serviceId","svco-48exxxa594",
22                        "paymentTiming","Prepaid"
23                ))
24                .execute();
25
26        System.out.println(Json.serialize(response));
27    }
28}
        1import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";
2
3// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
4setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
5setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');
6
7async function main() {
8  //base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
9  //action:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
10  //data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
11  const res = await consoleAction({base_api_route: '/v2/serviceresources', action: 'DescribeComputeUnits', data: {
12        "serviceId":"svco-48exxxa594",
13        "paymentTiming":"Prepaid"
14    }
15  });    
16    
17  console.log(res);
18}
19
20main();
        返回示例
1{
2    "requestId":"1bef3f87-cxxxx50f9884f10d4",
3    "result":{
4        "instances":[
5            {
6                "instanceId":"a0085162xxx9d19e58e",
7                "paymentTiming":"Prepaid",
8                "replicasCount":5,
9                "status":"Running",
10                "startTime":"2024-04-01T10:00:00Z",
11                "expiredTime":"2024-05-01T10:00:00Z"
12            }
13        ]
14    }
15}
        1{
2    "requestId":"1bef3f87-cxxxx50f9884f10d4",
3    "result":{
4        "instances":[
5            {
6                "instanceId":"a0085162xxx9d19e58e",
7                "paymentTiming":"Prepaid",
8                "replicasCount":5,
9                "status":"Running",
10                "startTime":"2024-04-01T10:00:00Z",
11                "expiredTime":"2024-05-01T10:00:00Z"
12            }
13        ]
14    }
15}
        1{
2    "requestId":"1bef3f87-cxxxx50f9884f10d4",
3    "result":{
4        "instances":[
5            {
6                "instanceId":"a0085162xxx9d19e58e",
7                "paymentTiming":"Prepaid",
8                "replicasCount":5,
9                "status":"Running",
10                "startTime":"2024-04-01T10:00:00Z",
11                "expiredTime":"2024-05-01T10:00:00Z"
12            }
13        ]
14    }
15}
        1{
2    requestId:'1bef3f87-cxxxx50f9884f10d4',
3    result:{
4        instances:[
5            {
6                instanceId:'a0085162xxx9d19e58e',
7                paymentTiming:'Prepaid',
8                replicasCount:5,
9                status:'Running',
10                startTime:'2024-04-01T10:00:00Z'
11                expiredTime:'2024-05-01T10:00:00Z'
12            }
13        ]
14    }
15}
        请求参数
| 名称 | 类型 | 必填 | 描述 | 
|---|---|---|---|
| serviceId | string | 是 | 服务ID | 
| paymentTiming | string | 否 | 付费类型,说明: (1)不填写该参数,默认查询当前服务所有正在使用的算力单元实例 (2)填写该字段,表示查询当前服务正在使用的特定付费类型的算力单元实例,可选值: · Prepaid:预付费 · Postpaid:表示后付费  | 
返回参数
| 名称 | 类型 | 描述 | 
|---|---|---|
| requestId | string | 请求ID | 
| result | object | 请求结果 | 
result说明
| 名称 | 类型 | 描述 | 
|---|---|---|
| instances | List<object> | 实例列表 | 
instances说明
| 名称 | 类型 | 描述 | 
|---|---|---|
| instanceId | string | 实例ID | 
| paymentTiming | string | 付费类型,说明: · Prepaid:预付费 · Postpaid:后付费  | 
| replicasCount | int | 副本数 | 
| status | string | 资源状态,说明: · 1:Creating · 2:Running · 3:Deleted,表示已过期  | 
| startTime | string | 开始时间,说明: (1)当status=Creating,该字段为空 (2)当status是Running或Deleted,该字段表示算力单元实例的开始时间  | 
| expiredTime | string | 算力单元实例的到期时间,说明: (1) 当status=Creating,该字段为空 (2)当status是Running或Deleted时,该字段表示算力单元实例的到期时间  | 
