mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
docs: describe budgets as they work today (#22784)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Operators control what agents spend with budgets, and the public docs explain how budgets work > - The budget docs were last changed in March 2026. The budget system was rebuilt after that > - The docs still describe a fixed 80% alert and a 100% auto-pause on company and agent budgets only > - The docs do not say that budgets count billed dollars only. Subscription usage is recorded at zero cents, so a budget never stops an agent that runs on a subscription > - An operator who reads the docs today can believe that a budget protects a subscription. It does not > - This pull request updates the cost and budget docs to match the code on `master`. It changes docs only > - The benefit is that operators and agent developers get a correct description of what a budget does and does not do ## Linked Issues or Issue Description Refs #8856 Related open pull requests. None of them changes these docs: #22745, #13379, #11511, #17356. **Issue type** Outdated content. **Where is the issue?** - `docs/guides/board-operator/costs-and-budgets.md` - `docs/api/costs.md` - The budget lines in `docs/guides/board-operator/managing-agents.md`, `docs/guides/board-operator/dashboard.md`, `docs/guides/board-operator/creating-a-company.md`, `docs/start/core-concepts.md`, and `docs/guides/agent-developer/cost-reporting.md` **What's wrong?** The docs describe the budget system as it was in March 2026. Seven points are wrong or missing. Each point is listed under Verification with the code that supports the new text. **Suggested fix** Update the docs to describe the behavior of the code on `master`. Do not change product code. ## What Changed - `costs-and-budgets.md`: added a warning at the top. A budget counts billed dollars only, and it does not stop an agent that runs on a subscription. - `costs-and-budgets.md`: added the three budget scopes (company, agent, project) and their windows. - `costs-and-budgets.md`: added the budget settings and their defaults (`warnPercent`, `notifyEnabled`, `hardStopEnabled`, `reservationCents`, `unpricedUsagePolicy`). - `costs-and-budgets.md`: rewrote the enforcement section. It now describes the warning, the hard stop, the budget incident, the two ways to resolve it, and the monthly reset. - `costs-and-budgets.md`: added where to set a budget in the UI and with the API. It says that the older `budgetMonthlyCents` fields still work. - `costs-and-budgets.md`: added sections for the reserve per run, usage with no reliable price, the Subscriptions card, and provider quota windows. - `docs/api/costs.md`: added the budget overview, budget policy, and incident routes, the report period parameters, and the subscription and quota routes. Added the required `occurredAt` field to the cost event example. - The five related guides: corrected the lines that repeated the old claims. Each one now links to the main guide. ## Verification I read the code on `origin/master` at commit `0731cd3afc`. I did not run the product. Each point below has the file and line that supports the new text. 1. **Budgets exist for a company, an agent, and a project. A project budget uses a lifetime window.** Corrected. - Scopes: `packages/shared/src/constants.ts:1050` - The service uses `lifetime` for a project when no window is given: `server/src/services/budgets.ts:862` - The project page sends `lifetime`: `ui/src/pages/ProjectDetail.tsx:658` - The request validator fills in `calendar_month_utc` when the field is absent: `packages/shared/src/validators/budget.ts:14`. The docs therefore tell API callers to send `"windowKind": "lifetime"` for a project. 2. **Budgets count dollars only. Subscription usage is recorded at zero cents.** Corrected, and stated at the top of the guide. - The only metric is `billed_cents`: `packages/shared/src/constants.ts:1053` - `subscription_included` is billed at 0: `server/src/services/heartbeat/run-state.ts:522` - Budget exposure counts it as 0: `server/src/services/budget-exposure.ts:33` - Claude Code and Codex report subscription billing when no API key is set: `packages/adapters/claude-local/src/server/execute.ts:176`, `packages/adapters/codex-local/src/server/execute.ts:204` 3. **The warning threshold and the hard stop are settings.** Corrected. - Defaults `warnPercent` 80 and `hardStopEnabled` true: `server/src/services/budgets.ts:912` - `warnPercent` accepts 1 to 99: `packages/shared/src/validators/budget.ts:17` - The UI shows `warnPercent` but has no control to change it: `ui/src/components/BudgetPolicyCard.tsx:108` 4. **At the hard stop, new work is refused, running work is told to stop, and an incident opens.** Corrected. - Incident, pause, and cancellation: `server/src/services/budgets.ts:770` - New work is refused: `server/src/services/budgets.ts:825` - Raise the budget or keep the scope paused: `server/src/services/budgets.ts:1045` - **A new month does resume a paused scope.** The budget worker reconciles held monthly scopes at the end of the UTC month: `server/src/services/budgets.ts:1329` and `server/src/services/budget-enforcement-worker.ts:44`. With no spend in the new window, the service closes the incident and removes the budget pause: `server/src/services/budgets.ts:716`. This also applies after "Keep paused". A manual pause stays. A lifetime budget does not reset. 5. **The "focus on critical tasks" text at 80% is skill guidance.** Corrected. - The text is in the skill: `skills/paperclip/SKILL.md:681` - At the soft threshold the server opens an incident and writes an activity entry. It sends nothing to the agent: `server/src/services/budgets.ts:750` 6. **Where to set a budget.** Corrected. - Routes: `server/src/routes/costs.ts:347` (overview), `:355` (policies), `:367` (resolve incident), `:399` (company), `:418` (agent) - UI: `ui/src/pages/audit/audit-navigation.ts:11`, `ui/src/pages/Costs.tsx:745`, `ui/src/pages/ProjectDetail.tsx:876`, `ui/src/pages/AgentDetail.production.tsx:186` - **The old fields still work.** `PATCH /companies/:id` with `budgetMonthlyCents`: `server/src/services/companies.ts:430`. `PATCH /agents/:id` with `budgetMonthlyCents`: `server/src/services/agent-configuration.ts:196`. On an agent the change needs a board user: `server/src/routes/agents.ts:5637`. 7. **Reserve per run, unpriced-usage policy, Subscriptions, and quota windows.** Added. - Reserve per run: `ui/src/components/BudgetPolicyCard.tsx:61`, `server/src/services/budget-reservations.ts:160` - Unpriced-usage policy: `server/src/services/budgets.ts:244` - Subscriptions: `server/src/routes/costs.ts:114`, `ui/src/components/SubscriptionCostCard.tsx:113` - Quota windows: `server/src/routes/costs.ts:332`, `packages/shared/src/types/quota.ts:2` Could not confirm: - I took the UI paths from the code and from `maps/feature-map/budgets-costs.md`. I did not check them on a running instance. - I found no UI control that creates the first company budget. The Budgets page edits a company budget that exists. The docs say to create it with the API. A maintainer who knows the UI should confirm this sentence. - I did not find an adapter that reports `subscription_overage`. The docs say only that such usage counts for its reported cost. Checks: - `pnpm verify` exits with code 2. It reports a global CI input change (`docs/api/costs.md`), so required CI supplies the broad coverage. I did not run the full local suite. - I checked every internal link and anchor in the seven changed files with a script. All resolve. - `git diff --check` reports no whitespace errors. - No test reads the changed files. ## Risks Low risk. The change is docs only. - A wrong sentence in these docs can mislead an operator about spend. The two sentences that most need a maintainer's review are the monthly resume (point 4) and the company budget in the UI (see "Could not confirm"). - `docs/guides/board-operator/delegation.md` still says that a CEO above 80% of its budget focuses on critical tasks. That is the skill guidance from point 5. I did not change that file. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Fable 5.2 (Anthropic), model ID `claude-fable-5-2`, in Claude Code. Extended thinking and tool use (file read, search, shell, `gh`). The model read the code, wrote the docs, and wrote this description. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass — *docs only. No test reads these files. `pnpm verify` asks for required CI* - [ ] I have added or updated tests where applicable — *not applicable. Docs only* - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green — *pending on this PR* - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups — *pending on this PR* - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
3128be7cda
commit
455462812a
7 files changed
+324
-47
No files matched your search
+93
-10
@@ -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.
|
||||
Reference in new issue
Block a user