# List AI service usage

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

List AI service usage and rating results for the current account, with service-slot and billing-scenario filters.

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

## Before you begin

1. Prepare a valid [personal access token](../../../../../guides/billing/credentials.md#personal-access-token) for the account owner.
2. Call [List current accounts](../accounts/current.md) to obtain the target account’s ID.

## Query parameters

Replace `$MOI_PERSONAL_ACCESS_TOKEN` and `$ACCOUNT_ID` in the example with your personal access token and the selected account’s ID.

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
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"
```

:::::
:::::{tab-item} Parameters

::::{div} mo-api-parameter-table

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `account_id` | string | No | Target account ID from `items[].billing_account_id` in the List current accounts response, represented by `$ACCOUNT_ID`; defaults to the first account accessible to the current user. |
| `meter_code` | string | No | Only `moi_ai_service_mtoken` is accepted; also the default. |
| `service_slot` | string | No | Filter by the service slot recorded in usage. |
| `billing_scenario` | string | No | Filter by the billing scenario recorded in usage. |
| `workspace_id` | string | No | Filter by usage-event workspace. |
| `status` | string | No | Filter by rated record status, falling back to usage event status before rating. |
| `from` | string | No | Inclusive start by usage event creation time, in RFC 3339 format. |
| `to` | string | No | Exclusive end by usage event creation time, in RFC 3339 format. |
| `page_size` | integer | No | Page size, 1–100; omitted, nonpositive, or greater than 100 uses 50. |
| `page_token` | string | No | Next-page token. Omit initially; then use `next_cursor` from the response. |

::::

:::::
::::::
:::::::

## Successful response

Returns HTTP `200` with AI service usage matching the filters; the list is empty when no records match.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

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

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `items` | array of object | Records returned by this request. |
| `items[].rated_record_id` | string | Rated usage record ID, returned after rating. |
| `items[].usage_event_id` | string | Usage event ID. |
| `items[].billing_account_id` | string | Billing account ID. |
| `items[].parent_name` | string | Service category name. |
| `items[].service_slot` | string | Service slot recorded by the usage source. |
| `items[].billing_scenario` | string | Billing scenario recorded by the usage source. |
| `items[].meter_code` | string | Meter code, `moi_ai_service_mtoken`. |
| `items[].quantity` | string | Usage quantity as a decimal string. |
| `items[].unit` | string | Usage unit. |
| `items[].unit_price_credit` | string | Unit price in Credit, when rating is available. |
| `items[].credit` | string | Net charge in Credit, when rating is available. |
| `items[].status` | string | Record status, preferring the rated record status. |
| `items[].occurred_at` | string | Time when the usage occurred. |
| `items[].request_id` | string | Source request ID; may be omitted. |
| `items[].request_count` | integer | Source request count; may be omitted. |
| `items[].created_at` | integer | Creation time in Unix seconds. |
| `total` | integer | Total records matching the filters. |
| `next_cursor` | string | Next-page token; stop when omitted or empty. |
| `as_of` | integer | Time the query result was generated, in Unix seconds. |

In field paths, `[]` denotes each array item. For example, `items[].rated_record_id` refers to the corresponding field in each item.

:::::
::::::
:::::::

For the next page, set `$NEXT_PAGE_TOKEN` to `next_cursor` from the preceding response and retain the same filters. Stop when the token is omitted or empty.

```bash
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"
```

## Error response

Missing authentication returns HTTP `401`; provide a valid personal access token.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

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

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | Error code. |
| `message` | string | Error message. |
| `error` | string | Compatibility error message, with the same content as message. |

:::::
::::::
:::::::
