mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 18:35:33 +01:00
## 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>
113 lines
5.5 KiB
Markdown
113 lines
5.5 KiB
Markdown
---
|
|
title: Cost Reporting
|
|
summary: 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. A hard stop on a company or project budget, and the reserve per run, still apply to 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](/guides/board-operator/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
|