Repository navigation
Closed
Description
Problem
Polylogue archives enough semantic structure to answer not only "what happened" but also "what did this likely cost." Right now there is no first-class cost model across providers and models, so cost analysis is left to ad hoc scripts and rough mental arithmetic.
That leaves several important questions unsupported:
- what did a session likely cost across input, output, cache, and tool phases?
- which providers or models are cheapest or most expensive for a given workload shape?
- how much budget did a day, week, or task cluster likely consume?
- what confidence should we have in an estimate when token or pricing data is partial?
Ambitiously strengthened scope
Implement a canonical cost-estimation substrate and expose it through archive product surfaces, not as a CLI-only calculator.
Required outcomes:
- normalize provider/model identity for pricing lookup across archived conversations and product rows
- define typed pricing, usage, estimate, uncertainty, and provenance contracts that can represent at least:
- input token price
- output token price
- cache read / cache write prices where a provider exposes them
- provider-supplied exact costs when archives contain them
- currency and pricing provenance/effective date
- missing-token and missing-price reasons without false precision
- compute estimated costs at useful semantic levels:
- message
- conversation/session
- aggregate rollups by provider, model, and time window
- make uncertainty explicit:
exactwhen provider/archive cost data is presentpricedwhen token counts and catalog prices are knownpartialwhen only some messages can be pricedunavailablewhen the archive lacks enough usable data
- expose at least one user-facing inspection path in CLI and one shared machine-facing path in facade/MCP or product APIs
- make the implementation intentionally compatible with later work-thread/task rollups by keeping the session estimate records composable
Design requirements
- Cost semantics must live in shared substrate/product logic, not in a formatter.
- Incomplete data must remain explicit. Do not silently emit false precision when token counts or historical prices are missing.
- Historical pricing changes need a real provenance story. If exact price at event time is unknown, that fact should be preserved in the estimate.
- Prefer reusing a sensible pricing/model catalog library or upstream source where that materially reduces maintenance burden, but keep the archive-side contract typed and provider-agnostic.
- The implementation should compose cleanly with later work on session clustering, summaries, and operator analytics.
- The first implementation may use a curated LiteLLM-compatible seed catalog rather than vendoring the full LiteLLM runtime, but it must document that as provenance and avoid pretending the seed is a live historical price oracle.
Acceptance criteria
- Polylogue can estimate costs for archived sessions across multiple providers and models using one shared contract.
- Estimates carry provenance and confidence metadata rather than just a naked float.
- Users can inspect cost rollups by provider/model and at least one per-session view.
- CLI JSON and MCP/facade product surfaces expose the same typed payload shape.
- Tests cover exact archive-provided cost, missing-token cases, missing-price cases, provider/model normalization, and at least one mixed-provider aggregate.
- The chosen pricing source/library and its limits are documented in the issue or implementation notes.
Useful references
- Claude usage/cost context reference:
https://she-llac.com/claude-limits?utm_source=unknownews - LiteLLM model price map, used as the shape/reference for the first curated catalog:
https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json
Metadata
Metadata
Assignees
Labels
No labels
Activity
Sinity commentedon Apr 24, 2026
Execution start for the strengthened #388 slice.
Decision: use Polylogue-owned typed estimate models and a small curated LiteLLM-shaped seed catalog for the first implementation, rather than adding the full LiteLLM runtime dependency. The reason is maintenance and trust boundary clarity: Polylogue needs stable archive-side semantics with explicit provenance; a bundled seed can say exactly when it is catalog-derived and incomplete, while provider/archive-reported exact costs still win when present.
Initial implementation target:
feat: add cost estimation products (#394)
Sinity commentedon Apr 24, 2026
Execution log for the expanded #388 slice:
exact/priced/partial/unavailablestatus, confidence, usage, components, price provenance, missing reasons, and normalized model identity.polylogue products costs,polylogue products cost-rollups, facade/sync facade product methods, and MCP registry-backed tools.devtools render-all --check: passeddevtools verify: passedCI was still hosted/in-progress at merge time; merge was based on local full verification and successful push hooks per current quota constraint.
feat: add cost estimation products (#394)