Skip to content

fix(usage): preserve nonnegative provider-reported exact cost - #2453

Open
ryanngit wants to merge 2 commits into
decolua:masterfrom
ryanngit:xai-exact-usage-cost
Open

ryanngit wants to merge 2 commits into
decolua:masterfrom
ryanngit:xai-exact-usage-cost

Conversation

@ryanngit

@ryanngit ryanngit commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve trusted provider-reported exact request cost without replacing current pricing tables or usage UI.

  • carry cost_usd, cost_in_usd, and cost_in_usd_ticks through usage extraction, normalization, format filtering, and canonical storage
  • prefer cost_usd, then cost_in_usd, then xAI ticks
  • accept finite nonnegative totals, including exact zero
  • reject negative, empty, NaN, and infinite totals
  • trust exact provider total even when local model pricing is missing
  • convert xAI ticks using 1 USD = 10^10 ticks
  • fall back to current local token pricing when exact value is invalid or absent

Scope

This refresh intentionally excludes:

  • model pricing table changes
  • cache-write/effective-tier transport
  • stored/UI component breakdowns
  • xAI local quota/dashboard rows
  • historical usage rewrites
  • API-key grouping

Streaming cache/tier work remains separate and overlaps #2348, #2713, #2747, #2873, and #2880. Exact embedding usage from #2794 is already upstream.

Base: v0.5.45 at 6fcd27337a7893642c7fe630840d0a641743f28f

Verification

  • focused/adjacent Vitest: 2 files, 25/25 passed
  • tests cover missing pricing, exact zero, precedence, negative rejection, xAI tick scale, streaming extraction, non-streaming extraction, and existing cache accounting
  • production npm run build: passed
  • changed-file ESLint: passed
  • git diff --check: passed
  • Gitleaks: 4 changed files, no findings

Full upstream suite is not used as binary gate because pristine v0.5.45 currently has 111 unrelated baseline failures.

@ghost
ghost force-pushed the xai-exact-usage-cost branch from 10139ee to 7659bc2 Compare July 10, 2026 01:12
@ghost ghost changed the title fix(usage): preserve provider-reported cost fix(usage): account for exact costs, tiers, and cache writes Jul 10, 2026

ghost commented Jul 16, 2026

Copy link
Copy Markdown
Author

Updated onto v0.5.35. Conflict resolution preserves upstream concise request logging while retaining service-tier attribution and exact cache/cost accounting. Focused pricing/usage tests pass (33/33); changed-path lint differs only by the same four React findings present on stock v0.5.35.

@ghost
ghost force-pushed the xai-exact-usage-cost branch from 302a4ba to bf2da72 Compare July 19, 2026 11:43

ghost commented Jul 21, 2026

Copy link
Copy Markdown
Author

v0.5.40 refresh

  • Base: upstream/master = v0.5.40 (79918c7)
  • Branch head: 2a6741b7f10793db784c21a9fc20993447536b36 (was bf2da7259601f839207c1bb9d4bdcfb3e09017c4)
  • Merge: merged
  • Tests (TMPDIR in worktree): pass — Test Files 5 passed (5); Tests 31 passed (31);
  • Files: tests/unit/xai-usage.test.js tests/unit/current-model-pricing.test.js tests/unit/responses-stream-to-json-usage.test.js tests/unit/usage-dispatch.test.js tests/unit/cached-token-usage.test.js
  • git diff --check: clean
  • gitleaks on range: ok

@ghost ghost mentioned this pull request Aug 3, 2026
@ghost
ghost force-pushed the xai-exact-usage-cost branch from 2a6741b to 846b0d2 Compare August 3, 2026 08:09
@ghost ghost changed the title fix(usage): account for exact costs, tiers, and cache writes fix(usage): preserve nonnegative provider-reported exact cost Aug 3, 2026

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Author

v0.5.45 split refresh

Force-pushed 846b0d2f from pristine v0.5.45, replacing old combined history with one exact-total commit.

Corrected old branch defects:

  • exact cost now wins when pricing is null
  • negative exact totals are rejected
  • zero remains authoritative
  • xAI scale is 1e10 ticks per USD, not 1e12

Removed pricing tables, cache/tier transport, UI breakdown, xAI local usage, and already-merged embedding scope. Fresh gates: 25/25 tests, production build, ESLint, diff check, and Gitleaks passed.

# Conflicts:
#	tests/unit/cached-token-usage.test.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant