---
title: "Budgets"
description: "Budgets limit spend in each window, in a meter's units or in dollars across several meters."
---

# Budgets

A budget is a limit on spend in each window. A reservation must fit every budget that counts it,
or it is denied and nothing is charged.

## Units or dollars

A budget counts one of two ways:

- **In units**: one [meter](/tidegate/docs/meters)'s spend, in that meter's own units, such as tokens or
  calls. A price never moves its limit. A rate limit is a budget in units on a meter that counts
  calls.
- **In dollars**: one or more meters' spend, each reservation at its meters'
  [prices](/tidegate/docs/prices) when it was made. One budget in dollars can cap everything a vendor
  charges, input and output tokens of every model together, so a call that switches among its
  models stays under the same cap. Its meters are fixed when it is defined, though: a meter
  added later, for a new model, isn't counted until the budget is defined again with it (see
  Changing a budget, below).

Units of different meters don't add up, so a budget over several meters is always in dollars.
Its limit is in micro-dollars in the API, and in dollars on the pages.

A budget in dollars counts only spend its meters have a price for: defining one over a meter with
no price now is refused, and spend from before a meter's first price isn't counted. A reservation it counts adds what each line cost,
rounded up to the micro-dollar, so the budget never counts less than was spent. A settlement
moves it by what the settled quantities cost instead, at the same prices. When a price changes
for a time in the budget's current window, the budget counts that spend at the new price, which can
take it past its limit, as a settlement above the estimate can.

## Windows

A budget's windows repeat back to back from an **anchor**, the start of one of them. A window is
either a fixed duration, such as a day, or a number of calendar months, counted in UTC.

The New budget form's **Resets** field names three windows, each resetting at 00:00 UTC:
**Monthly**, on the 1st of each month; **Weekly**, on Mondays; and **Daily**, every day.
**Custom** sets how long each window lasts, in hours, days, weeks, months, or years, a year being
12 calendar months, and when one starts: a date and time, in UTC or in your browser's time zone,
which the budget keeps as the same moment. Beneath it, the form shows that moment in the other
zone. A local time your clocks skip, as they go forward, is refused; one they repeat, as they go
back, is the first. A budget with an anchor counts the matching spend already in its current
window, so a monthly budget defined on the 4th counts what was reserved since the 1st. Before you
define it, the form says how much that is, and how much of the limit is left: with a split, the
most any one value has spent. Where that's the whole limit already, it says so, since the budget
would refuse what it counts from the moment it's defined until its window resets.

Without an anchor, a budget's first window starts at its first reservation, and the rest follow
from there: the page reads such a budget as, say, "Every month from its first reservation". Leave
Custom's start empty for that, or leave out the anchor in the API.

Month windows clamp to the end of the month: anchored on January 31, windows start February 28
(or 29), then March 31. Windows also repeat backward from the anchor, so it can lie in the future.

## Narrowing to an app

A budget is for one [app](/tidegate/docs/apps), or for the whole organization. An app's budget counts only
the reservations that app's keys make; an organization's budget counts every reservation.

## Narrowing to an environment

A budget is for one [environment](/tidegate/docs/environments), such as `staging`, or for every environment.
An environment's budget counts only the reservations that keys in that environment make. A
budget can be for an app and an environment at once.

## Narrowing with labels

Reservations carry labels, such as `member=user_42` or `job=summary`. A budget can count only
the reservations that carry given labels: a budget with `job=summary` caps summaries and nothing
else. The New budget form takes them as `key=value` pairs separated by commas; write a comma in a
value as `\,`, and a backslash before a comma as `\\`. Duplicating a budget whose label values
have spaces around them, or a line break, keeps those labels exactly, though the form can't edit
them.

## Splitting by a label

A budget can be **split** by label keys, keeping spend apart for each of their values. Split by
`member`, one budget caps every member separately, each at the full limit. A reservation that
doesn't carry a split label isn't counted by that budget at all, so make sure your services send
it.

## Budgets within budgets

The Budgets page groups budgets by vendor, then by the meters they count, and draws each group's
budgets as a tree: a budget sits under the narrowest one that counts everything it counts, in
windows of the same length, and in the same unit. Budgets over several of a vendor's meters come
first in the vendor's section; budgets over several vendors' meters come first on the page. For example, a meter's total, then
one app's part of it, then that app's bulk jobs, then each user's bulk jobs. A narrower budget is
defined like any other, with the same meters, unit, and window length; the page draws it under
the broader one.

When narrower budgets, each for one app, each for one environment, or each on one value of a
label, together allow more
than the budget above them, the page says so: they compete for its limit, or, when there is only
one, it never refuses anything, since the broader budget fills first.

## Watching spend

The Budgets page shows each budget's spend in its current window against its limit: in dollars
for a budget in dollars, and for one in units, in dollars too where the meter has a price. The
counts at the top of the page say how many budgets are over their limit, near it (at 80% or
more), and under it; each one filters the list to those budgets. A frozen budget refuses
everything it counts, whatever its spend, so it isn't in those counts: while any budget is
frozen, a Frozen count comes first, and filters the list to the frozen budgets. Unfreeze the last
of them from that list and the count stays, at none, until you choose it again or **Show all**.
Each vendor's budgets sit on one card, folded when the page opens, unless there is only one
vendor: its line says how many budgets it has, how many are frozen, over their limit, or near
it, and what the organization has spent with that vendor this month, on all of its meters, with a
link to that spend on the Spend page. Under **Across vendors**, the spend is on the meters its
budgets count. Pick a vendor to open its budgets, and again to fold them. A link to a budget or
to a meter's budgets opens its vendor, and while a count filters the list, every vendor is open.
Pick a budget for its panel, with everything else about it. The open budget and the filter are in
the page's address, so a link to it opens the same view, and Back closes the panel.

A budget can also mail people as its spend nears its limit: every budget whose windows are a day
or longer starts with an alert at 100% spent and one for being on pace to reach 100% before its
window resets. A budget with shorter windows has no alerts and can't be given any. [Budget
alerts](/tidegate/docs/alerts) says who gets them and how to change them.

## Setting the limit

The New budget form takes a limit in dollars, and how often the budget resets, which is its
window. Check the meters it counts, from any vendors; search finds a meter by its id, its vendor,
or the vendor's name for it, and each vendor's box checks all of its meters the search shows that
have a price now. A meter needs a price for a budget in dollars to count it. A budget in one
meter's units, which the API takes, is defined through the API or by an agent. The form can also
share a limit evenly among a number of a split's values. The budget keeps only each value's
share: Tidegate learns your users only as they spend, so it can't divide a limit among them
itself.

## Changing a budget

Only the limit can change; it applies from the next reservation. A budget's meters, unit, app,
environment, labels, split, and window are fixed: to change one, pick **Duplicate as new** from
the budget's menu or its panel. It opens New budget's form with every field filled from the
budget, its windows too, and a new id; change what you need, define it, then archive the old one,
which the duplicate leaves as it is. The form counts dollars, so a budget in a meter's units comes
over with its limit left for you to fill in, and a meter with no price now comes over unchecked.
To add a new model's meters to a budget in dollars, duplicate it, check them too, and archive the
old one: the duplicate's windows start where the old one's do, so it counts the spend already in
this window. A limit shared among a split's values comes over as
each value's share, which is what the budget keeps. A budget defined with an anchor counts the
spend already in its current window; one without starts counting at its next reservation. Either way, it counts every
reservation made while it was being defined, by the time the definition answers. A reservation
made at the very moment a price changes is repriced about ten seconds after. The limit, a freeze, or
an archive applies to the reservations that start after the change; one already under way, for a
millisecond or so, is judged by what was in effect when it started.

## Freezing and archiving

Freeze a budget to stop the spend it counts at once: every reservation it counts is refused,
whatever its spend, until you unfreeze it. Its denials say so, with `"frozen": true`.

Archive a budget to retire it: it stops counting and limiting spend, and the Budgets page lists it
apart, under its archived budgets. Its record stays, and its id stays its own. Restore it to put
it back in effect; it counts from its next reservation, so what was reserved while it was
archived stays uncounted. That holds for a budget archived just after it was defined, too: if it
hadn't yet finished counting the spend already in its window, restoring it doesn't finish it. Budgets are archived rather than removed, so the history of what limited
spend, and when, is never lost.
