Conversation
GPT-5.6 and later report prompt-cache writes in cache_write_tokens. Read that field for the Responses API and Chat Completions, including streaming usage chunks, so cacheWriteTokens is no longer hardcoded to 0. Co-authored-by: florian <florian@omnifact.ai>
This branch has not been deployed
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.
What
@core-ai/openainow reads prompt-cache writes from the API usage payload:usage.input_tokens_details.cache_write_tokensusage.prompt_tokens_details.cache_write_tokensThose values map to
usage.inputTokenDetails.cacheWriteTokens. A missing field still maps to0.inputTokensstays the provider total, inclusive of cache reads and writes.@core-ai/azure-openaiuses these same adapters, so GPT-5.6 and later cache-write billing is reported there as well. TheChatUsagecomment that said only Anthropic reports cache writes is updated to match.Why
Starting with GPT-5.6, OpenAI bills cache writes at 1.25× the uncached input rate and reports them in
cache_write_tokens. The mappers hardcodedcacheWriteTokens: 0, so the written tokens stayed insideinputTokenswith no write breakdown. Callers that pricecacheWriteTokensseparately under-reported cost by 0.25× input on every written token.Tests
Adapter fixtures cover Responses and Chat Completions, streaming and non-streaming, for both a present
cache_write_tokensvalue and a missing field.npm run testpassed for@core-ai/openai,@core-ai/core-ai, and@core-ai/azure-openai. Lint andtsc --noEmitpassed for the OpenAI and core packages.