fix(openai): report prompt cache write tokens in usage - #331
Open
1stRunciter wants to merge 1 commit into
Open
Conversation
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.
Current behavior
OpenAI Responses cache writes remain inside
InputTokens, whileCacheCreationTokensstays zero.Expected behavior
Subtract provider-reported cached reads and cache writes from normalized input tokens, and expose writes through the existing
CacheCreationTokensfield. Normalized input is clamped at zero, whileTotalTokensretains the existing raw input-plus-output aggregate.Compatibility
Absent or zero cache-write values preserve existing behavior. This makes no public API changes.
Path coverage
The shared mapping covers generate,
response.completedandresponse.incompletestreams, successful object generation, both object-stream terminal events, and no-text object-generation errors.Evidence
OpenAI documents
cache_write_tokensandcached_tokensunder Responsesusage.input_tokens_detailsin the prompt caching guide.input_tokenscached_tokenscache_write_tokensScope
Responses only. Chat Completions and proxy-provider behavior remain unchanged.
Validation
gofumpt -w providers/openai/responses_language_model.go providers/openai/openai_test.gogolangci-lint rungo test ./... -count=1 -timeout=30m