feat(cost): itemize reasoning cost per span and by model#34
Merged
Conversation
feat(cost): itemize reasoning cost per span and by model
Reasoning tokens were already billed at their own rate, but the cost was
blended into the per-span total. This surfaces it as a first-class figure:
- computeCostBreakdownUsd returns {total, reasoning}; computeCostUsd is now a
thin wrapper over it, so existing behavior is unchanged.
- enrichSpanCost stores a per-span reasoning_cost_usd (additive migration v7,
SQLite + Postgres parity verified in-process).
- CostsRepository.summary adds `reasoning` (total) and `reasoningByModel` — the
routing dimension. The /api/costs/summary route surfaces both.
- Dashboard shows reasoning as a share of total and charts cost by model.
The reasoning figure is computed even with no explicit reasoning rate (the share
of the output bill those tokens account for), so it stays a sub-component of the
total, never an extra charge.
This makes the "use a smarter model on harder requests" routing premium legible
per request type instead of only in aggregate — as suggested by @alphaxagent.bsky.social.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@
JoniMartin27
added a commit
that referenced
this pull request
Jun 13, 2026
Reasoning tokens were already billed at their own rate, but the cost was
blended into the per-span total. This surfaces it as a first-class figure:
- computeCostBreakdownUsd returns {total, reasoning}; computeCostUsd is now a
thin wrapper over it, so existing behavior is unchanged.
- enrichSpanCost stores a per-span reasoning_cost_usd (additive migration v7,
SQLite + Postgres parity verified in-process).
- CostsRepository.summary adds `reasoning` (total) and `reasoningByModel` — the
routing dimension. The /api/costs/summary route surfaces both.
- Dashboard shows reasoning as a share of total and charts cost by model.
The reasoning figure is computed even with no explicit reasoning rate (the share
of the output bill those tokens account for), so it stays a sub-component of the
total, never an extra charge.
This makes the "use a smarter model on harder requests" routing premium legible
per request type instead of only in aggregate — as suggested by @alphaxagent.bsky.social.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
What
Lookspan already bills reasoning tokens at their own rate, but the cost was blended into the per-span total. This makes the reasoning cost a first-class, queryable figure — per span and per model.
computeCostBreakdownUsd(model, usage)returns{ total, reasoning }.computeCostUsdis now a thin wrapper, so existing behavior/signature is unchanged.enrichSpanCoststores a per-spanreasoning_cost_usdat ingest (additive migration v7; SQLite + Postgres parity verified in-process via pg-mem).CostsRepository.summaryaddsreasoning(total) andreasoningByModel(the routing dimension).GET /api/costs/summarysurfaces both.The reasoning figure is computed even when a model has no explicit
reasoningPer1M— it is then the share of the output bill those tokens account for, which is the very signal that tells you whether a dedicated reasoning rate is worth setting. It is always a sub-component oftotal, never an extra charge.Why
In reply to the reasoning-token billing post, @alphaxagent.bsky.social noted:
This delivers exactly that: the reasoning premium is now visible per request type (per model), not just in aggregate.
Tests
computeCostBreakdownUsd: explicit reasoning rate, output-rate fallback (total unchanged), zero-reasoning, unknown model.enrichSpanCost: itemizesreasoningCostUsdon the span.CostsRepository.summary+ Postgres parity:reasoningtotal andreasoningByModelround-trip and sum./api/costs/summaryexposes the new fields.npm run cigreen locally: typecheck, lint (biome), 237 tests, build.🤖 Generated with Claude Code
@