本文介绍GetIqsUsage的接口参数以及使用方法。
接口说明
提供客户T+1 信息查询服务接口日维度使用量查询,上午10点之后可以查询前一天数据。
接口定义
请求参数
参数 | 类型 | 必填 | 默认值 | 描述 | 示例值 |
startDate | string | 是 | - | 用量开始时间(包含在内),最近60天内。 | 20250612 |
endDate | string | 是 | - | 用量结束时间(包括在内),最近60天内。 | 20250612 |
返回参数
字段 | 类型 | 是否可空 | 字段说明 | 示例值 | |
requestId | string | 不可空 | 请求RequestId,排查问题时可以提供此信息。 | 35E5608A-A737-2038-****-D9D34C6BFD9E | |
records | date | string | 不可空 | 计量时间。 | 20250612 |
mainAccountId | string | 不可空 | 主账号ID。 | 128608930******0 | |
subAccountId | string | 不可空 | 调用子账号(RAM子账号或者 | 2193843763***9272 | |
api | string | 不可空 | API名称。 | UnifiedSearch | |
engineType | string | 不可空 | 引擎类型,枚举值:
| Generic | |
billingQps | int32 | 可空 | 阶梯计费QPS。 | 30 | |
ladderType | string | 可空 | 匹配到的计量阶梯。取值:
| 1001 | |
valueAddedSummary | int32 | 不可空 | 开启摘要使用的增值包的用量。 | 293480次 | |
valueAddedAdvanced | int32 | 不可空 | 调用增加接口使用增值包的用量。 | 23324次 | |
totalCalls | int32 | 不可空 | 总调用量。 | 293482次 | |
successCalls | int32 | 不可空 | 成功调用量。 | 293480次 | |
failedCalls | int32 | 不可空 | 失败调用量。 | 2次 |
示例
请求参数
https://*/iqs/usage?endDate=20250723&startDate=20250701
返回参数
{ "requestId": "929a2db4-aa7e-4b62-8291-f08fb17f6a75", "records": [ { "date": "20250716", "mainAccountId": "138608930******0", "subAccountId": "138608930******0", "api": "UnifiedSearch", "engineType": "Generic", "billingQps": 30, "ladderType": "1001", "totalCalls": 5, "successCalls": 5, "failedCalls": 0, "valueAddedSummary": 5, "valueAddedAdvanced": 0 }, { "date": "20250716", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "GenericAdvanced", "billingQps": 30, "ladderType": "1001", "totalCalls": 5, "successCalls": 5, "failedCalls": 0, "valueAddedSummary": 5, "valueAddedAdvanced": 5 }, { "date": "20250718", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "Generic", "billingQps": 30, "ladderType": "1001", "totalCalls": 4, "successCalls": 4, "failedCalls": 0, "valueAddedSummary": 2, "valueAddedAdvanced": 0 }, { "date": "20250718", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "GenericAdvanced", "billingQps": 30, "ladderType": "1001", "totalCalls": 4, "successCalls": 4, "failedCalls": 0, "valueAddedSummary": 2, "valueAddedAdvanced": 4 }, { "date": "20250721", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "GenericAdvanced", "billingQps": 30, "ladderType": "1001", "totalCalls": 5, "successCalls": 5, "failedCalls": 0, "valueAddedSummary": 5, "valueAddedAdvanced": 5 }, { "date": "20250722", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "Generic", "billingQps": 30, "ladderType": "1001", "totalCalls": 9, "successCalls": 9, "failedCalls": 0, "valueAddedSummary": 9, "valueAddedAdvanced": 0 }, { "date": "20250722", "mainAccountId": "138608930*******0", "subAccountId": "138608930*******0", "api": "UnifiedSearch", "engineType": "GenericAdvanced", "billingQps": 30, "ladderType": "1001", "totalCalls": 3, "successCalls": 3, "failedCalls": 0, "valueAddedSummary": 3, "valueAddedAdvanced": 3 } ] }
接口调用
SDK调用
使用阿里云AK/SK认证方式,并使用阿里云SDK发起接口调用。
Python SDK
前提条件
您需要确保已安装Python3.8或以上版本。
安装SDK
pip install alibabacloud_iqs20241111==1.4.0
调用代码
同步调用
import os from Tea.exceptions import TeaException from alibabacloud_iqs20241111 import models from alibabacloud_iqs20241111.client import Client from alibabacloud_tea_openapi import models as open_api_models class Sample: def __init__(self): pass @staticmethod def create_client() -> Client: config = open_api_models.Config( #使用您的AK/SK进行替换(建议通过环境变量加载) access_key_id='$YOUR_ACCESS_KEY', access_key_secret='$YOUR_ACCESS_SECRET' ) config.endpoint = f'iqs.cn-zhangjiakou.aliyuncs.com' return Client(config) @staticmethod def main() -> None: client = Sample.create_client() get_iqs_usage_request = models.GetIqsUsageRequest( start_date='20250701', end_date='20250723' ) try: response = client.get_iqs_usage(get_iqs_usage_request) print(f"api success, size :{len(response.body.records)}") if len(response.body.records) > 0: print(f"records:{response.body.records[0]}") for index, item in enumerate(response.body.records): print(f"{index}. {'-' * 20}") print(f"api:{item.api}") print(f"date:{item.date}") print(f"engineType:{item.engine_type}") print(f"mainAccountId:{item.main_account_id}") print(f"subAccountId:{item.sub_account_id}") print(f"totalCalls:{item.total_calls}") print(f"successCalls:{item.success_calls}") print(f"valueAddedSummary:{item.value_added_summary}") print(f"valueAddedAdvanced:{item.value_added_advanced}") except TeaException as e: code = e.code request_id = e.data.get("requestId") message = e.data.get("message") print(f"api exception, requestId:{request_id}, code:{code}, message:{message}") if __name__ == '__main__': Sample.main()
异步调用
import asyncio import os import time from Tea.exceptions import TeaException from alibabacloud_iqs20241111 import models from alibabacloud_iqs20241111.client import Client from alibabacloud_tea_openapi import models as open_api_models class Sample: def __init__(self): pass @staticmethod def create_client() -> Client: config = open_api_models.Config( # 使用您的AK/SK进行替换(建议通过环境变量加载) access_key_id=os.environ.get('ACCESS_KEY'), access_key_secret=os.environ.get('ACCESS_SECRET') ) config.endpoint = f'iqs.cn-zhangjiakou.aliyuncs.com' return Client(config) @staticmethod async def main_async() -> None: start = time.time() client = Sample.create_client() get_iqs_usage_request = models.GetIqsUsageRequest( start_date='20250701', end_date='20250723' ) try: # 使用异步方法 response = await client.get_iqs_usage_async(get_iqs_usage_request) print(f"api success, size :{len(response.body.records)}") if len(response.body.records) > 0: print(f"records:{response.body.records[0]}") for index, item in enumerate(response.body.records): print(f"{index}. {'-' * 20}") print(f"api:{item.api}") print(f"date:{item.date}") print(f"engineType:{item.engine_type}") print(f"mainAccountId:{item.main_account_id}") print(f"subAccountId:{item.sub_account_id}") print(f"totalCalls:{item.total_calls}") print(f"successCalls:{item.success_calls}") print(f"valueAddedSummary:{item.value_added_summary}") print(f"valueAddedAdvanced:{item.value_added_advanced}") except TeaException as e: code = e.code request_id = e.data.get("requestId") message = e.data.get("message") print(f"api exception, requestId:{request_id}, code:{code}, message:{message}") if __name__ == '__main__': asyncio.run(Sample.main_async())
Java SDK
前提条件
已安装Java8或以上版本。
Maven依赖
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>iqs20241111</artifactId>
<version>1.4.0</version>
</dependency>
调用代码
package com.aliyun.iqs;
import com.aliyun.iqs20241111.Client;
import com.aliyun.iqs20241111.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* @author zj-407802
* @date 2025/7/25 10:03
* @desc
**/
public class GetIqsUsageExample {
public static void main(String[] args) throws Exception {
Client client = initClient();
invoke(client, "20250701", "20250723");
}
private static Client initClient() throws Exception {
//使用您的AK/SK进行替换(建议通过环境变量加载)
String accessKeyId = "$YOUR_ACCESS_KEY";
String accessKeySecret = "$YOUR_ACCESS_SECRET";
Config config = new Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
config.setEndpoint("iqs.cn-zhangjiakou.aliyuncs.com");
return new Client(config);
}
private static void invoke(Client client, String startDate, String endDate) {
GetIqsUsageRequest request = new GetIqsUsageRequest();
request.setStartDate(startDate);
request.setEndDate(endDate);
try {
GetIqsUsageResponse response = client.getIqsUsage(request);
GetIqsUsageResult body = response.getBody();
printOutput(body);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void printOutput(GetIqsUsageResult output) {
// 使用 GsonBuilder 创建带格式化的 Gson 实例
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.disableHtmlEscaping()
.create();
// 输出格式化的 JSON
String prettyJson = gson.toJson(output);
System.out.println(prettyJson);
}
}
Go SDK
前提条件
Go 环境版本必须不低于 1.10.x。
安装SDK
require (
github.com/alibabacloud-go/iqs-20241111 v1.4.0
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.10
)
调用代码
package main
import (
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
iqs20241111 "github.com/alibabacloud-go/iqs-20241111/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"log"
)
const endpointURL = "iqs.cn-zhangjiakou.aliyuncs.com"
func createClient() (*iqs20241111.Client, error) {
//使用您的AK/SK进行替换
accessKeyID := "YOUR_ACCESS_KEY"
accessKeySecret := "YOUR_ACCESS_SECRET"
if accessKeyID == "" || accessKeySecret == "" {
return nil, fmt.Errorf("ACCESS_KEY or ACCESS_SECRET environment variable is not set")
}
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyID),
AccessKeySecret: tea.String(accessKeySecret),
Endpoint: tea.String(endpointURL),
}
return iqs20241111.NewClient(config)
}
func runGetIqsUsage(client *iqs20241111.Client) error {
request := &iqs20241111.GetIqsUsageRequest{
StartDate: tea.String("20250610"),
EndDate: tea.String("20250723"),
}
runtime := &util.RuntimeOptions{}
resp, err := client.GetIqsUsageWithOptions(request, nil, runtime)
if err != nil {
return fmt.Errorf("GetIqsUsage failed: %w", err)
}
fmt.Printf("response: %s\n", resp.Body)
return nil
}
func main() {
client, err := createClient()
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
if err := runGetIqsUsage(client); err != nil {
log.Fatalf("Error running GetIqsUsage: %v", err)
}
}
}