Files
PaperClipAI/docs/api/costs.md
T
Michael NguyenandClaude Fable 5.2 f7fd3f43fe docs: correct three budget claims from the review of the budget docs (#22833)
## 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
> - Pull request #22784 updated the budget docs to match the code on
`master`
> - The review of #22784 found three claims that were stated too broadly
> - #22784 merged before the corrections reached its branch, so `master`
still has the three claims
> - An operator who reads them can expect the wrong behavior from a
budget
> - This pull request applies the three corrections. It changes docs
only
> - The benefit is that the budget docs on `master` match the review and
the code

## Linked Issues or Issue Description

Refs #22784
Refs #8856

**Issue type**

Incorrect content.

**Where is the issue?**

- `docs/guides/board-operator/costs-and-budgets.md`
- `docs/api/costs.md`
- `docs/guides/board-operator/creating-a-company.md`
- `docs/guides/board-operator/managing-agents.md`
- `docs/start/core-concepts.md`
- `docs/guides/agent-developer/cost-reporting.md`

**What's wrong?**

Three claims from #22784 are too broad:

1. The docs say that a budget does not stop an agent that runs on a
subscription. Subscription usage adds no billed spend, but a hard stop
in the agent's scope still refuses its runs, and the reserve per run
applies to every run.
2. One guide says that both thresholds are settings. Only the warning
percentage is a setting. The hard stop is on or off and always uses 100%
of the budget.
3. The docs say that the unpriced-usage setting blocks all usage with no
price. It does not cover every entry under "run costs unavailable".

**Suggested fix**

Apply the corrections from the review threads of #22784.

## What Changed

- Subscription claim: the docs now say that subscription usage adds $0
and never moves a budget toward its limit. They also say that a hard
stop on a shared budget and the reserve per run still apply to
subscription agents. Corrected in the main guide, the API page, and four
related guides.
- Thresholds: `creating-a-company.md` now says that you can change the
warning percentage and turn the hard stop on or off, and that the hard
stop always uses 100% of the budget.
- Unpriced usage: the guide now says that the setting covers usage from
a complete receipt that has no price. It lists the entries that do not
trigger `block`.

## Verification

I read the code on `origin/master`. I did not run the product.

- A hard stop refuses work in its scope without reading the billing
type: `server/src/services/budgets.ts:825`
- The reserve check does not read the billing type:
`server/src/services/budget-reservations.ts:160`
- The hard stop compares spend with the full amount:
`server/src/services/budgets.ts:258`
- The exclusions from the unpriced-usage block:
`server/src/services/budget-exposure.ts:144`
- I checked every internal link and anchor in the changed files with a
script. All resolve.
- `git diff --check` reports no whitespace errors.

## Risks

Low risk. The change is docs only. It is the same commit that the review
threads of #22784 refer to, applied on top of `master`.

> 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*
- [ ] 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>
2026-11-24 14:45:34 -08:00

155 lines
5.4 KiB
Markdown

---
title: Costs
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
```
POST /api/companies/{companyId}/cost-events
{
"agentId": "{agentId}",
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"inputTokens": 15000,
"outputTokens": 3000,
"costCents": 12,
"billingType": "metered_api",
"occurredAt": "2026-11-24T10:00:00Z"
}
```
`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
```
GET /api/companies/{companyId}/costs/summary
```
Returns total spend, the monthly company budget, and utilization.
## Costs by Agent
```
GET /api/companies/{companyId}/costs/by-agent
```
Returns per-agent cost breakdown.
## Costs by Project
```
GET /api/companies/{companyId}/costs/by-project
```
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 it never moves a budget toward its limit. A hard stop and `reservationCents` still apply to 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}/budgets
{ "budgetMonthlyCents": 100000 }
```
### Set Agent Budget
```
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 a complete usage receipt 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 |
|-----------|--------|
| `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 |
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.