feat: extract cache tokens from prompt_tokens_details for non-Claude models#1226
Merged
Conversation
…models - Add ExtendedPromptTokensDetails interface extending OpenAI's PromptTokensDetails with cache_creation_input_tokens field - Update ClaudeUsage to override prompt_tokens_details with extended type - Update extendUsageWithCacheMetrics to extract cache tokens from prompt_tokens_details.cached_tokens and prompt_tokens_details.cache_creation_input_tokens as fallback when Claude top-level fields are absent (Claude top-level takes priority) - Remove supportsPromptCaching gate from aiService cache extraction — prompt_tokens_details is OpenAI-standard, applicable to all models - Remove unused modelName param from processStreamingResponse - Update Usage type comment to reflect dual-source cache fields - Add 3 test cases for prompt_tokens_details extraction - Update spec 021 docs to reflect cross-model cache token tracking
…cache token extraction Update spec 021 to explicitly distinguish two concerns: - supportsPromptCaching / WAVE_PROMPT_CACHE_REGEX gates cache_control marker injection (messages/tools) — Claude-only - Cache token extraction from usage applies to ALL models — no gate Updated: spec.md (FR-001, FR-007, FR-008, edge cases, key entities), data-model.md (relationships, model detection flow), quickstart.md (phase 3 integration notes), contracts/cache-control-api.md (scope note), research.md (universal caching alternatives)
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.
with cache_creation_input_tokens field
prompt_tokens_details.cached_tokens and prompt_tokens_details.cache_creation_input_tokens
as fallback when Claude top-level fields are absent (Claude top-level takes priority)
prompt_tokens_details is OpenAI-standard, applicable to all models