查询 AI 服务用量

查询当前账户的 AI 服务用量及计费结果,支持按服务槽位和计费场景筛选。

GET https://billing.moi.matrixorigin.cn/api/v1/billing/usage

调用前准备

  1. 准备计费账户所属用户的有效个人访问令牌

  2. 调用查询当前账户接口,获取目标账户的 ID。

查询参数

将示例中的 $MOI_PERSONAL_ACCESS_TOKEN$ACCOUNT_ID 分别替换为个人访问令牌和所选账户的 ID。

curl -X GET \
  "https://billing.moi.matrixorigin.cn/api/v1/billing/usage?account_id=$ACCOUNT_ID&page_size=2" \
  -H "X-API-Key: $MOI_PERSONAL_ACCESS_TOKEN"

参数

类型

是否必填

说明

account_id

string

目标账户的 ID,取自“查询当前账户”响应中的 items[].billing_account_id,对应示例中的 $ACCOUNT_ID;省略时使用当前用户可访问的第一个账户。

meter_code

string

仅接受 moi_ai_service_mtoken,省略时使用该值。

service_slot

string

按用量来源的服务槽位筛选。

billing_scenario

string

按用量来源的计费场景筛选。

workspace_id

string

按用量事件所属工作区筛选。

status

string

按计费记录状态筛选;未计费时按用量事件状态筛选。

from

string

按用量事件创建时间筛选的起点,包含该时刻。使用 RFC 3339 时间。

to

string

按用量事件创建时间筛选的终点,不包含该时刻。使用 RFC 3339 时间。

page_size

integer

每页数量,1–100;省略、非正数或大于 100 时使用 50。

page_token

string

下一页标记。首次请求省略;后续使用响应的 next_cursor

成功响应

请求成功时返回 HTTP 200 和符合筛选条件的 AI 服务用量;没有匹配记录时,列表为空。

{
  "items": [],
  "total": 0,
  "as_of": 1788739200
}

字段

类型

说明

items

array of object

本次返回的记录。

items[].rated_record_id

string

计费用量记录 ID,计费后返回。

items[].usage_event_id

string

用量事件 ID。

items[].billing_account_id

string

Billing 账户 ID。

items[].parent_name

string

服务分类名称。

items[].service_slot

string

用量来源的服务槽位。

items[].billing_scenario

string

用量来源的计费场景。

items[].meter_code

string

计量项代码,返回 moi_ai_service_mtoken

items[].quantity

string

用量,以十进制字符串返回。

items[].unit

string

计量单位。

items[].unit_price_credit

string

Credit 单价,完成计费后可能返回。

items[].credit

string

折扣后费用,单位为 Credit,完成计费后可能返回。

items[].status

string

记录状态,优先返回计费记录状态。

items[].occurred_at

string

用量发生时间。

items[].request_id

string

来源请求 ID,可能省略。

items[].request_count

integer

来源请求数,可能省略。

items[].created_at

integer

创建时间,Unix 秒。

total

integer

符合筛选条件的总记录数。

next_cursor

string

下一页标记;省略或为空时停止翻页。

as_of

integer

查询结果生成时间,Unix 秒。

字段路径中的 [] 表示数组中的每一项。例如,items[].rated_record_id 表示数组中每一项的对应字段。

继续查询时,将响应中的 next_cursor 保存为 $NEXT_PAGE_TOKEN,保持筛选条件不变。标记省略或为空时停止翻页。

curl -X GET \
  "https://billing.moi.matrixorigin.cn/api/v1/billing/usage?account_id=$ACCOUNT_ID&page_size=2&page_token=$NEXT_PAGE_TOKEN" \
  -H "X-API-Key: $MOI_PERSONAL_ACCESS_TOKEN"

错误响应

缺少认证信息时返回 HTTP 401,请提供有效的个人访问令牌。

{
  "code": "unauthenticated",
  "message": "missing bearer token",
  "error": "missing bearer token"
}

字段

类型

说明

code

string

错误代码。

message

string

错误说明。

error

string

兼容错误说明,与 message 内容相同。

最后更新于