Description
openai==2.45.0 added cache_write_tokens as a required field to InputTokensDetails in src/openai/types/responses/response_usage.py. This is a breaking change for openai-agents (and likely any other library that constructs InputTokensDetails directly) because openai-agents==0.18.0 creates that model with only cached_tokens:
# openai-agents/usage.py
self.input_tokens_details = InputTokensDetails(cached_tokens=self_cached + other_cached)
With openai==2.45.0, this immediately raises:
pydantic.ValidationError: 1 validation error for InputTokensDetails
cache_write_tokens
Field required [type=missing, input_value={'cached_tokens': 0}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.13/v/missing
The error also surfaces when non-OpenAI providers (e.g. Google Gemini via the OpenAI-compatible endpoint) return a usage payload that only contains cached_tokens — the SDK's Pydantic model rejects it before it even reaches user code.
Steps to Reproduce
pip install openai==2.45.0 openai-agents==0.18.0
- Run any agent against a non-OpenAI provider (e.g. Gemini via
https://generativelanguage.googleapis.com/v1beta/openai/) — the provider returns input_tokens_details: {cached_tokens: 0} without cache_write_tokens.
- Observe
pydantic.ValidationError: cache_write_tokens Field required.
Or simply:
from openai.types.responses.response_usage import InputTokensDetails
InputTokensDetails(cached_tokens=0) # raises ValidationError in 2.45.0
Diff
In v2.44.0 (source):
class InputTokensDetails(BaseModel):
cached_tokens: int
In v2.45.0 (source):
class InputTokensDetails(BaseModel):
cache_write_tokens: int # ← NEW, required
cached_tokens: int
Expected Behavior
cache_write_tokens should be Optional[int] = None (or at minimum have a default of 0) so that:
- Existing callers that construct
InputTokensDetails(cached_tokens=...) don't break.
- Providers that don't return
cache_write_tokens in their usage payload don't cause a validation error.
Workaround
Pin openai==2.44.0 until this is resolved.
Environment
openai==2.45.0
openai-agents==0.18.0
- Python 3.11
Description
openai==2.45.0addedcache_write_tokensas a required field toInputTokensDetailsinsrc/openai/types/responses/response_usage.py. This is a breaking change foropenai-agents(and likely any other library that constructsInputTokensDetailsdirectly) becauseopenai-agents==0.18.0creates that model with onlycached_tokens:With
openai==2.45.0, this immediately raises:The error also surfaces when non-OpenAI providers (e.g. Google Gemini via the OpenAI-compatible endpoint) return a usage payload that only contains
cached_tokens— the SDK's Pydantic model rejects it before it even reaches user code.Steps to Reproduce
pip install openai==2.45.0 openai-agents==0.18.0https://generativelanguage.googleapis.com/v1beta/openai/) — the provider returnsinput_tokens_details: {cached_tokens: 0}withoutcache_write_tokens.pydantic.ValidationError: cache_write_tokens Field required.Or simply:
Diff
In
v2.44.0(source):In
v2.45.0(source):Expected Behavior
cache_write_tokensshould beOptional[int] = None(or at minimum have a default of0) so that:InputTokensDetails(cached_tokens=...)don't break.cache_write_tokensin their usage payload don't cause a validation error.Workaround
Pin
openai==2.44.0until this is resolved.Environment
openai==2.45.0openai-agents==0.18.0