fix(sdk): take max of OpenRouter cost and upstream_inference_cost - #1175
Open
nordicnode wants to merge 1 commit into
Open
fix(sdk): take max of OpenRouter cost and upstream_inference_cost#1175nordicnode wants to merge 1 commit into
nordicnode wants to merge 1 commit into
Conversation
usage.cost is the total amount charged and already contains the upstream portion reported separately in cost_details.upstream_inference_cost, so summing the two roughly doubles the credits on normal (non-BYOK) OpenRouter routes — the shape behind the inflated-usage reports. The ledger side already takes the max (see the Solar Pro 4 BYOK note in common/src/constants/freebuff-models.ts, where cost is 0 and upstream carries the real spend); this fixes the user-facing credit path the same way at all three sites (stream, generateText, structured). Fixes CodebuffAI#1164
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.
Summary
usage.cost + cost_details.upstream_inference_costat all three cost sites (sdk/src/impl/llm.tsstreamingreportCost,generateText, and structured paths)usage.costis the total amount charged and already includes the upstream portion reported separately incost_details, per OpenRouter's usage accounting docs — summing them roughly doubles credits on normal (non-BYOK) OpenRouter routes, which lines up with the "extreme inflation" reports on Discordcommon/src/constants/freebuff-models.ts: cost = 0 there and upstream carries the real spend, so max is correct for both shapes)cost=0.01, upstream=0.02(fails under the sum: 3 vs 2)Fixes #1164
Validation
Re-run on the new main after the history rewrite:
bun test sdk/src/impl/__tests__/usage-receipts.test.ts— 5 pass, 0 failbunx tsc --noEmit -p sdk/tsconfig.jsoncleanReplaces #1165 — auto-closed when the repo history was force-pushed (the original commits no longer exist in the new history). Rebased onto the new main per the maintainer's request; picking the review up here.