# Spend

> What BareCI charges for, the monthly cap, budgets per run, pull request and repository, alerts and webhooks, and reading spend from the CLI, MCP or API.

Source: https://bareci.com/docs/modules/spend

Every organisation has a hard monthly cap. BareCI checks it before it starts work and while work runs, so a bill never goes past it. Spend is read from the same records that the cap checks and Stripe bills.

## What costs money

| Meter        | Price                                                             |
| ------------ | ----------------------------------------------------------------- |
| Machine time | Per vCPU-minute: $0.0006 on spot, $0.0012 on demand               |
| Previews     | $0.01 an hour, on top of the machine time the preview keeps       |
| Flows tokens | The model's list price plus 20 %, when BareCI's model key is used |

The free plan includes $5 a month, needs no card, and work stops once the $5 is used. On the paid plan the first $5 a month is free too. The cap is $100 by default, and you can set it up to $10 000 with `PUT /v1/accounts/:a/cap`.

## Reading spend

```sh
bareci spend                    # this checkout's organisation, this month
bareci spend --org acme --month 2026-11 --json
```

The MCP tool `spend` and `GET /v1/accounts/:a/spend?month=YYYY-MM` return the same report:

| Field                       | What it holds                                                                   |
| --------------------------- | ------------------------------------------------------------------------------- |
| `usedUsd`, `capUsd`, `plan` | Spend this month against the cap                                                |
| `billableUsd`               | The part above the free allowance, which Stripe bills (paid plan only)          |
| `inFlightUsd`               | Flows calls still running, counted at their worst case until they answer        |
| `meters`                    | Each meter: quantity, unit, dollars and the billable part                       |
| `machines`                  | Machine time by size (vCPUs) and market (spot or on demand)                     |
| `flows`                     | Flows tokens and dollars by model                                               |
| `repos`                     | The ten repositories that spent most                                            |
| `savings`                   | What churn savings left unrun: dollars, minutes and jobs, by kind               |
| `machineLimit`              | How many machines the organisation may run at once                              |
| `graceEndsAt`               | Only when a payment failed: when the free plan's limits start unless it is paid |

For a past month, the dollars, meters, machines, Flows, repositories and savings are that month's, while `plan`, `capUsd`, `inFlightUsd`, `machineLimit` and `graceEndsAt` are always today's values. The report can be up to a minute old.

`GET /v1/accounts/:a/usage` lists the usage records themselves.

## Budgets

Budgets limit one run, one pull request (counted on its head branch) or one repository for the month, in dollars, vCPU-minutes or both. Budgets you set stop work at 100 %: the run is cancelled, and a **BareCI spend control** check on the commit says why. Where you set none, the defaults apply, and they only alert: $5 or 3 000 vCPU-minutes a run, and $25 or 15 000 vCPU-minutes a pull request.

```sh
curl -X PUT "$BARECI_URL/v1/accounts/acme/budgets" -H "authorization: Bearer $BARECI_TOKEN" \
  -d '{"run": {"usd": 5, "vcpuMinutes": 3000}, "repos": {"acme/web": {"repo": {"usd": 200, "vcpuMinutes": null}}}}'
```

`GET /v1/accounts/:a/budgets` returns the budgets in force. Setting a budget needs the `operate` scope.

## Alerts and webhooks

BareCI raises an alert at 50, 80 and 100 % of the cap and of each budget, once per threshold per month. The dashboard shows it, and `GET /v1/accounts/:a/alerts` lists it. Each URL set with `PUT /v1/accounts/:a/alerts/settings` (at most 5, HTTPS, on a public host) also gets a POST:

```json
{
  "type": "spend.threshold",
  "id": "2026-12:cap:acme:usd:80",
  "account": "acme",
  "month": "2026-12",
  "kind": "cap",
  "scope": "acme",
  "metric": "usd",
  "threshold": 80,
  "used": 81.2,
  "limit": 100,
  "at": 1764900000000
}
```

The request carries `x-bareci-event: spend.threshold` and `x-bareci-signature: sha256=<hex>`, an HMAC-SHA256 of the body. The signing secret is returned once: when the first webhook is set, and again when you send `{"rotateSecret": true}`. A delivery that fails is retried five times with backoff, and then shows as failed.

## Machines at once, and payments

An organisation may run 4 machines at once on the free plan. On the paid plan it may run 16, 64 after one paid invoice, and 256 after three. A refund, a dispute, or a failed or voided invoice drops it back to 16. When a payment fails, the paid plan's limits hold for 7 days; after that, the free plan's limits apply until the invoice is paid. To change or fix the card, use the billing portal (`POST /v1/accounts/:a/billing/portal`). A second checkout is refused while a subscription is live.

## Runaway protection

A job that failed in 3 earlier attempts of its workflow run within 30 minutes is not run again. Reruns after spot interruptions are capped at 2 per run. Flows on BareCI's key are limited by calls in flight (2 free, 8 paid) and by 2 million tokens a month. See [Flows](https://bareci.com/docs/modules/flows) and [Runners](https://bareci.com/docs/modules/runners).
