Conversation
OASIS records token usage on every run (RunResult.tokens) but never turns it into money, so a sweep's spend is invisible until the invoice arrives and models cannot be compared on cost-per-flag. Add src/lib/cost.ts: a pure lookup + arithmetic layer with no network calls. resolvePrice(model) -> ModelPrice | null (substring match, order-aware) estimateCost(model,tokens) -> CostEstimate estimateRunCost(run) -> CostEstimate summarizeCosts(runs) -> totals, per-model breakdown, usd-per-flag formatUsd(amount) -> sub-cent aware formatting Correct-model resolution: real runs record model: "custom" and put the concrete provider id in modelVersion. Pricing off run.model alone marked nearly every run unpriced, so estimateRunCost prefers modelVersion and falls back to model. Unknown models are reported as unpriced (usd: null + unpricedRuns count), never silently costed at zero, and models with zero flags get usdPerFlag: null rather than Infinity. Verified against 326 real run files on disk: runs 326, flags 95, unpriced 41, total .59, /bin/bash.05 per flag zai-org/GLM-5.3-Flash /bin/bash.0020 per flag (cheapest) moonshotai/Kimi-K3 /bin/bash.11 per flag 27 new tests cover pricing math, substring/ordering resolution, the modelVersion preference, unpriced accounting, per-model aggregation and formatting. Refs #77
5 tasks
This branch has not been deployed
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.
Problem
OASIS already records token usage on every run:
…but nothing translates those tokens into money. Consequences:
grepforcost|price|usd|spend|budgetacrosssrc/returns only two unrelated comments inenv-check.ts. This capability genuinely does not exist.Change
New module
src/lib/cost.ts— a pure lookup + arithmetic layer. No network calls, no provider SDKs, so it is trivially testable and cannot fail at runtime.Prices live in an exported, auditable table (
MODEL_PRICES) keyed by a lowercase substring, so versioned ids likezai-org/GLM-5.3-Flashandglm-5.3-flash-2026-01both resolve without an exhaustive enumeration. Ordering is significant and documented —glm-5.3-flashmust precedeglm-5.3, and a test asserts that specificity actually wins.Two deliberate correctness decisions
1. Unknown models are
unpriced, never$0.Silently costing an unknown model at zero is how a cost model quietly becomes fiction. Unknown models return
usd: nullwithunpriced: true, andsummarizeCosts()reports anunpricedRunscount so the total is never mistaken for complete.2. Pricing resolves off
modelVersion, notmodel.This one was found by running the module against real data rather than trusting the type. Actual runs on disk record:
Pricing off
run.modelalone marked nearly every run unpriced.estimateRunCost()therefore prefersmodelVersion, falls back tomodel, andsummarizeCosts()groups by the id the cost was actually computed from — otherwise the per-model breakdown collapses into a single"custom"bucket.Models with zero captured flags get
usdPerFlag: nullrather thanInfinity.Verification against real data
Run over the 326 real run files on disk (19.0M input / 854K output tokens, 95 flags):
That already answers a real question the project could not previously answer: GLM-5.3-Flash is ~55× cheaper per captured flag than Kimi-K3 at comparable flag counts.
Tests
tests/unit/cost.test.ts— 27 tests: pricing math, case-insensitivity, substring + specificity ordering,modelVersionpreference and fallback, unpriced accounting (including the no-tokens case), per-model aggregation,nullvsInfinityfor zero flags, empty-input handling, and sub-cent formatting. Also asserts the price table has no duplicate keys and no negative prices.Verification
Before: 441 tests. After: 446 tests, all passing. (441 includes the 22 docker tests from #79.)
Scope / follow-ups
This PR is the library layer only — it deliberately does not touch the CLI or report output. Wiring it into
oasis reportand printing a live running total during a sweep is a natural follow-up and would be a much smaller diff on top of this.Price list is list-price estimation for comparison, not a billing source of truth;
ModelPrice.sourcerecords provenance per entry so any number can be audited.Closes #77