# Usage

## Get Usage Record

`client.usage.get(stringresourceID, RequestOptionsoptions?): Usage`

**get** `/v1/usage/{resource_id}`

Get the usage record for a single resource (metadata plus dimension history) for the current organization.

### Parameters

- `resourceID: string`

### Returns

- `Usage`

  Usage record for a single metered resource.

  - `dimensions: Array<UsageDimension>`

    - `id: string`

    - `dimension: string`

    - `ended_at: string | null`

    - `quantity: number`

    - `started_at: string`

    - `children?: Array<UsageDimensionLeaf>`

      - `id: string`

      - `dimension: string`

      - `ended_at: string | null`

      - `quantity: number`

      - `started_at: string`

  - `ended_at: string | null`

  - `project_id: string`

  - `region: RegionName`

    Region the resource is in.

    - `"us-sva-2"`

  - `resource_id: string`

  - `resource_type: UsageResourceType`

    Kind of metered resource a ledger row belongs to.

    - `"vm"`

    - `"volume"`

    - `"vpc"`

    - `"connect_connection"`

    - `"nks_cluster"`

    - `"nks_node_pool"`

    - `"nks_load_balancer"`

  - `started_at: string`

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

const usage = await client.usage.get('123e4567-e89b-12d3-a456-426614174000');

console.log(usage.project_id);
```

#### Response

```json
{
  "dimensions": [
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "dimension": "compute_n1_standard_8",
      "ended_at": "2026-02-01T00:00:00Z",
      "quantity": 1,
      "started_at": "2026-01-01T00:00:00Z",
      "children": [
        {
          "id": "123e4567-e89b-12d3-a456-426614174000",
          "dimension": "compute_vcpu",
          "ended_at": "2026-02-01T00:00:00Z",
          "quantity": 2,
          "started_at": "2026-01-01T00:00:00Z"
        }
      ]
    }
  ],
  "ended_at": "2026-02-01T00:00:00Z",
  "project_id": "123e4567-e89b-12d3-a456-426614174000",
  "region": "us-sva-2",
  "resource_id": "123e4567-e89b-12d3-a456-426614174000",
  "resource_type": "vm",
  "started_at": "2026-01-01T00:00:00Z"
}
```

## List Usage Records

`client.usage.list(UsageListParamsquery?, RequestOptionsoptions?): Cursor<Usage>`

**get** `/v1/usage`

List per-resource usage records for the current organization. Each item is one resource with its nested dimension history (active and closed segments).

### Parameters

- `query: UsageListParams`

  - `cursor?: string`

    Pagination cursor returned by a previous request

  - `limit?: number`

    Maximum number of items to return

### Returns

- `Usage`

  Usage record for a single metered resource.

  - `dimensions: Array<UsageDimension>`

    - `id: string`

    - `dimension: string`

    - `ended_at: string | null`

    - `quantity: number`

    - `started_at: string`

    - `children?: Array<UsageDimensionLeaf>`

      - `id: string`

      - `dimension: string`

      - `ended_at: string | null`

      - `quantity: number`

      - `started_at: string`

  - `ended_at: string | null`

  - `project_id: string`

  - `region: RegionName`

    Region the resource is in.

    - `"us-sva-2"`

  - `resource_id: string`

  - `resource_type: UsageResourceType`

    Kind of metered resource a ledger row belongs to.

    - `"vm"`

    - `"volume"`

    - `"vpc"`

    - `"connect_connection"`

    - `"nks_cluster"`

    - `"nks_node_pool"`

    - `"nks_load_balancer"`

  - `started_at: string`

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const usage of client.usage.list()) {
  console.log(usage.project_id);
}
```

#### Response

```json
{
  "items": [
    {
      "dimensions": [
        {
          "id": "123e4567-e89b-12d3-a456-426614174000",
          "dimension": "compute_n1_standard_8",
          "ended_at": "2026-02-01T00:00:00Z",
          "quantity": 1,
          "started_at": "2026-01-01T00:00:00Z",
          "children": [
            {
              "id": "123e4567-e89b-12d3-a456-426614174000",
              "dimension": "compute_vcpu",
              "ended_at": "2026-02-01T00:00:00Z",
              "quantity": 2,
              "started_at": "2026-01-01T00:00:00Z"
            }
          ]
        }
      ],
      "ended_at": "2026-02-01T00:00:00Z",
      "project_id": "123e4567-e89b-12d3-a456-426614174000",
      "region": "us-sva-2",
      "resource_id": "123e4567-e89b-12d3-a456-426614174000",
      "resource_type": "vm",
      "started_at": "2026-01-01T00:00:00Z"
    }
  ],
  "pagination": {
    "next_cursor": "RhwniMT4B74siYZcPF8TnCdGI1l9rpPvg",
    "previous_cursor": "ARhwnmi1hA7wEbHbMjdYQlOB_ZusP4fYvw",
    "total_count": 125
  }
}
```

## Domain Types

### Usage

- `Usage`

  Usage record for a single metered resource.

  - `dimensions: Array<UsageDimension>`

    - `id: string`

    - `dimension: string`

    - `ended_at: string | null`

    - `quantity: number`

    - `started_at: string`

    - `children?: Array<UsageDimensionLeaf>`

      - `id: string`

      - `dimension: string`

      - `ended_at: string | null`

      - `quantity: number`

      - `started_at: string`

  - `ended_at: string | null`

  - `project_id: string`

  - `region: RegionName`

    Region the resource is in.

    - `"us-sva-2"`

  - `resource_id: string`

  - `resource_type: UsageResourceType`

    Kind of metered resource a ledger row belongs to.

    - `"vm"`

    - `"volume"`

    - `"vpc"`

    - `"connect_connection"`

    - `"nks_cluster"`

    - `"nks_node_pool"`

    - `"nks_load_balancer"`

  - `started_at: string`

### Usage Dimension

- `UsageDimension`

  Top-level dimension entry; bundle heads expand via children.

  - `id: string`

  - `dimension: string`

  - `ended_at: string | null`

  - `quantity: number`

  - `started_at: string`

  - `children?: Array<UsageDimensionLeaf>`

    - `id: string`

    - `dimension: string`

    - `ended_at: string | null`

    - `quantity: number`

    - `started_at: string`

### Usage Dimension Leaf

- `UsageDimensionLeaf`

  One ledger segment for a (resource, dimension) pair.

  - `id: string`

  - `dimension: string`

  - `ended_at: string | null`

  - `quantity: number`

  - `started_at: string`

### Usage List

- `UsageList`

  - `items: Array<Usage>`

    - `dimensions: Array<UsageDimension>`

      - `id: string`

      - `dimension: string`

      - `ended_at: string | null`

      - `quantity: number`

      - `started_at: string`

      - `children?: Array<UsageDimensionLeaf>`

        - `id: string`

        - `dimension: string`

        - `ended_at: string | null`

        - `quantity: number`

        - `started_at: string`

    - `ended_at: string | null`

    - `project_id: string`

    - `region: RegionName`

      Region the resource is in.

      - `"us-sva-2"`

    - `resource_id: string`

    - `resource_type: UsageResourceType`

      Kind of metered resource a ledger row belongs to.

      - `"vm"`

      - `"volume"`

      - `"vpc"`

      - `"connect_connection"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"nks_load_balancer"`

    - `started_at: string`

  - `pagination: Pagination`

    Pagination response details.

    - `next_cursor: string | null`

    - `previous_cursor: string | null`

    - `total_count: number`

### Usage Resource Type

- `UsageResourceType = "vm" | "volume" | "vpc" | 4 more`

  Kind of metered resource a ledger row belongs to.

  - `"vm"`

  - `"volume"`

  - `"vpc"`

  - `"connect_connection"`

  - `"nks_cluster"`

  - `"nks_node_pool"`

  - `"nks_load_balancer"`
