# Get started with Billing

See what your organization spends this month, create a budget that e-mails you, check what it watches, and delete it again, in about ten minutes.

Replace _jane.doe@example.com_ with your own e-mail address and _budget-id_ with the id of the
budget you create in step 2. Nothing in this tutorial creates anything billable.

## Prerequisites

- Permission for `billing:GetBillingSummary`, `billing:CreateBudget`, `billing:GetBudgets` and
  `billing:DeleteBudget`.
- In the console, the check of what a budget covers also needs `tags:ListTags`. **Forecast for the
  month** and **This month by service** need `billing:GetCostAndUsage` (without it they show
  "Nothing to forecast yet." and "Nothing billed this month yet."), and the **Invoices** list
  needs `billing:GetInvoices`.
- For the CLI steps, the dcloud CLI, signed in. For the API steps, an access key.

## Step 1: See what you spend this month

**Console**
1. Open **Billing**.

The page shows **Current month**, **Forecast for the month** and **Last month**, then **This month
by service**, **Monthly spend** and **Invoices**.

**CLI**
```sh
dcloud billing summary get
```

**API**
```http
GET /billing/api/summary
```

The amounts are net, before discounts, credits and VAT. The CLI and the API answer in euro cents.

## Step 2: Create a budget

A budget never stops anything by itself: it records an alert, and e-mails it, when spending reaches
a percentage of its amount.

**Console**
1. Open **Budgets**, then choose **Create budget**.
2. For **Name**, enter Tutorial.
3. For **Alert me at (EUR)**, enter 100.
4. Leave **Period** at **Monthly** and **What it covers** at **The whole organization**.
5. Leave **Alert thresholds** at `80,100`, **Forecast thresholds** at `100` and **Notification
   emails** at your own address, which the form fills in.
6. Choose **Create budget**.

The budget appears in the list, with what it has used this month. Unlike the CLI and the API, the
console also gives a monthly budget a forecast threshold of 100 % by default.

**CLI**
```sh
dcloud billing budgets create --name Tutorial --amount-cents 10000 --period monthly \
  --notification-emails jane.doe@example.com
```

**API**
```http
POST /billing/api/budgets
{ "name": "Tutorial", "amountCents": 10000, "period": "monthly", "notificationEmails": ["jane.doe@example.com"] }
```

The answer is `201` with the budget and its `id`. Without `alertThresholds` it alerts at 80 % and
100 %.

## Step 3: See what the budget watches

**Console**
1. Open **Budgets**.

Each budget shows the percentage used, the spend against the amount, the period, what it covers and
the thresholds it alerts at.

**CLI**
```sh
dcloud billing budgets status
```

**API**
```http
GET /billing/api/budgets/status
```

For each budget, `evaluation` holds `spendCents`, `percentUsed`, the thresholds already `crossed`,
and, for a monthly budget, `forecastCents`. `alerts` lists the alerts fired this period.

## Clean up

**Console**
1. Open **Budgets**.
2. Choose the delete button of the budget Tutorial.
3. Choose **Delete**.

**CLI**
```sh
dcloud billing budgets delete budget-id
```

**API**
```http
DELETE /billing/api/budgets/budget-id
```

The budget and the record of its alerts are gone. Your spending is unaffected.

## Next steps

- [Budgets](budgets.md)
- [Explore costs](explore-costs.md)
- [Read and download an invoice](read-an-invoice.md)
