Repository navigation
fix(sdk-openrouter): count the provider cost of byok requests - #92
Merged
Merged
Conversation
For a request with the user's own provider key (BYOK), the provider bills the inference, and OpenRouter's usage.cost is only the OpenRouter fee. The fee is zero inside the free BYOK allowance. Thus the integrations recorded the fee as the cost of the request. When usage.is_byok is true, the TypeScript and Python integrations now record usage.cost plus cost_details.upstream_inference_cost as gen_ai.usage.cost. Without the upstream inference cost, they record no cost, and telemetry.dev calculates an estimate from the token counts. Requests without BYOK keep usage.cost.
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.
A request with the user's own provider key (BYOK) through the OpenRouter SDK integration now gets the cost that the provider bills. Before this change, the span took
usage.cost. For a BYOK request, that value is only the OpenRouter fee, which is 0 inside OpenRouter's free BYOK allowance. Thus BYOK calls showed as free.When
is_byokis true, the span cost iscost_details.upstream_inference_costplususage.cost. If the upstream cost is not in the response, the span gets no cost, and telemetry.dev calculates an estimate from the token counts. Requests without BYOK keepusage.cost, with the upstream cost as the fallback, as before. The TypeScript and Python integrations change together.The tests that ran are
packages/openrouter/tests/openrouter.test.ts(55 pass) andsdks/python-openrouter/tests/test_openrouter.py(73 pass).