Skip to content

feat(sdk): catalog Cost(ref, tokens) + unpriced-meter reporting#366

Merged
aaliboyev merged 1 commit into
mainfrom
sdk-catalog-cost-breakdown
Jul 2, 2026
Merged

feat(sdk): catalog Cost(ref, tokens) + unpriced-meter reporting#366
aaliboyev merged 1 commit into
mainfrom
sdk-catalog-cost-breakdown

Conversation

@aaliboyev

Copy link
Copy Markdown
Member

Lets an SDK consumer that has only accumulated token counts price them against the catalog's built-in rate sheets, and closes a silent under-count in the existing cost path.

  • IndexedCatalog.Cost(ref, usage.Tokens) (float64, []string, bool) — one call: resolve the model ref, price the tokens. The catalog already ships every model's rates, so a consumer holding session/day token totals needs no local price table. Takes usage.Tokens (the short-key map Done.Usage frames already carry) — no new vocabulary.
  • Binding.CostBreakdown returns the unpriced-meter list with the total. Today Binding.Cost silently continues past any meter it can't price and still returns ok=true, so reasoning/audio/server-tool tokens vanish from the estimate with no signal — the same silent-drop class we just fixed for items. Callers can now render "input+output priced, reasoning unpriced" honestly instead of guessing.
  • Binding.Cost unchanged (float64, bool), now delegating to CostBreakdownStream.Cost/Response.Cost and their tests are untouched.
  • Tiered (AboveTokens) pricing was already handled by rateFor; added a test to pin it.

Tests cover the unpriced list (known-but-unpriced meter + unknown key), zero-count meters not being reported, tiered selection, and the resolve-then-price path incl. unknown-ref.

Give consumers holding accumulated token totals a one-call price path that
uses the catalog's own knowledge of every model's rate sheet:

- IndexedCatalog.Cost(ref, usage.Tokens) resolves the ref and prices it,
  so a caller with session token totals needs no local price table.
- Binding.CostBreakdown returns the unpriced-meter list alongside the
  total. Binding.Cost previously skipped any meter it couldn't price and
  still returned ok=true — a silent under-count (reasoning/audio/etc. tokens
  vanished from the estimate). Callers can now surface what went unpriced
  instead of presenting a partial total as complete.
- Binding.Cost keeps its (float64, bool) signature, delegating to
  CostBreakdown, so Stream.Cost/Response.Cost are unchanged.

Tiered (AboveTokens) pricing was already handled by rateFor; tests pin it.
@aaliboyev aaliboyev merged commit 3736c1f into main Jul 2, 2026
2 checks passed
@aaliboyev aaliboyev deleted the sdk-catalog-cost-breakdown branch July 2, 2026 17:38
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