Repository navigation
fix(openrouter): record billed costs as estimated_cost - #2848
Open
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
Open
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
Conversation
This branch has not been deployed
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
The OpenRouter instrumentation (
openrouter-instrumentation.tsandopenrouter-agent-instrumentation.ts) recorded the billed cost under a barecostmetric. Every other provider here that records a billed cost usesestimated_cost(ai-sdk-metrics.ts,flue,pi-coding-agent,eve,claude-agent-sdk,openai-batch), andai-sdk-instrumentation.tstreatsestimated_costas a special key. OpenRouter now records it the same way, so it is picked up like the other providers.The value is only recorded when it is a finite number, so NaN and +/-Infinity are dropped. A cost of 0 (free models) and negative values are still kept.
Behaviour change
OpenRouter spans no longer carry a
costmetric. Anyone filtering or chartingmetrics.costfor OpenRouter spans will find the same value underestimated_cost. Thecost_upstream_inference_*metrics are unchanged.Verification
cost_estimatedare each caught..json, 8.txt) were regenerated withnode scripts/run-e2e-tests.mjs --update openrouter-instrumentation openrouter-agent-instrumentation, which replays the recorded cassettes. Before regenerating, 12 snapshot tests failed on thecostkey. After, 88 pass and 2 skip, twice. The diff is only each"cost"line replaced by"estimated_cost"with the same value, moved to its sorted position.check:typings, lint (no new warnings) and the formatting check are clean, and the changeset validates.Not covered
The OpenRouter parser also emits
prompt_cache_write_tokens, which I left alone because #2842 touches that area.