资讯 社区 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

查询服务调用情况

功能介绍

用于查询服务调用情况。

使用说明

本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程

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,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求地址的后缀
    "/v2/service", 
    # 调用本文API,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求参数-Query参数的Action
    "DescribeServiceMetric", 
    # 对应HTTP调用文档-请求说明-请求参数-Body参数,具体使用请查看Body参数说明,根据实际使用选择参数
    {
        "serviceId": ["svco-tv5t4zpkj3za"],
        "appId": ["1483416575"],
        "startTime": "2024-04-23T00:00:00Z",
        "endTime": "2024-04-24T23:00:00Z"
    }
)

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,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求地址的后缀
    "/v2/service",
    // 调用本文API,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求参数-Query参数的Action
    "DescribeServiceMetric",
    // 对应HTTP调用文档-请求说明-请求参数-Body参数,具体使用请查看Body参数说明,根据实际使用选择参数
    map[string]interface{}{
                "serviceId": []string{"svco-tv5t4zpkj3za"},
                "appId": []string{"1483416575"},
                "startTime": "2024-04-23T00:00:00Z",
                "endTime": "2024-04-24T23:00:00Z",
    })
    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,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求地址的后缀
                .route("/v2/service")
                // 调用本文API,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求参数-Query参数的Action
                .action("DescribeServiceMetric")
                // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
                // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
                // 对应HTTP调用文档-请求说明-请求参数-Body参数,具体使用请查看Body参数说明,根据实际使用选择参数
                .body(CollUtils.mapOf(
                    "serviceId", new String[]{"svco-tv5t4zpkj3za"},
                    "appId", new String[]{"1483416575"},
                    "startTime", "2024-04-23T00:00:00Z",
                    "endTime", "2024-04-24T23:00:00Z"
                ))
                .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,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求地址的后缀
  //action:调用本文API,该参数值为固定值,无需修改;对应HTTP调用文档-请求说明-请求参数-Query参数的Action
  //data:对应HTTP调用文档-请求说明-请求参数-Body参数,具体使用请查看Body参数说明,根据实际使用选择参数
  const res = await consoleAction({base_api_route: '/v2/service', action: 'DescribeServiceMetric', data: {
       "serviceId": ["svco-tv5t4zpkj3za"],
        "appId": ["1483416575"],
        "startTime": "2024-04-23T00:00:00Z",
        "endTime": "2024-04-24T23:00:00Z"
    }
  });    
    
  console.log(res);
}

main();

返回示例

{
    "requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
    "result": {
        "startTime": "2024-04-23T00:00:00Z",
        "endTime": "2024-04-24T23:00:00Z",
        "serviceList": [
            {
                "serviceId": "svco-tvxxxxda",
                "serviceName": "sunxxxu0506",
                "appList": [
                    {
                        "appId": "14xxx75",
                        "metric": {
                            "inputTokensTotal": 900,
                            "outputTokensTotal": 721,
                            "tokensTotal": 1621,
                            "succeedCallTotal": 575,
                            "failureCallTotal": 100,
                            "callTotal": 675
                        }
                    }
                ]
            }
        ]
    }
}
{
    "requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
    "result": {
        "startTime": "2024-04-23T00:00:00Z",
        "endTime": "2024-04-24T23:00:00Z",
        "serviceList": [
            {
                "serviceId": "svco-tvxxxxda",
                "serviceName": "sunxxxu0506",
                "appList": [
                    {
                        "appId": "14xxx75",
                        "metric": {
                            "inputTokensTotal": 900,
                            "outputTokensTotal": 721,
                            "tokensTotal": 1621,
                            "succeedCallTotal": 575,
                            "failureCallTotal": 100,
                            "callTotal": 675
                        }
                    }
                ]
            }
        ]
    }
}
{
    "requestId": "1bef3f87-c5b2-4419-936b-50f9884f10d4",
    "result": {
        "startTime": "2024-04-23T00:00:00Z",
        "endTime": "2024-04-24T23:00:00Z",
        "serviceList": [
            {
                "serviceId": "svco-tvxxxxda",
                "serviceName": "sunxxxu0506",
                "appList": [
                    {
                        "appId": "14xxx75",
                        "metric": {
                            "inputTokensTotal": 900,
                            "outputTokensTotal": 721,
                            "tokensTotal": 1621,
                            "succeedCallTotal": 575,
                            "failureCallTotal": 100,
                            "callTotal": 675
                        }
                    }
                ]
            }
        ]
    }
}
{
    requestId: '1bef3f87-c5b2-4419-936b-50f9884f10d4',
    result: {
        startTime: '2024-04-23T00:00:00Z'
        endTime: '2024-04-24T23:00:00Z'
        serviceList: [
            {
                serviceId: 'svco-tvxxxxda',
                serviceName: 'sunxxxu0506',
                appList: [
                    {
                        appId: '14xxx75',
                        metric: {
                            inputTokensTotal: 900,
                            outputTokensTotal: 721,
                            tokensTotal: 1621,
                            succeedCallTotal: 575,
                            failureCallTotal: 100,
                            callTotal: 675
                        }
                    }
                ]
            }
        ]
    }
}

请求参数

名称 类型 必填 描述
serviceId list<string> 服务ID,说明:
(1)不填写该字段,默认查询全部服务ID
(2)可以通过任一方式获取:
方式一:通过调用接口创建服务,返回参数serviceId获取
方式二:通过千帆控制台-在线服务-我的服务页面,点击某服务详情查看,如下图所示:
image.png
(3)该接口超时时间大约为5s,查询服务过多,调用接口可能会出错
appId list<string> 应用ID,说明:
(1)不填写该字段,默认查询全部应用
(2)通过千帆控制台-在线服务-应用接入页面,查看AppID,如下图所示:
image.png
(3)该接口超时时间大约为5s,查询应用过多,调用接口可能会出错
startTime string 查询起始时间,说明:
(1)格林威治时间,格式为2016-04-06T08:23:00Z,精确到分钟,如果填写秒数默认使用00替换
(2)该接口超时时间为5s,时间范围选择太大,调用接口可能会出错
endTime string 查询终止时间,说明:
(1)格林威治时间,格式为2016-04-06T08:23:00Z,精确到分钟,如果填写秒数默认使用59替换
(2)该接口超时时间为5s,时间范围选择太大,调用接口可能会出错

返回参数

名称 类型 描述
requestId string 请求ID
result object 请求结果

result说明

名称 类型 描述
startTime string 查询起始时间
endTime string 查询终止时间
serviceList List<servicesItem> 服务列表

serviceItem说明

名称 类型 描述
serviceId string 服务ID
serviceName string 服务名
appList List<appItem> app列表

appItem说明

名称 类型 描述
appId string appID
metrics object 监控指标,返回入参指定的指标结果

metrics说明

名称 类型 描述
inputTokensTotal float 输入token数
outputTokensTotal float 输出token数
tokensTotal float 总token数
succeedCallTotal int 调用成功次数
failureCallTotal int 调用失败次数
callTotal int 调用总次数
上一篇
获取定制服务详情
下一篇
获取预置服务列表