cURL
Query dimensions
| dimension | Scope | Parameters |
|---|---|---|
workspace | Usage of the current workspace | time_range is required. Do not pass agent_id, agent_version, or session_id |
agent | Usage of a specific agent in the current workspace | agent_id and time_range are required. agent_version is optional. Do not pass session_id |
session | Lifetime cumulative usage of a specific session in the current workspace | Pass only dimension and session_id. Do not pass agent filters, time_range, or granularity |
agent_id and session_id must be non-empty single values. time_range and granularity do not accept explicit null. Passing agent filters with the workspace dimension, or time_range or granularity with the session dimension, returns HTTP 400 / invalid_parameter. For time formats, granularity selection, and range alignment rules, see Time range and granularity.
Session queries return the same usage structure without query_range or session metadata such as title and status. The service verifies session ownership before querying lifetime cumulative usage. If the session exists but has no statistics yet, each metric value is null and the model and tool detail arrays are empty; the session is not reported as nonexistent.
This endpoint returns the total and all model and tool details in one response and does not provide pagination. The combined limit for model and tool detail items per request is 100,000; when exceeded, HTTP 400 / query_limit_exceeded is returned. For the usage object structure and empty result rules, see Usage object.
Time range and granularity
This section applies to workspace and agent summary and trend queries. Session summaries always query lifetime cumulative usage and do not use a time range or granularity.
Time format
Start and end times are second-level RFC 3339 strings with a time zone. Z and numeric offsets are supported. Seconds can be non-zero and do not need to align to a whole minute, for example:
2026-11-02T10:00:30+08:002026-11-02T02:00:30Z, which represents the same instant as the previous example.
2026-11-02T10:00:00.123+08:00. Response times always use +08:00; runtime is still expressed in milliseconds.
Automatic granularity selection
If granularity is omitted, the granularity is selected from the original request range:
| Original range | Granularity |
|---|---|
| No more than 72 hours | hour |
| More than 72 hours, and the end time is no later than the start time plus 3 calendar months in UTC+8 | day |
| All other cases | month |
granularity is specified explicitly, the specified granularity is used. hour, day, and month are supported.
Actual query range
The service aligns the start time backward and the end time forward to complete periods in UTC+8 (Asia/Shanghai). The actual range is returned in query_range.
| Granularity | Alignment boundary |
|---|---|
hour | The top of each hour |
day | 00:00 UTC+8 each day |
month | 00:00 UTC+8 on the first day of each month; calendar month lengths vary |
hour query for 10:15:30—14:00:01 UTC+8 covers 10:00:00—15:00:00. If the end time is already on a boundary, it is not extended; for example, 10:00:00—14:00:00 remains unchanged.
All ranges are left-closed and right-open: the start instant is included and the end instant is excluded. To compare a summary with a trend, use the same query conditions and check query_range. Ratio metrics must be recalculated from the summed numerator and denominator; they cannot be added or averaged directly.
Usage object
data.usage in summary responses and data.points[].usage in trend responses share the same structure:
| Field | Type | Description |
|---|---|---|
total | object | Summary metrics for the current range |
models | array | Model details grouped by model_name |
tools | array | Tool details grouped by source and tool_name; tools with the same name but different sources are returned separately |
Metric values and units
Each metric contains value and unit:
| unit | value type | Meaning |
|---|---|---|
tokens | int64 / null | Number of tokens |
count | int64 / null | Number of calls |
ms | int64 / null | Milliseconds |
ratio | number / null | Decimal ratio, for example 0.4 means 40% |
0. Do not treat null as zero.
Summary metrics (total)
| Field | Unit | Description |
|---|---|---|
input_tokens | tokens | Number of model input tokens |
output_tokens | tokens | Number of model output tokens |
total_tokens | tokens | Sum of input and output tokens; null if either is unknown |
cache_read_tokens | tokens | Number of input tokens read from cache |
cache_creation_tokens | tokens | Number of input tokens used to create cache |
cache_hit_ratio | ratio | cache_read_tokens / input_tokens. null if input is 0, input is unknown, or cache reads are unknown; rounded to 8 decimal places |
model_call_count | count | Number of model calls, counted from recorded model request end events, including successful and failed calls |
tool_call_count | count | Number of tool calls, counted at call start, including successful, failed, and unfinished calls |
builtin_tool_call_count | count | Number of built-in tool calls |
mcp_tool_call_count | count | Number of MCP tool calls |
custom_tool_call_count | count | Number of custom tool calls |
turns | count | Number of interaction turns, counted from events with role=user |
steps | count | Number of execution steps: one step for each model request end and one for each tool call start |
interrupt_error_count | count | Number of error events that are not model or tool call failures; model and tool call failures are counted in their respective failure metrics |
model_failed_count | count | Number of model call failures |
tool_failed_count | count | Number of confirmed tool call failures |
runtime_ms | ms | Total duration of settled runtime segments; unsettled segments are not included |
total_tokens. total, models, and tools are different views of the same range; do not add the total and the details together.
Model details (models)
| Field | Type | Description |
|---|---|---|
models[].model_name | string / null | Model name |
models[].usage | object | Usage metrics for the model |
models[].usage contains the following metrics:
| Field | Unit | Description |
|---|---|---|
input_tokens, output_tokens, total_tokens | tokens | Input, output, and total tokens for the model; calculation rules are the same as the summary |
cache_read_tokens, cache_creation_tokens | tokens | Cache read and cache creation tokens for the model |
cache_hit_ratio | ratio | Cache hit ratio for the model; calculation rules are the same as the summary |
call_count | count | Number of calls to the model |
failed_count | count | Number of failed calls to the model |
Tool details (tools)
| Field | Type | Description |
|---|---|---|
tools[].source | string / null | Tool source: builtin (built-in tool), mcp (MCP tool), custom (custom tool); null if unknown |
tools[].tool_name | string / null | Tool name |
tools[].usage.call_count | object | Number of calls, unit=count |
tools[].usage.failed_count | object | Number of confirmed call failures, unit=count |
points in ascending time order. If a model name, tool name, or source is unknown, the detail is still returned and the corresponding field can be null.
Data updates and empty results
- Statistics are updated continuously as usage is processed, so recent calls may not appear yet. Results may be briefly cached; consecutive requests are not guaranteed to reflect the latest statistics immediately.
data_updated_atis the latest known source update time among the records in this result. It does not mean that all data before that time has been processed, and it is not the request time.- If a summary query has no matching records,
usage.totaland the units of all metrics are still returned, each metricvalueisnull,modelsandtoolsare[], anddata_updated_atisnull. Workspace and agent queries still returnquery_range. - If a trend query has no matching records, an empty
pointsarray is returned. Missing periods are not filled with zeros automatically.
Error codes
| HTTP status | Error code | Description and handling |
|---|---|---|
| 400 | invalid_parameter | Invalid parameters, including unsupported dimensions, granularity, time format, page size, or malformed request body. Correct the request based on error.message |
| 400 | invalid_page_token | The page token is malformed, or the identity, original query conditions, actual granularity, or page_size do not match the token. Use the token returned by the previous page and keep the query conditions unchanged. Trend queries only |
| 400 | query_limit_exceeded | The combined model and tool detail items exceed 100,000: calculated over the entire query range for summaries and over the current page for trends. For summaries, narrow the time range or query a more specific dimension; for trends, reduce page_size or use a finer granularity |
| 404 | not_found | The session does not exist or does not belong to the current account and workspace. Session summary queries only |
| 410 | page_token_expired | The page token has expired. Remove page_token and restart from the first page. Trend queries only |
| 429 | rate_limit | Both usage endpoints share the rate limit for the Alibaba Cloud account and workspace. Reduce concurrency and retry later |
| 503 | service_unavailable | The usage query or pagination service is temporarily unavailable. Retry later |
| 500 | internal_error | Internal service error. Keep request_id for troubleshooting |
Authorizations
string
header
required
DashScope API Key
Body
application/jsonenum<string>
required
查询维度,区分大小写。取值仅为 workspace、agent、session
workspace,agent,session
string
dimension=agent 时必填,指定一个 Agent;其他维度不传
string | null
仅 dimension=agent 可用。指定 Agent 版本;不传或为 null 时合并全部版本。不能是空字符串或纯空白;按原始字符串精确匹配,不自动去除首尾空格
string
dimension=session 时必填。使用创建 Session 时返回的 ID;必须为非空、非纯空白的单个字符串,其他维度不传
object
workspace、agent 维度必填;session 维度不接受。时间范围按 UTC+8 对齐
enum<string>
workspace、agent 维度可用;不传时自动选择。影响实际统计区间的对齐方式。session 维度不传。不接受显式 null
hour,day,month