> ## Documentation Index
> Fetch the complete documentation index at: https://ona.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# List Environment Usage Records

> Lists completed environment runtime records within a specified date range.

`Unary` · [`Usage`](/docs/api-reference/generated/usage/overview)

Lists completed environment runtime records within a specified date range.

Returns a list of environment runtime records that were completed within the specified date range. Records of currently running environments are not included.

Use this method to:

* View environment runtime records
* Filter by project
* Create custom usage reports

### Example

```yaml theme={null}
filter:
  projectId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
  dateRange:
    startTime: "2024-01-01T00:00:00Z"
    endTime: "2024-01-02T00:00:00Z"
pagination:
  pageSize: 100
```

## Endpoint

```text theme={null}
POST /api/gitpod.v1.UsageService/ListEnvironmentUsageRecords
```

Send a Bearer token as described in [Authentication](/docs/api-reference#authenticate-requests). If your organization uses a custom management-plane domain, replace `https://app.ona.com` with that domain.

## Request example

<CodeGroup>
  ```bash cURL theme={null}
  export ONA_HOST=https://app.ona.com
  export ONA_API_KEY=<your-token>

  curl --request POST \
    --url "$ONA_HOST/api/gitpod.v1.UsageService/ListEnvironmentUsageRecords" \
    --header "Authorization: Bearer $ONA_API_KEY" \
    --header "Content-Type: application/json" \
    --data '{
    "pagination": {
      "pageSize": 1
    }
  }'
  ```

  ```python Python theme={null}
  import gitpod.v1.pagination_pb2 as pagination_pb2
  import gitpod.v1.usage_pb2 as usage_pb2
  from ona_sdk import create_client_from_env

  ona = create_client_from_env()
  request = usage_pb2.ListEnvironmentUsageRecordsRequest(
      pagination=pagination_pb2.PaginationRequest(
          page_size=1,
      ),
  )
  response = ona.services.usage.list_environment_usage_records(request)
  print(response)
  ```

  ```typescript TypeScript theme={null}
  import { create } from "@bufbuild/protobuf";
  import { createClientFromEnv } from "@gitpod/sdk";
  import { ListEnvironmentUsageRecordsRequestSchema } from "@gitpod/sdk/gitpod/v1/usage_pb";

  async function main() {
    const ona = createClientFromEnv();
    const request = create(ListEnvironmentUsageRecordsRequestSchema, {
      pagination: {
        pageSize: 1,
      },
    });
    const response = await ona.services.usage.listEnvironmentUsageRecords(request);
    console.log(response);
  }

  main().catch(console.error);
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	"connectrpc.com/connect"
  	"github.com/gitpod-io/gitpod-sdk-go/sdk"
  	gitpodpb "github.com/gitpod-io/gitpod-sdk-go/v1"
  )

  func main() {
  	ona, err := sdk.NewFromEnv()
  	if err != nil {
  		log.Fatal(err)
  	}

  	request := connect.NewRequest(&gitpodpb.ListEnvironmentUsageRecordsRequest{
  		Pagination: &gitpodpb.PaginationRequest{
  			PageSize: 1,
  		},
  	})
  	response, err := ona.Services.Usage.ListEnvironmentUsageRecords(context.Background(), request)
  	if err != nil {
  		log.Fatal(err)
  	}
  	fmt.Println(response.Msg)
  }
  ```

  ```json Request body theme={null}
  {
    "pagination": {
      "pageSize": 1
    }
  }
  ```
</CodeGroup>

## Request

`gitpod.v1.ListEnvironmentUsageRecordsRequest`

| Field        | Type                                                                    | Required | Description         |
| ------------ | ----------------------------------------------------------------------- | -------- | ------------------- |
| `pagination` | [PaginationRequest](#type-gitpod-v1-pagination-request)                 | No       | Pagination options. |
| `filter`     | [Filter](#type-gitpod-v1-list-environment-usage-records-request-filter) | No       | Filter options.     |

## Response

`gitpod.v1.ListEnvironmentUsageRecordsResponse`

| Field        | Type                                                                        | Required | Description                          |
| ------------ | --------------------------------------------------------------------------- | -------- | ------------------------------------ |
| `pagination` | [PaginationResponse](#type-gitpod-v1-pagination-response)                   | No       | Pagination response.                 |
| `records`    | array of [EnvironmentUsageRecord](#type-gitpod-v1-environment-usage-record) | No       | List of environment runtime records. |

## Related types

<a id="type-gitpod-v1-date-range" />

<Accordion title="DateRange">
  DateRange specifies a time period for queries.

  `gitpod.v1.DateRange`

  | Field       | Type               | Required | Description                                                             |
  | ----------- | ------------------ | -------- | ----------------------------------------------------------------------- |
  | `startTime` | RFC 3339 timestamp | Yes      | Start time of the date range (inclusive). Constraints: `required=true`. |
  | `endTime`   | RFC 3339 timestamp | Yes      | End time of the date range (exclusive). Constraints: `required=true`.   |
</Accordion>

<a id="type-gitpod-v1-environment-usage-record" />

<Accordion title="EnvironmentUsageRecord">
  EnvironmentUsageRecord represents a record of an environment from start to stop.

  `gitpod.v1.EnvironmentUsageRecord`

  | Field                | Type               | Required | Description                                                                           |
  | -------------------- | ------------------ | -------- | ------------------------------------------------------------------------------------- |
  | `id`                 | string             | No       | Environment usage record ID.                                                          |
  | `environmentId`      | string             | No       | Environment ID associated with the record.                                            |
  | `userId`             | string             | No       | User ID is the ID of the user who created the environment associated with the record. |
  | `projectId`          | string             | No       | Project ID associated with the environment (if available).                            |
  | `runnerId`           | string             | No       | Runner ID associated with the environment.                                            |
  | `environmentClassId` | string             | No       | Environment class ID associated with the record.                                      |
  | `createdAt`          | RFC 3339 timestamp | No       | Time when the environment was created.                                                |
  | `stoppedAt`          | RFC 3339 timestamp | No       | Time when the environment was stopped.                                                |
</Accordion>

<a id="type-gitpod-v1-list-environment-usage-records-request-filter" />

<Accordion title="Filter">
  `gitpod.v1.ListEnvironmentUsageRecordsRequest.Filter`

  | Field       | Type                                    | Required | Description                                                               |
  | ----------- | --------------------------------------- | -------- | ------------------------------------------------------------------------- |
  | `projectId` | string                                  | No       | Optional project ID to filter runtime records by.                         |
  | `dateRange` | [DateRange](#type-gitpod-v1-date-range) | Yes      | Date range to query runtime records within. Constraints: `required=true`. |
</Accordion>

<a id="type-gitpod-v1-pagination-request" />

<Accordion title="PaginationRequest">
  `gitpod.v1.PaginationRequest`

  | Field      | Type    | Required | Description                                                                                                                              |
  | ---------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
  | `pageSize` | integer | No       | Page size is the maximum number of results to retrieve per page. Defaults to 25. Maximum 100. Constraints: `int32.gte=0, int32.lte=100`. |
  | `token`    | string  | No       | Token for the next set of results that was returned as next\_token of a PaginationResponse                                               |
</Accordion>

<a id="type-gitpod-v1-pagination-response" />

<Accordion title="PaginationResponse">
  `gitpod.v1.PaginationResponse`

  | Field       | Type   | Required | Description                                                                             |
  | ----------- | ------ | -------- | --------------------------------------------------------------------------------------- |
  | `nextToken` | string | No       | Token passed for retrieving the next set of results. Empty if there are no more results |
</Accordion>
