Skip to content

feat: extract cache tokens from prompt_tokens_details for non-Claude models#1226

Merged
lewis617 merged 2 commits into
mainfrom
feat/prompt-tokens-details-cache
Jun 12, 2026
Merged

feat: extract cache tokens from prompt_tokens_details for non-Claude models#1226
lewis617 merged 2 commits into
mainfrom
feat/prompt-tokens-details-cache

Conversation

@lewis617

Copy link
Copy Markdown
Collaborator
  • 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

lewis617 added 2 commits June 12, 2026 16:15
…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)
@lewis617 lewis617 merged commit e246f07 into main Jun 12, 2026
1 check passed
@lewis617 lewis617 deleted the feat/prompt-tokens-details-cache branch June 12, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant