---
name: azion-query-data-stream-usage-data
description: >-
  Read the usage that Data Stream accounts on your account, per workload and metric, with a GraphQL query to the Azion consumption API.
---

# Query Data Stream usage data

You can query the usage that [Data Stream](/en/documentation/platform/data-stream/) accounts on your account with the Azion GraphQL API. To check the sends of a stream and the status code of each one instead, refer to [How Data Stream works](/en/documentation/platform/data-stream/how-it-works/#delivery-records-and-metrics).

The `workloadConsumptionMetrics` dataset aggregates the usage accounted for each Azion product, Data Stream included, and keeps it for up to 24 months. The consumption endpoint serves it at `https://api.azion.com/v4/consumption/graphql`. To compare the totals with what your plan includes, refer to [Data Stream limits](/en/documentation/platform/data-stream/limits/#included-usage-per-plan).

---

## Prerequisites

- A stream that sent logs during the period you query. To create one, refer to the [Data Stream quickstart](/en/documentation/platform/data-stream/quickstart/).
- A personal token. To create one, refer to [How to manage a personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- `curl`.

---

## Query the usage of Data Stream

The query filters the dataset on the product ID of Data Stream, `1498670028`, and on its two metrics, `data_streamed` and `requests`. It sums the accounted usage for each workload and metric:

```graphql
query {
  workloadConsumptionMetrics(
    filter: {
      tsRange: { begin: "2026-09-01T00:00:00", end: "2026-10-03T00:00:00" }
      productId: 1498670028
      metricNameIn: ["data_streamed", "requests"]
    }
    aggregate: { sum: accounted }
    limit: 10000
    groupBy: [clientId, workloadId, productId, metricName]
  ) {
    clientId
    workloadId
    productId
    metricName
    total: sum
  }
}
```

The query uses these arguments:

- `tsRange` sets the period, with `begin` and `end` in the `YYYY-MM-DDTHH:mm:ss` format.
- `productId` keeps the usage of Data Stream only.
- `metricNameIn` takes a list of metrics. To read one metric, use `metricName` with one string, such as `metricName: "data_streamed"`.
- `sum: accounted` adds up the usage accounted for the events that match the filter, for each group.
- `limit` caps the number of rows. The maximum is `10000`.
- `groupBy` returns one row for each combination of client, workload, product, and metric.

To send the query, make a `POST` request to the consumption endpoint. Replace `[TOKEN VALUE]` with your personal token, and the dates with your own:

```bash
curl -X POST 'https://api.azion.com/v4/consumption/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Token [TOKEN VALUE]' \
  -d '{"query":"query { workloadConsumptionMetrics( filter: { tsRange: { begin: \"2026-09-01T00:00:00\", end: \"2026-10-03T00:00:00\" } productId: 1498670028 metricNameIn: [\"data_streamed\", \"requests\"] } aggregate: { sum: accounted } limit: 10000 groupBy: [clientId, workloadId, productId, metricName] ) { clientId workloadId productId metricName total: sum } }"}'
```

On an account with no Data Stream usage accounted in the period, the API answers `200` with an empty list:

```json
{
  "data": {
    "workloadConsumptionMetrics": []
  }
}
```

An empty list means that no usage of Data Stream matches the filter in that period. When usage exists, each row carries these fields:

- `clientId`: the identifier of your account on Azion.
- `workloadId`: the workload the usage belongs to.
- `productId`: `1498670028`, the product ID of Data Stream.
- `metricName`: `data_streamed` or `requests`.
- `total`: for `data_streamed`, the data that Data Stream sent for the workload, in bytes. For `requests`, the number of requests processed.

To see how much data your streams sent for each workload, read the `total` of the `data_streamed` rows. A list in `metricName` fails with `400` and `Expected type "String"`. Use `metricNameIn` for a list.

You can also paste the query into the [GraphiQL Playground](/en/documentation/devtools/graphql/graphql-playground/) at `https://api.azion.com/v4/consumption/graphql`, signed in to your Azion account. For every field of the dataset, refer to [Consumption GraphQL fields](/en/documentation/devtools/graphql/gql-consumption-fields/).

---

## Check an empty result

An empty list can also come from a wrong period or a filter that matches nothing. To confirm that the dataset returns usage for your account, query it without the product and metric filters. This query groups one day of usage by product and metric:

```bash
curl -X POST 'https://api.azion.com/v4/consumption/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Token [TOKEN VALUE]' \
  -d '{"query":"query { workloadConsumptionMetrics( filter: { tsRange: { begin: \"2026-10-02T00:00:00\", end: \"2026-10-03T00:00:00\" } } aggregate: { sum: accounted } limit: 50 groupBy: [productId, metricName] ) { productId metricName total: sum } }"}'
```

The API answers `200` with one row for each product and metric that has accounted usage:

```json
{
  "data": {
    "workloadConsumptionMetrics": [
      {
        "productId": 1441740010,
        "metricName": "requests",
        "total": 514.0
      },
      {
        "productId": 1441740010,
        "metricName": "data_transferred_total",
        "total": 17057621.0
      }
    ]
  }
}
```

Rows for other products, with none that carries `1498670028`, mean that the token and the dataset work and that the account has no Data Stream usage accounted that day. If this query also returns an empty list, the account has no usage accounted in that period.

---

## Next steps

- [Data Stream limits](/en/documentation/platform/data-stream/limits.md#included-usage-per-plan): Compare the totals with the Requests and Data Transfer each plan includes.
- [How Data Stream works](/en/documentation/platform/data-stream/how-it-works.md): See how a stream batches and sends log lines, and where each send is recorded.
- [Consumption GraphQL fields](/en/documentation/devtools/graphql/gql-consumption-fields.md): Look up every field, filter, and product of the workloadConsumptionMetrics dataset.
