Fix tests for openai v2.45.0 cache_write_tokens compatibility#453
Merged
Conversation
openai v2.45.0 added a required field to in . Existing tests construct without this field, causing ValidationError on the newer version. Pass to all InputTokensDetails constructions. This is backward compatible because openai's BaseModel uses , so the extra field is silently accepted on older versions that don't define it. Verified passing on both openai v2.44.0 and v2.45.0.
fanzeyi
enabled auto-merge (squash)
July 16, 2026 21:36
nisha2003
self-requested a review
July 16, 2026 21:37
nisha2003
approved these changes
Jul 16, 2026
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.
Problem
CI started failing for the
langchaintests and type checks due to a breaking change inopenai v2.45.0(released July 9, 2026).openai v2.45.0added a new required fieldcache_write_tokens: inttoInputTokensDetailsinopenai.types.responses.response_usage:Existing tests construct
InputTokensDetails(cached_tokens=...)withoutcache_write_tokens, causingValidationErroron v2.45.0.Failures
This causes 6 test failures and 4
tytype-check errors:test_convert_responses_usage_to_usage_metadata(2 parametrized)test_extract_response_usage_from_chunk(2 parametrized)test_build_usage_chunk_from_responses(1 parametrized)test_chat_databricks_responses_api_invoke_returns_usage_metadataThe
langchain_testandlangchain_test_with_extrasjobs fail withuv: highestresolution (which picks up v2.45.0), whilelowest-directstill passes (uses older version).Fix
Pass
cache_write_tokens=0to allInputTokensDetailsconstructions.This is backward compatible: openai's
BaseModelusesextra='allow', so the extra field is silently accepted on older versions (e.g. v2.44.0) that don't define it.Verified passing on both
openai==2.44.0andopenai==2.45.0.