Skip to content

fix(usage): map OpenAI chat cache_write_tokens to cache_creation_tokens - #728

Open
pcbeingused333 wants to merge 1 commit into
activeagents:mainfrom
pcbeingused333:fix/openai-chat-cache-write-tokens
Open

pcbeingused333 wants to merge 1 commit into
activeagents:mainfrom
pcbeingused333:fix/openai-chat-cache-write-tokens

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Usage.from_openai_chat copies prompt_tokens_details.cached_tokens but ignores prompt_tokens_details.cache_write_tokens, so cache_creation_tokens stays nil for OpenAI chat responses that report cache writes. from_anthropic already maps its equivalent field, and the openai gem declares CompletionUsage::PromptTokensDetails#cache_write_tokens.

Fix: pass cache_write_tokens as cache_creation_tokens. Test: added a case in test/providers/common/usage_test.rb asserting both cached and cache-creation tokens are populated (fails on main with Expected: 30, Actual: nil).

Disclosure: this change was prepared with AI assistance (Claude Code); it has not been reviewed line by line by a human.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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