You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenAI integration does not record cache-write tokens #7870
Call client.responses.create(...) or client.chat.completions.create(...) and get a response whose usage has input_tokens_details.cache_write_tokens (or prompt_tokens_details.cache_write_tokens) set, e.g. 96.
Expected Result
The span has gen_ai.usage.input_tokens.cache_write = 96, like the Anthropic integration.
Actual Result
No cache-write attribute. _calculate_responses_token_usage and _calculate_completions_token_usage only read cached_tokens (openai.py#L283-L289).
Hi! I'm interested in contributing to this issue as my first contribution to sentry-python.
I noticed that a fix and test have already been proposed. Would it be useful for me to investigate the current implementation and test coverage, or is this issue already being handled internally?
I'd like to contribute without duplicating existing work. Thanks!
Thanks @aditiT09 for the interest. To avoid duplicate work: I already have a small fix with tests on my branch, so I can open the PR whenever it suits.
It reads cache_write_tokens from usage.prompt_tokens_details (chat completions) and usage.input_tokens_details (Responses API) in the two existing token helpers, so streaming is covered too, with tests for both APIs.
One question for the maintainers: which attribute should it set? gen_ai.usage.input_tokens.cache_write (what the Anthropic integration uses) or gen_ai.usage.cache_creation.input_tokens (what JS and langchain use)? Happy to follow whatever fits the #8012 work.
Activity
linear-code commentedon Oct 6, 2026
PY-2926
alexander-alderman-webb commentedon Oct 6, 2026
Thanks for reporting!
We'll be tackling these gaps in the coming months.
aditiT09 commentedon Oct 12, 2026
Hi! I'm interested in contributing to this issue as my first contribution to sentry-python.
I noticed that a fix and test have already been proposed. Would it be useful for me to investigate the current implementation and test coverage, or is this issue already being handled internally?
I'd like to contribute without duplicating existing work. Thanks!
4ktLuffy commentedon Oct 15, 2026
Thanks @aditiT09 for the interest. To avoid duplicate work: I already have a small fix with tests on my branch, so I can open the PR whenever it suits.
It reads
cache_write_tokensfromusage.prompt_tokens_details(chat completions) andusage.input_tokens_details(Responses API) in the two existing token helpers, so streaming is covered too, with tests for both APIs.One question for the maintainers: which attribute should it set?
gen_ai.usage.input_tokens.cache_write(what the Anthropic integration uses) orgen_ai.usage.cache_creation.input_tokens(what JS and langchain use)? Happy to follow whatever fits the #8012 work.