# Google Cloud cost by a hierarchy of labels

> Returns Google Cloud spend grouped by up to three label keys at once, for example cluster, namespace and workload. A resource label wins over the same key set on its project.

Source: https://docs.levelfour.ai/api-reference/costs/get-costs-by-labels


## GET /api/v1/costs/by-labels

Returns Google Cloud spend grouped by up to three label keys at once, for example cluster, namespace and workload. A resource label wins over the same key set on its project.

### Authentication

Send `Authorization: Bearer <token>`.

### Parameters

- `provider` (query, `gcp`, default `gcp`)
- `key` (query, array of string, required): Label keys, in order
- `filter` (query, array of string, nullable): key=value pairs to narrow to
- `start` (query, string, nullable)
- `end` (query, string, nullable)
- `credits` (query, one of `before`, `after`, default `after`): Cost basis for Google Cloud: after credits (default) or before them. AWS stays on its invoiced basis.
- `include_project_labels` (query, boolean, default `true`)
- `limit` (query, integer, default `50`)

### Responses

#### 200: Successful Response

- `success` (boolean, default `true`)
- `timestamp` (date-time string)
- `data` (object, required)
  - `keys` (array of string, required): The label keys, in the order they were requested
  - `credits` (one of `before`, `after`, required): Cost basis applied
  - `total` (number, required): Total spend in the window
  - `unlabeled` (number, required): Spend carrying none of the keys
  - `items` (array of object, required): Combinations ranked by spend
    - `values` (map of string to string, nullable, required): The value of each requested key, null when unset
    - `cost` (number, required): Spend for this combination
    - `share_pct` (number, required): Share of total spend

#### Errors

- `400`: Bad Request
- `401`: Authentication Error
- `403`: Authorization Error
- `404`: Not Found
- `409`: Conflict
- `422`: Validation Error
- `429`: Rate Limit Exceeded
- `500`: Internal Server Error

Body of `400`, `401`, `403`, `404`, `409`, `422`, `429`, `500`:

- `success` (`false`, required)
- `error` (object, required)
  - `code` (string, required)
  - `message` (string, required)
  - `details` (any)
- `timestamp` (date-time string, required)
