# Explore costs

Draw your cost over time, grouped and filtered by any dimension, find the days that cost unusually much, and follow any bar down to the metered usage lines.

The cost explorer reads the usage records the invoice is made from. It writes nothing; its query
endpoints are `POST` only because a question is a nested structure. Amounts in the API are EUR
strings with eight decimal places.

## Prerequisites

- Permission for `billing:GetCostAndUsage`. Without it, **Cost explorer** shows an access-denied
  notice.
- `billing:GetBudgets` for the **Budgets** panel; without it the explorer works, and the panel says
  "No budgets yet" whatever budgets exist.
- `iam:UpdateOrganization` to group or filter by **Runs on** (where a resource runs). Without it the
  dimension is not offered, and an API query that uses it is refused with `403`.

## Ask a question

A question is a window of days (UTC, both ends included, at most 400 days), a granularity (hourly
for windows of at most 14 days, daily, or monthly), a dimension to group by, and up to 20 filters.

| Dimension     | API id            | Groups by                                        |
| ------------- | ----------------- | ------------------------------------------------ |
| Service       | `service`         | The service that metered the usage               |
| Usage type    | `usageType`       | The priced item (SKU)                            |
| Resource      | `resource`        | Each resource                                    |
| Resource type | `resourceType`    | Instance, volume, database, …                    |
| Region, Zone  | `region`, `zone`  | Where it ran                                     |
| Project       | `resourceProject` | The project a resource lives in                  |
| Saved view    | `project`         | The saved views (saved tag queries) it matches   |
| Tag           | `tag` + `tagKey`  | The values of one tag key                        |
| Created by    | `creator`         | The IAM user who created the resource            |
| Runs on       | `provider`        | Where the resource runs (admins only, see above) |

**Console**
1. Open **Cost explorer**.
2. Choose a range (**7 days**, **30 days**, **90 days**, **This month**, **Last month**), or set
   **From** and **To**.
3. For **Granularity**, choose **Hourly**, **Daily** or **Monthly**.
4. For **Group by**, choose a dimension, or `Tag: ` followed by a tag key.
5. (Optional) To filter, choose a dimension, **is** or **is not**, and a value, then choose **Add
   filter**. Repeat for more filters; all of them apply.

The page address holds the whole question, so you can share the view as a link.

**CLI**
```sh
dcloud billing costs query --start 2026-10-01 --end 2026-10-31 \
  --group-by '{"dimension":"tag","tagKey":"team"}'
```

**API**
```http
POST /billing/api/cost-explorer/query
{ "start": "2026-10-01", "end": "2026-10-31", "granularity": "day", "groupBy": { "dimension": "tag", "tagKey": "team" } }
```

A filter keeps (or, with `exclude`, drops) the rows whose dimension has one of the given values.
The value `""` selects rows that have none: untagged, no project, unknown creator. A filter value
that matches nothing selects nothing and is named in `notices`.

## Read the answer

- **Total** for the window, compared with the previous period: the same number of whole calendar
  months before when the window is whole months, otherwise the same number of days just before.
- **Forecast** for the month, when the window reaches into the current month: month to date, plus
  what is billing now at its current rate for the hours left, plus usage-based charges at the
  average of the last complete days.
- **Discounts and credits**: gross, discounts, credits and net for the window.
- **Unusual days**: days whose total is above the median of the 14 days before by more than 40 %
  and by more than €1, with the resources that explain the jump. Days with fewer than 7 days of
  history are not judged.
- **Top movers vs previous period**, by resource or by group.
- The groups table: the eight largest groups (`maxGroups`, 1–50, over the API) and **Other**, with
  their cost, share and change.
- **Resources**: the billed resources, the 300 most expensive at most, with a warning when it looks forgotten (**Idle**,
  **Detached**, **Untagged**, **No owner**, **Stopped, still billed**, **Deleted, still billed**)
  and its run rate a month.

## See the usage lines behind a cost

**Console**
1. Choose a bar of the chart, a group's **Usage lines**, an unusual day, or a resource.

A panel lists the usage lines, largest first: resource, usage type, quantity and unit, unit price,
amount, number of records, and the first and last metered hour, with the monthly cap where one
applies.

**CLI**
```sh
dcloud billing costs lines --start 2026-10-01 --end 2026-10-31
```

**API**
```http
POST /billing/api/cost-explorer/lines
{ "start": "2026-10-01", "end": "2026-10-31", "bucket": "2026-10-14T00:00:00.000Z", "granularity": "day" }
```

One line is one resource, usage type and unit price. `bucket` (the start of a bar) with its
`granularity` narrows the lines to one bar. At most `limit` lines (default 200, at most 2,000) are
returned; `total` covers every matching line and `truncated` says when more exist.

## Credits and discounts

Credits and discounts are granted by Deutsche Cloud. A discount is a percentage off usage in its
validity window, optionally for some services only, and is applied before credits; a credit is an
EUR amount that each month's net consumes, oldest first. To list them with what is left:

```sh
dcloud billing costs credits
```

## Related

- [Compare costs with other clouds](compare-with-other-clouds.md)
- [Export costs](export-costs.md)
- [Save and mail a cost view](save-a-cost-view.md)
- `billing.costs.query` · `billing.costs.lines` · `dcloud billing costs query`
