Repository navigation
fix(langchain): record audio token metrics from usage metadata - #2843
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 JS LangChain callback handler read
usage_metadata.input_token_detailsandoutput_token_detailsfor cache and reasoning tokens but ignored theiraudioentries, so audio-model LangChain spans lost audio-token cost attribution. The Python SDK records both (#1166), and the other JS providers use the same metric names.getMetricsFromResponsenow emitsprompt_audio_tokensfrominput_token_details.audioandcompletion_audio_tokensfromoutput_token_details.audio, next to the cache and reasoning handling and behind the same guards. Non-numbers are dropped and0is kept. Zero is emitted because Python emits audio whenever it is notNone, and this function already emitsprompt_cached_tokens: 0andcompletion_reasoning_tokens: 0the same way, so many OpenAI-style spans will now also carryprompt_audio_tokens: 0.Tests
callback-handler.test.ts: an end-to-end case plus sixit.eachcases (absent details, details without audio, non-number audio, non-record details, input-only, output-only). One existing test, "reports zero reasoning tokens rather than dropping the field", already fedaudio: 0on both sides and expected no audio metrics; it now expectsprompt_audio_tokens: 0andcompletion_audio_tokens: 0.check:typings,lint, the formatting check andvalidate-changesetsare clean.