Map OpenAI cached tokens in Java SDK#137
Open
Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit into
Open
Map OpenAI cached tokens in Java SDK#137Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit into
Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit into
Conversation
Andrew Kent (realark)
requested changes
Jul 6, 2026
Andrew Kent (realark)
left a comment
Collaborator
There was a problem hiding this comment.
we need to add spec tests for these metrics to make sure all the openai integrations are actually mapping metrics to the semconv tool. I'll knock this out in the next day or two. Thanks for getting us started, Alex!
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
prompt_cached_tokensmetrics.usage.prompt_tokens_details.cached_tokensandResponses API
usage.input_tokens_details.cached_tokens.InstrumentationSemConvtests for both payload shapes.Root Cause
The Java SDK preserved the raw OpenAI
usageobject, includingcached_tokens,but
InstrumentationSemConvonly mapped prompt, completion, total, andreasoning token fields into Braintrust span metrics.
As a result, OpenAI responses could contain:
usage.prompt_tokens_details.cached_tokensbut the exported Braintrust span omitted:
metrics.prompt_cached_tokensValidation