feat(messages): implement prompt caching metrics tracking#5469
Merged
cdoern merged 2 commits intollamastack:mainfrom Apr 14, 2026
Merged
feat(messages): implement prompt caching metrics tracking#5469cdoern merged 2 commits intollamastack:mainfrom
cdoern merged 2 commits intollamastack:mainfrom
Conversation
Add support for mapping OpenAI's cache metrics to Anthropic's cache fields. Maps usage.prompt_tokens_details.cached_tokens to cache_read_input_tokens in both non-streaming and streaming responses. cache_creation_input_tokens remains None as OpenAI does not provide this metric. Includes unit tests for both scenarios (cache metrics present and missing). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Charlie Doern <cdoern@redhat.com>
leseb
approved these changes
Apr 10, 2026
franciscojavierarceo
approved these changes
Apr 10, 2026
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
Implements prompt caching metrics tracking for the Anthropic Messages API by mapping OpenAI's cache metrics to Anthropic's cache fields.
Changes
usage.prompt_tokens_details.cached_tokens→cache_read_input_tokensin non-streaming responsesMessageDeltaEventcache_creation_input_tokensremainsNone(OpenAI does not provide this metric)Implementation
_openai_to_anthropic()to extract and map cache metrics_stream_openai_to_anthropic()to track and emit cache metricsprompt_tokens_detailsexistenceTesting
Added 2 unit tests:
test_cache_metrics_mapping- verifies cache metrics are properly mapped when presenttest_cache_metrics_missing- verifies graceful handling when cache metrics are absentAll 19 unit tests passing.
Test Plan
🤖 Generated with Claude Code