Skip to content

v2.45.0 breaking change: cache_write_tokens added as required field in InputTokensDetails breaks openai-agents SDK #3480

Description

@DMLoy

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

  1. pip install openai==2.45.0 openai-agents==0.18.0
  2. 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.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions