购买算力单元实例
更新时间:2025-05-16
功能介绍
用于购买当前服务部署所需的算力单元实例。
注意事项
- 当库存不足或余额不足时,可能会导致购买失败。
- 本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程。
权限说明
调用本文API,需符合以下权限要求,权限介绍及分配,请查看角色与权限控制列表、账号创建与权限分配。需具有以下任一权限:
- 完全控制千帆大模型平台的权限:QianfanFullControlAccessPolicy
- 运维操作千帆大模型平台预测服务的权限:QianfanServiceOperateAccessPolicy
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 "PurchaseComputeUnit",
14 # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
15 {
16 "serviceId":"svco-48esssdpa594",
17 "billing":{
18 "paymentTiming":"Prepaid",
19 "reservation":{
20 "reservationTimeUnit":"Month",
21 "reservationLength":5
22 }
23 },
24 "replicasCount":5
25 }
26)
27print(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 "PurchaseComputeUnit",
23 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
24 map[string]interface{}{
25 "serviceId": "svco-48esssdpa594",
26 "replicasCount": 5,
27 "billing": map[string]any{
28 "paymentTiming": "Prepaid",
29 "reservation": map[string]any{
30 "reservationTimeUnit": "Month",
31 "reservationLength": 5,
32 },
33 },
34 })
35
36 if err != nil {
37 panic(err)
38 }
39
40 fmt.Println(string(res.Body))
41
42}
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("PurchaseComputeUnit")
17 // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
18 // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
19 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
20 .body(CollUtils.mapOf(
21 "serviceId","svco-48esssdpa594",
22 "billing",CollUtils.mapOf(
23 "paymentTiming","Prepaid",
24 "reservation",CollUtils.mapOf(
25 "reservationTimeUnit","Month",
26 "reservationLength",5
27 )
28 ),
29 "replicasCount",5
30 ))
31 .execute();
32
33 System.out.println(Json.serialize(response));
34 }
35}
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: 'PurchaseComputeUnit', data: {
12 "serviceId":"svco-48esssdpa594",
13 "billing":{
14 "paymentTiming":"Prepaid",
15 "reservation":{
16 "reservationTimeUnit":"Month",
17 "reservationLength":5
18 }
19 },
20 "replicasCount":5
21 }
22 });
23
24 console.log(res);
25}
26
27main();
返回示例
1{
2 "requestId":"1bef3f87-c5b2-4419-936b-50f9884f10d4",
3 "result":{
4 "instanceId":"44961088fxxxx9e9379f5daf",
5 "orderId":"7b468732xxxxxx8364292"
6 }
7}
1{
2 "requestId":"1bef3f87-c5b2-4419-936b-50f9884f10d4",
3 "result":{
4 "instanceId":"44961088fxxxx9e9379f5daf",
5 "orderId":"7b468732xxxxxx8364292"
6 }
7}
1{
2 "requestId":"1bef3f87-c5b2-4419-936b-50f9884f10d4",
3 "result":{
4 "instanceId":"44961088fxxxx9e9379f5daf",
5 "orderId":"7b468732xxxxxx8364292"
6 }
7}
1{
2 requestId:'1bef3f87-c5b2-4419-936b-50f9884f10d4',
3 result:{
4 instanceId:'44961088fxxxx9e9379f5daf',
5 orderId:'7b468732xxxxxx8364292'
6 }
7}
请求参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
serviceId | string | 是 | 服务ID |
billing | object | 是 | 订单、计费相关参数 |
replicasCount | int | 是 | 购买副本数量 |
billing说明
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
paymentTiming | string | 是 | 付费类型,可选值: · Prepaid:表示预付费 · Postpaid:表示后付费 |
reservation | object | 否 | 保留信息,说明: (1)只有当付费类型为预付费,即paymentTiming值为Prepaid时,该字段必填 (2)付费类型为后付费,无需填写此参数 |
releaseTime | string | 否 | 定时释放时间,说明: (1)只有当付费类型为后付费,即paymentTiming值为Postpaid时,该字段有效 (2)支持RFC3339格式和标准格式,如 2030-01-25T12:30:30+08:00 、2030-01-25 12:30:30 |
reservation说明
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
reservationTimeUnit | string | 是 | 时间单位,可选值: · Month: 月 |
reservationLength | int | 是 | 购买时长,说明: · 时间单位为月,取值范围 [1-12] |
autoRenew | boolean | 否 | 是否自动续费,可选值: · true:是 · false:否,默认值为false |
autoRenewTimeUnit | String | 否 | 自动续费周期时间单位,默认值为Month,可选值: · Month:月 |
autoRenewTime | int | 否 | 自动续费时长,说明: (1)单位:月 (2)默认值为1,取值范围:[1,6] |
返回参数
名称 | 类型 | 描述 |
---|---|---|
requestId | string | 请求ID |
result | object | 请求结果 |
result说明
名称 | 类型 | 描述 |
---|---|---|
instanceId | string | 实例ID |
orderId | string | 订单ID |