# Break down your costs

> Break Cost Explorer reports down by service, region, usage type or resource, filter what they count, and add usage quantities.

This guide reports a month's costs per service and per day, narrows a report to one service or
region, and adds how much of each resource type you used.

## Before you begin

Sign in with the [CLI](/developer/cli), get a
[token](/identity/get-a-token) for the API, or create the
[Python client](/cost-explorer/guides/use-the-python-client).

## 1. Choose the period and granularity

A report covers a period from `start` up to, but not including, `end`, and splits it into
`hourly`, `daily` or `monthly` rows. A period can be up to 366 days long. Prefer `daily` or
`monthly` for long periods, because hourly rows make large reports.

## 2. Group by what you want to compare

`group_by` splits each row into groups. Group by any of `service`, `region`, `usage_type`,
`project_id` and `resource_id`. Grouping by `resource_id` shows what each server, volume and
image cost.

This request reports September's costs per service, per day:

<CodeBlockTabs defaultValue="CLI">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="API">
      API
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Python">
      Python
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="CLI">
    ```sh
    openstack cost report create \
      --start 2026-09-01 \
      --end 2026-10-01 \
      --granularity daily \
      --group-by service \
      --metric cost \
      --detail
    ```
  </CodeBlockTab>

  <CodeBlockTab value="API">
    ```sh
    curl --request POST https://cost-explorer.public.global.vexxhost.net/v1/cost_reports \
      --header "X-Auth-Token: $TOKEN" \
      --header "Content-Type: application/json" \
      --data '{
        "time_period": {"start": "2026-09-01T00:00:00Z", "end": "2026-10-01T00:00:00Z"},
        "granularity": "daily",
        "metrics": ["cost"],
        "group_by": ["service"]
      }'
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Python">
    ```python
    report = costs.cost_reports.create(
        time_period={"start": "2026-09-01T00:00:00Z", "end": "2026-10-01T00:00:00Z"},
        granularity="daily",
        metrics=["cost"],
        group_by=["service"],
    )
    ```
  </CodeBlockTab>
</CodeBlockTabs>

`--detail` adds the per-group rows to the CLI's table. The API returns one entry per day, each
with a total and a group per service:

```json
{
  "as_of": "2026-10-07T15:12:40Z",
  "currency": "USD",
  "pricing_version": "legacy-usd-21c6b51",
  "group_definitions": ["service"],
  "regions": [{"name": "ca-ymq-1", "data_through": "2026-10-07T14:00:00Z"}],
  "results_by_time": [
    {
      "time_period": {"start": "2026-09-01T00:00:00Z", "end": "2026-09-02T00:00:00Z"},
      "estimated": true,
      "total": {"cost": {"amount": "35.912000000000", "unit": "USD"}},
      "groups": [
        {"keys": ["compute"], "metrics": {"cost": {"amount": "31.104000000000", "unit": "USD"}}},
        {"keys": ["volume"], "metrics": {"cost": {"amount": "4.808000000000", "unit": "USD"}}}
      ]
    }
  ]
}
```

The `keys` of each group follow the order of `group_definitions`. The response continues with an
entry for every day of September.

## 3. Filter what counts

Filters narrow a report to some of your spending. A filter with several values matches any of
them, and different filters must all match.

| Filter                                            | CLI                          | API                                            |
| ------------------------------------------------- | ---------------------------- | ---------------------------------------------- |
| Service: `compute`, `volume`, `image` or `object` | `--service compute`          | `"filter": {"services": ["compute"]}`          |
| Region                                            | `--region ca-ymq-1`          | `"filter": {"regions": ["ca-ymq-1"]}`          |
| Usage type, such as a flavor                      | `--usage-type v3-standard-2` | `"filter": {"usage_types": ["v3-standard-2"]}` |

On the CLI, repeat an option to give several values. In the API, leave a filter out to count
everything. An empty list matches nothing.

## 4. Add usage quantities

To see how much you used as well as what it cost, add the `usage_quantity` metric. Hours and
GiB-hours cannot be added together, so this metric needs grouping by `usage_type`:

<CodeBlockTabs defaultValue="CLI">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="API">
      API
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="CLI">
    ```sh
    openstack cost report create \
      --start 2026-09-01 \
      --end 2026-10-01 \
      --granularity monthly \
      --group-by usage_type \
      --metric cost \
      --metric usage_quantity \
      --detail
    ```
  </CodeBlockTab>

  <CodeBlockTab value="API">
    ```json
    {
      "time_period": {"start": "2026-09-01T00:00:00Z", "end": "2026-10-01T00:00:00Z"},
      "granularity": "monthly",
      "metrics": ["cost", "usage_quantity"],
      "group_by": ["usage_type"]
    }
    ```
  </CodeBlockTab>
</CodeBlockTabs>

Each group then has a `usage_quantity` in `Hours` or `GiB-Hours`, and each row has
`usage_by_unit` totals.

## Verify

Add up the daily totals of a month and compare them with a monthly report for the same month. They
are equal, because Cost Explorer counts each minute in exactly one row. If the most recent rows look
low, check `data_through`: usage after that time is not counted yet.

## Next steps

* [Forecast your spending](/cost-explorer/guides/forecast-spending) for the rest of the month.
* Get alerted before you overspend with [Budgets](/budgets).
* Look up every field in the [API reference](/cost-explorer/api).
