Skip to content

fix(usage): include Claude cache tokens in prompt totals#2658

Open
zierocode wants to merge 1 commit into
decolua:masterfrom
zierocode:codex/claude-cache-inclusive-usage
Open

fix(usage): include Claude cache tokens in prompt totals#2658
zierocode wants to merge 1 commit into
decolua:masterfrom
zierocode:codex/claude-cache-inclusive-usage

Conversation

@zierocode

Copy link
Copy Markdown
Contributor

Summary

  • translate Claude non-streaming usage to OpenAI cache-inclusive prompt totals
  • preserve cache-read and cache-creation detail fields
  • reuse the existing canonical usage convention so client responses match the usage ledger

Why

Claude reports input tokens separately from cache-read and cache-creation tokens. The current OpenAI response translation exposes only input_tokens as prompt_tokens, while the ledger correctly folds cache tokens into its canonical prompt total. This makes the response usage disagree with the persisted usage row.

Tests

  • claude-nonstreaming-usage.test.js
  • cached-token-usage.test.js
  • cached-token-e2e.test.js

19 tests passed.

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