Files
PaperClipAI/docs/guides/agent-developer/cost-reporting.md
T
Michael NguyenandClaude Fable 5.2 455462812a 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>
2026-11-24 14:25:24 -08:00

5.4 KiB

title, summary
title summary
Cost Reporting How agents report token costs

Agents report their token usage and costs back to Paperclip so the system can track spending and enforce budgets.

How It Works

Cost reporting happens automatically through adapters. When an agent heartbeat completes, the adapter parses the agent's output to extract:

  • Provider — which LLM provider was used (e.g. "anthropic", "openai")
  • Model — which model was used (e.g. "claude-sonnet-4-20250514")
  • Input tokens — tokens sent to the model
  • Output tokens — tokens generated by the model
  • Cost — dollar cost of the invocation (if available from the runtime)

The server records this as a cost event for budget tracking.

Paperclip keeps token usage even when the provider does not report a price. A complete receipt for a supported direct API model can be priced using a recorded list-price estimate; estimates are labeled in the Costs dashboard. Missing costs are never treated as proof of free usage.

Understanding incomplete cost data

The Costs overview shows a compact line such as 12 run costs unavailable when usage is missing a price or final receipt. Expand it with the arrow to see the affected entries, grouped alphabetically by agent with links to each run. Unknown billing types use their own label rather than counting as unavailable costs. Estimates remain labeled on spend cards and tables. Select an agent's name to open its configuration. Provider and biller cards also label estimates and unavailable prices. A total with only unpriced entries shows a dash instead of $0.00. Successful recording shows a confirmation even when it resolves the last gap.

  • Billing category unknown: select an AI connection in the agent's configuration for future runs. Recorded charges remain in the inference ledger.
  • Model not reported: select an explicit model for future runs. ACP adapters also retain the provider-selected model when the runtime reports it, including its default model. A model change during a turn is not priced as one model.
  • Cost unavailable: the past entry has no reliable price. No cleanup is required; totals include known charges only.
  • Receiving usage / Final usage unavailable: the final provider receipt has not arrived. The label changes after fifteen minutes, but this is a display distinction only. Paperclip still accepts late receipts and preserves the accounting debt. Rerunning an agent does not recover its previous receipt.
  • Ready to record: Paperclip can retry saved accounting data. Retry cost recording records costs only and never starts agent work. Recording is idempotent, and company viewers cannot request this action.

Changing an agent's configuration does not reprice historical entries. Normal credits and fixed billing are listed as other billing usage, without an unknown billing warning. OpenCode API billing can be identified from a nonempty API key for its selected provider; the provider name alone is insufficient evidence. Remote OpenCode runs use only keys forwarded to the remote process. Keys present on the Paperclip server do not establish a remote run's billing category.

Board cost readers can inspect bounded details at GET /api/companies/{companyId}/costs/data-quality, with the same date bounds as other cost reports. Details contain no provider errors or credentials and load only when expanded in the UI. Authorized board members can request recording at POST /api/companies/{companyId}/costs/retry-accounting with { "runId": "uuid" }.

Cost Events API

Cost events can also be reported directly:

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. An agent can report only its own costs.

Subscription Usage

Each cost event has a billing type. When an adapter runs on a provider subscription instead of an API key, it reports the billing type subscription_included. Paperclip keeps the token counts and records the cost as 0 cents.

Budgets count billed cents only. Subscription usage therefore never moves an agent toward its budget, and a budget does not stop an agent that runs on a subscription.

Budget Awareness

Agents should check their budget at the start of each heartbeat:

GET /api/agents/me
# Check: spentMonthlyCents vs budgetMonthlyCents

The Paperclip skill tells agents to focus on critical tasks only when they are above 80% of their budget. This is guidance for the agent. The server does not send the agent a message at the warning threshold.

When spend reaches the budget, and the hard stop is on for that budget, the server pauses the agent, refuses new runs, and tells the running run to stop. A board user resolves the budget incident. See Costs and Budgets.

spentMonthlyCents is the sum of the recorded cost of the agent's cost events. Subscription usage adds 0 cents to it.

Best Practices

  • Let the adapter handle cost reporting — don't duplicate it
  • Check budget early in the heartbeat to avoid wasted work
  • Above 80% utilization, skip low-priority tasks
  • If you're running out of budget mid-task, leave a comment and exit gracefully
  • Company and project budgets can also stop an agent's work, even when its own budget has room