按会话 ID 查询指定会话的用量明细。每条明细附带用量发生时成员的直属部门。
statistics:read
POST{域名}/openapi/v1/statistics/session_usage_detailmodel_source 字段为准。| Header 参数 | 是否必填 | 描述 |
|---|---|---|
Authorization |
是 | 固定取值为 Bearer {access_token}。关于如何获取访问令牌,参考鉴权。 |
Content-Type |
是 | 固定取值为 application/json。 |
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
|
|
string[] |
是 |
- |
待查询用量明细的会话 ID。 如需获取会话 ID,可登录 TRAE 企业版控制台,并前往 用量管理 > 用量明细 来查看。 |
该接口独有的响应参数如下,参数位于 data 数组中。通用响应参数参考此文档。
| 参数 | 类型 | 描述 |
|---|---|---|
items |
array | 会话维度的结果列表。 |
items[].start_time |
int64 | 用量记录的开始时间,Unix 秒时间戳。 |
items[].user_id |
string | 发起该会话的成员的 ID。 |
items[].email |
string | 发起该会话的成员的邮箱。 |
|
|
int |
成员的账号类型,取值:
|
|
|
string |
产生用量的客户端,取值:
|
items[].model_name |
string | 产生用量的模型的展示名,取值随模型配置变化。 |
|
|
string |
产生用量的模型功能类型,取值:
|
|
|
string |
模型来源,取值:
|
items[].session_id |
string | 产生用量的会话的 ID。无会话信息时返回空字符串。 |
items[].usage |
object | Token 用量明细。 |
items[].usage.prompt_tokens |
int | 输入 Token 消耗数量。 |
items[].usage.completion_tokens |
int | 输出 Token 消耗数量。 |
items[].usage.total_tokens |
int | Token 消耗总数。 |
items[].usage.cache_creation_input_tokens |
int | 缓存创建输入 Token 数。可为 0。 |
items[].usage.cache_read_input_tokens |
int | 缓存读取输入 Token 数。可为 0。 |
|
|
string |
折算后的实际扣费金额。返回十进制金额字符串,固定保留 6 位小数,例如 提示:仅统计 TRAE 内置模型的金额消耗。若为企业自定义模型,返回 “ |
|
|
string |
扣费金额的币种,取值:
|
|
|
string |
Token 或金额的消耗来源,取值:
|
items[].model_call_count |
int | 按会话聚合后的模型调用次数。 |
|
|
string |
产生用量的场景,取值:
|
|
|
array |
用量发生时,成员的直属部门。 当时没有显式部门归属时,则将数据归入企业根部门;无法确定归属时为 |
items[].departments[].department_id |
string | 用量发生时,成员直属部门的真实 ID。 |
|
|
string |
部门的名称。 返回查询时的当前部门名称。部门后续改名时,该值会随查询时间变化。若部门已被删除,则返回空字符串。 |
|
|
string |
部门的完整归属路径。 返回查询时的当前归属路径。部门后续移动时,该值会随查询时间变化。若部门已被删除,则返回空字符串。 |
curl -X POST "${HOST}/openapi/v1/statistics/session_usage_detail" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"session_ids": [
"6a43b324xxxxd71ed71f9e19"
]
}'
{
"code": 0,
"message": "success",
"request_id": "req_xxx",
"data": {
"items": [
{
"start_time": 1780012345,
"user_id": "123456",
"email": "alice@example.com",
"account_type": 1,
"client": "ide",
"model_name": "model-a",
"model_type": "Chat",
"model_source": "Trae",
"session_id": "6a43b324xxxxd71ed71f9e19",
"usage": {
"prompt_tokens": 8000,
"completion_tokens": 2000,
"total_tokens": 10000,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 1000
},
"total_cost": "0.800000",
"total_cost_currency": "CNY",
"consumption_source": "mixed",
"model_call_count": 2,
"scene": "Chat",
"departments": [
{
"department_id": "20001",
"name": "研发一部",
"full_path": "示例企业/研发一部"
}
]
}
]
}
}
若该接口的请求返回错误码,参考错误码文档进行排查。