Record OpenAI cache write tokens on spans
get_openai_usage_attributes reads cached_tokens from prompt_tokens_details (chat completions) or input_tokens_details (Responses), but ignored the cache_write_tokens field that the OpenAI API and the openai SDK (3.35) report next to it. gen_ai.usage.cache_creation.input_tokens, which is defined in llm_providers/semconv.py and allow-listed in the scrubber, was therefore never set on OpenAI spans, and the cache-write count was only visible inside gen_ai.usage.raw.
Both counts are now passed to get_usage_attributes, the same way get_anthropic_usage_attributes does since #2616. This covers chat completions, the Responses API and streams, since they all go through this function. Counts are only recorded when non-zero, so spans without prompt caching are unchanged.
Test: test_cache_write_tokens_recorded mocks a chat completion (cached_tokens=20, cache_write_tokens=30) and a Responses response (cache_write_tokens=40), and checks gen_ai.usage.cache_creation.input_tokens is 30 and 40 and that the cache read attribute is absent when it is 0. It fails on main with a KeyError and passes with the change. The existing cache tests in test_openai.py still pass; the 5 failures in test_openai.py/test_anthropic.py that occur in my environment are identical on main.
This change was made with Claude Code (AI-assisted); the test above was run before opening the PR.
š¤ Generated with Claude Code