Skip to main content

Query Usage Trend

Paginate the usage trend for a workspace or agent by hour, UTC+8 calendar day, or calendar month.

POST
/api/v1/agentstudio/usage/trend
cURL
curl --request POST \
  --url 'https://{workspace_id}.{region}.maas.aliyuncs.com/api/v1/agentstudio/usage/trend' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "dimension": "workspace",
  "time_range": {
    "start_time": "2026-11-02T10:15:30+08:00",
    "end_time": "2026-11-02T14:00:01+08:00"
  },
  "granularity": "hour",
  "page_size": 1
}
'
{
  "request_id": "req_trend_example",
  "data": {
    "query_range": {
      "start_time": "2026-11-02T10:00:00+08:00",
      "end_time": "2026-11-02T15:00:00+08:00"
    },
    "data_updated_at": "2026-11-02T11:05:00+08:00",
    "granularity": "hour",
    "points": [
      {
        "start_time": "2026-11-02T10:00:00+08:00",
        "end_time": "2026-11-02T11:00:00+08:00",
        "usage": {
          "total": {
            "input_tokens": {
              "value": 600,
              "unit": "tokens"
            },
            "output_tokens": {
              "value": 120,
              "unit": "tokens"
            },
            "total_tokens": {
              "value": 720,
              "unit": "tokens"
            },
            "cache_read_tokens": {
              "value": 240,
              "unit": "tokens"
            },
            "cache_creation_tokens": {
              "value": 60,
              "unit": "tokens"
            },
            "cache_hit_ratio": {
              "value": 0.4,
              "unit": "ratio"
            },
            "model_call_count": {
              "value": 3,
              "unit": "count"
            },
            "tool_call_count": {
              "value": 2,
              "unit": "count"
            },
            "builtin_tool_call_count": {
              "value": 0,
              "unit": "count"
            },
            "mcp_tool_call_count": {
              "value": 2,
              "unit": "count"
            },
            "custom_tool_call_count": {
              "value": 0,
              "unit": "count"
            },
            "turns": {
              "value": 1,
              "unit": "count"
            },
            "steps": {
              "value": 5,
              "unit": "count"
            },
            "interrupt_error_count": {
              "value": 0,
              "unit": "count"
            },
            "model_failed_count": {
              "value": 1,
              "unit": "count"
            },
            "tool_failed_count": {
              "value": 1,
              "unit": "count"
            },
            "runtime_ms": {
              "value": 36000,
              "unit": "ms"
            }
          },
          "models": [
            {
              "model_name": "qwen-plus",
              "usage": {
                "input_tokens": {
                  "value": 600,
                  "unit": "tokens"
                },
                "output_tokens": {
                  "value": 120,
                  "unit": "tokens"
                },
                "total_tokens": {
                  "value": 720,
                  "unit": "tokens"
                },
                "cache_read_tokens": {
                  "value": 240,
                  "unit": "tokens"
                },
                "cache_creation_tokens": {
                  "value": 60,
                  "unit": "tokens"
                },
                "cache_hit_ratio": {
                  "value": 0.4,
                  "unit": "ratio"
                },
                "call_count": {
                  "value": 3,
                  "unit": "count"
                },
                "failed_count": {
                  "value": 1,
                  "unit": "count"
                }
              }
            }
          ],
          "tools": [
            {
              "source": "mcp",
              "tool_name": "web_search",
              "usage": {
                "call_count": {
                  "value": 2,
                  "unit": "count"
                },
                "failed_count": {
                  "value": 1,
                  "unit": "count"
                }
              }
            }
          ]
        }
      }
    ],
    "has_more": true,
    "next_page_token": "v1_0123456789abcdef0123456789abcdef"
  }
}

Query dimensions

dimension supports only lowercase workspace and agent; session is not supported. For workspace, do not pass agent filter parameters; passing them returns HTTP 400 / invalid_parameter. For agent, agent_id must be a non-empty single value. For time formats, granularity selection, and range alignment rules, see Query usage summary.

Pagination

Pass the next_page_token returned by the previous page unchanged as page_token. Keep the same Alibaba Cloud account, workspace, dimension, agent, version, original start and end times, actual granularity, and page_size. Start and end times are compared as the same absolute instant, so equivalent time zone notations can be interchanged; even if the aligned query_range is the same, the original time boundaries cannot be changed.
  • Each token is valid for 15 minutes from creation and can be retried within that period; retrying the same token does not extend its validity. An expired token returns HTTP 410 / page_token_expired; remove page_token and query the first page again.
  • Pagination is by complete period, and page_size limits only the number of periods. Model and tool details within a period are returned together; the combined model and tool detail items across all periods on the page are limited to 100,000, and the summary total does not count toward this limit.
  • Only periods with summary records are returned; missing periods are not filled automatically. A period is still returned when its recorded metrics are 0 or null.
  • If the first query has no records, points=[], has_more=false, and next_page_token=null are returned, while the actual query_range and granularity are still included.
  • Statistics may continue to update during pagination, and a token does not lock a data snapshot. The next page starts after the last period of the previous page; data added later to periods that have already been paged through is not returned again on subsequent pages. To refresh, query from the first page again; results may still be briefly cached.
data.query_range is the actual aligned range for the entire query and is the same on every page; it is not the start and end of the current page. data_updated_at is the latest known update time among the usage records returned on the current page and may differ between pages. For the usage object structure and empty result rules, see Query usage summary; for error codes, see Query Usage Summary.

Authorizations

string
header
required

DashScope API Key

Body

application/json
enum<string>
required

取值仅为小写 workspace、agent,区分大小写。不支持 session

workspace,agent
object
required

查询时间范围。时间范围按 UTC+8 对齐

string

dimension=agent 时必填,指定一个 Agent;workspace 维度不传。必须为非空单值

string | null

仅 dimension=agent 可用。不传或为 null 时合并全部版本;不能是空字符串或纯空白,按原始字符串精确匹配,不自动去除首尾空格

enum<string>

hour、day 或 month;不传时自动选择,不接受显式 null

hour,day,month
integer
default100

每页最多返回的时间段数量,取值 1~100,默认 100;不接受显式 null

1 <= x <= 100
string

首次查询不传。续页原样传入上一页的 next_page_token,不解析或自行拼接;不接受显式 null、空字符串、纯空白或无效游标。游标自生成起有效期为 15 分钟,失效后返回 HTTP 410 / page_token_expired

Response

200-application/json
string

请求标识

object