# List monthly bill usage line items

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

Group rated usage by posting period and return bill usage line items.

```text
GET https://billing.moi.matrixorigin.cn/api/v1/billing/accounts/$ACCOUNT_ID/monthly-bills/$PERIOD/line-items
```

## 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.
3. Call [List rated usage records](../usage/records.md#billing-period-selection) to obtain a posting period with usage for that account.

## Request example

Replace `$MOI_PERSONAL_ACCESS_TOKEN`, `$ACCOUNT_ID`, and `$PERIOD` with your personal access token, account ID, and posting period.

```bash
curl -X GET \
  "https://billing.moi.matrixorigin.cn/api/v1/billing/accounts/$ACCOUNT_ID/monthly-bills/$PERIOD/line-items?dimension=meter&page_size=2" \
  -H "X-API-Key: $MOI_PERSONAL_ACCESS_TOKEN"
```

## Path parameters

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

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `accountID` | string | Yes | Target account ID from `items[].billing_account_id` in the List current accounts response. |
| `period` | string | Yes | Posting period for the target account from `items[].posting_period` in the List rated usage records response, in `YYYY-MM` format. |

::::

## Query parameters

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

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `dimension` | string | No | Aggregation dimension: meter, workspace, service, or day; defaults to meter. Daily grouping uses UTC dates. |
| `meter_code` | string | No | Filter by meter code. |
| `billing_item_code` | string | No | Filter by billing item code; when combined with `meter_code`, both must match the same meter. |
| `workspace_id` | string | No | Filter by the workspace of the usage event. |
| `status` | string | No | Filter by usage record status; use charged for charged records. Omitted means no status filter. |
| `subject_type` | string | No | Filter by account owner type. |
| `subject_id` | string | No | Filter by account owner ID. |
| `q` | string | No | Case-insensitive search over rated record ID, usage event ID, meter code, or event key. |
| `search` | string | No | Alias for q, used only when q is empty. |
| `page_size` | integer | No | Page size, 1–100; omitted, nonpositive, or greater than 100 uses 50. |
| `page_token` | string | No | Next-page token. Omit for the first request; then use `next_page_token` from the response. |

::::

## Successful response

Returns HTTP `200` with aggregated usage line items.

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

```json
{
  "items": [
    {
      "line_item_id": "billline:2026-09:meter:meter_example",
      "period": "2026-09",
      "line_type": "usage",
      "dimension": "meter",
      "group_key": "meter_example",
      "group_label": "Example usage",
      "meter_code": "meter_example",
      "billing_item_code": "meter_example",
      "billing_item_display_name": "Example usage",
      "unit": "token",
      "quantity": "1000",
      "gross_credit": "1.000000000000",
      "discount_credit": "0.100000000000",
      "net_credit": "0.900000000000",
      "credit_amount": "0.900000000000",
      "source_record_ids": [
        "rated_record_example"
      ],
      "source_record_count": 1
    }
  ],
  "total": 1,
  "next_page_token": ""
}
```

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

| Field | Type | Description |
| --- | --- | --- |
| `items` | array of object | Aggregated usage line items. |
| `items[].line_item_id` | string | Bill usage line item ID. |
| `items[].period` | string | Posting period in `YYYY-MM` format. |
| `items[].line_type` | string | Line type, usage. |
| `items[].dimension` | string | Applied aggregation dimension. |
| `items[].group_key` | string | Group identifier. |
| `items[].group_label` | string | Group display label. |
| `items[].meter_code` | string | Meter code. |
| `items[].billing_item_code` | string | Billing item code. |
| `items[].billing_item_display_name` | string | Billing item display name. |
| `items[].unit` | string | Line item unit; grouping across meters uses the unit of the first record in the group. |
| `items[].workspace_id` | string | Workspace ID for workspace grouping; may be omitted. |
| `items[].service_code` | string | Service code for service grouping; may be omitted. |
| `items[].bucket_start` | string | UTC day start for daily grouping; may be omitted. |
| `items[].bucket_end` | string | Exclusive UTC day end for daily grouping; may be omitted. |
| `items[].quantity` | string | Sum of usage quantities in the group. |
| `items[].gross_credit` | string | Gross charge in Credit. |
| `items[].discount_credit` | string | Discount in Credit. |
| `items[].net_credit` | string | Net charge in Credit. |
| `items[].credit_amount` | string | Line charge, equal to `net_credit`, in Credit. |
| `items[].source_record_ids` | array of string | Rated usage record IDs included in the aggregate. |
| `items[].source_record_count` | integer | Number of records included in the aggregate. |
| `total` | integer | Total matching aggregated line items. |
| `next_page_token` | string | Next-page token; empty means the last page. |

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

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

Set `$NEXT_PAGE_TOKEN` to `next_page_token` from the previous response and retain the same filters. Stop when the token is empty.

```bash
curl -X GET \
  "https://billing.moi.matrixorigin.cn/api/v1/billing/accounts/$ACCOUNT_ID/monthly-bills/$PERIOD/line-items?dimension=meter&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. |

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