feat(sdk): catalog Cost(ref, tokens) + unpriced-meter reporting#366
Merged
Conversation
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.
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.
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. Takesusage.Tokens(the short-key mapDone.Usageframes already carry) — no new vocabulary.Binding.CostBreakdownreturns the unpriced-meter list with the total. TodayBinding.Costsilentlycontinues past any meter it can't price and still returnsok=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.Costunchanged(float64, bool), now delegating toCostBreakdown—Stream.Cost/Response.Costand their tests are untouched.AboveTokens) pricing was already handled byrateFor; 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.