Merge remote-tracking branch 'origin/master' into swarm-neon-tmp

* origin/master:
  docs: describe budgets as they work today (#22784)
This commit is contained in:
Dotta committed 2026-11-24 16:26:47 -06:00
commit 9108b25251
7 files changed
+324 -47

No files matched your search

+93 -10
View File
@@ -5,6 +5,8 @@ summary: Cost events, summaries, and budget management
Track token usage and spending across agents, projects, and the company.
For how budgets behave, see [Costs and Budgets](/guides/board-operator/costs-and-budgets).
## Report Cost Event
```
@@ -15,11 +17,17 @@ POST /api/companies/{companyId}/cost-events
"model": "claude-sonnet-4-20250514",
"inputTokens": 15000,
"outputTokens": 3000,
"costCents": 12
"costCents": 12,
"billingType": "metered_api",
"occurredAt": "2026-11-24T10:00:00Z"
}
```
Typically reported automatically by adapters after each heartbeat.
`occurredAt` is required. `billingType` is optional and defaults to `unknown`. Its values are `metered_api`, `subscription_included`, `subscription_overage`, `credits`, `fixed`, and `unknown`.
An agent can report only its own costs.
Typically reported automatically by adapters after each heartbeat. Adapters record usage that is included in a subscription with the billing type `subscription_included` and a cost of 0 cents.
## Company Cost Summary
@@ -27,7 +35,7 @@ Typically reported automatically by adapters after each heartbeat.
GET /api/companies/{companyId}/costs/summary
```
Returns total spend, budget, and utilization for the current month.
Returns total spend, the monthly company budget, and utilization.
## Costs by Agent
@@ -35,7 +43,7 @@ Returns total spend, budget, and utilization for the current month.
GET /api/companies/{companyId}/costs/by-agent
```
Returns per-agent cost breakdown for the current month.
Returns per-agent cost breakdown.
## Costs by Project
@@ -43,29 +51,104 @@ Returns per-agent cost breakdown for the current month.
GET /api/companies/{companyId}/costs/by-project
```
Returns per-project cost breakdown for the current month.
Returns per-project cost breakdown.
## Report Period
The cost reports above use the current UTC calendar month by default. To change the period, add query parameters:
- `from` and `to` — an ISO date or an ISO date-time with an offset
- `period=all` — all recorded costs. Do not combine it with `from` or `to`
## Subscriptions and Provider Quota
```
GET /api/companies/{companyId}/costs/subscriptions
GET /api/companies/{companyId}/costs/quota-windows
```
`costs/subscriptions` returns the subscription accounts that the caller can see, with their monthly fees. `costs/quota-windows` returns the quota windows that each connected subscription provider reports, with the percent used and the reset time.
Both are board-only. Both are separate from budgets.
## Budget Management
A budget is a budget policy on one scope: `company`, `agent`, or `project`. Only board users can change budgets.
Budgets count billed cost in cents (`billed_cents`). Usage with the billing type `subscription_included` has a cost of 0 cents, so a budget does not stop an agent that runs on a subscription.
### Budget Overview
```
GET /api/companies/{companyId}/budgets/overview
```
Returns every budget policy with its observed spend, status (`ok`, `warning`, or `hard_stop`), and window. Also returns the open budget incidents and the number of paused agents and projects.
### Set Company Budget
```
PATCH /api/companies/{companyId}
PATCH /api/companies/{companyId}/budgets
{ "budgetMonthlyCents": 100000 }
```
### Set Agent Budget
```
PATCH /api/agents/{agentId}
PATCH /api/agents/{agentId}/budgets
{ "budgetMonthlyCents": 5000 }
```
Both calls set a budget for the UTC calendar month. A value of `0` turns the budget off.
`PATCH /api/companies/{companyId}` and `PATCH /api/agents/{agentId}` still accept `budgetMonthlyCents` and set the same budget.
### Set Any Budget Policy
```
POST /api/companies/{companyId}/budgets/policies
{
"scopeType": "project",
"scopeId": "{projectId}",
"windowKind": "lifetime",
"amount": 20000
}
```
| Field | Default | Meaning |
|-------|---------|---------|
| `scopeType` | — | `company`, `agent`, or `project`. Required |
| `scopeId` | — | The ID of the company, agent, or project. Required |
| `windowKind` | `calendar_month_utc` | `calendar_month_utc` or `lifetime` |
| `amount` | — | The limit in cents. Required for a new policy. `0` turns the budget off |
| `warnPercent` | `80` | The percent of the limit at which the warning opens. From 1 to 99 |
| `notifyEnabled` | `true` | Whether the warning opens |
| `hardStopEnabled` | `true` | Whether work stops when spend reaches the limit |
| `reservationCents` | `0` | An estimate held against the budget before each run starts |
| `unpricedUsagePolicy` | `block` | `block` or `allow`. What to do when usage has no reliable price |
| `isActive` | `true` | Set `false` to turn the policy off and keep its amount |
A scope has one policy for each window kind. A second call with the same scope and window updates the policy. Fields you leave out keep their value.
The project page in the UI sets project budgets with the `lifetime` window. If you leave `windowKind` out of this call, the policy uses `calendar_month_utc`.
### Resolve a Budget Incident
```
POST /api/companies/{companyId}/budget-incidents/{incidentId}/resolve
{ "action": "raise_budget_and_resume", "amount": 150000 }
```
| Action | Effect |
|--------|--------|
| `raise_budget_and_resume` | Sets the limit to `amount`, removes the budget pause, and continues the runs that the hard stop cancelled. `amount` is required and must be more than the observed spend |
| `keep_paused` | Dismisses the incident. The scope stays paused |
## Budget Enforcement
| Threshold | Effect |
|-----------|--------|
| 80% | Soft alert — agent should focus on critical tasks |
| 100% | Hard stop — agent is auto-paused |
| `warnPercent` of the limit (default 80%) | A warning incident opens. Work continues |
| 100% of the limit, when `hardStopEnabled` is on (default) | A hard-stop incident opens. The scope is paused with the pause reason `budget`. New runs are refused and running work is told to stop |
Budget windows reset on the first of each month (UTC).
Monthly windows reset on the first of each month (UTC). At the reset, Paperclip closes the open incident of a monthly budget and removes its budget pause. A `lifetime` budget does not reset.