1616
1717@dataclass (repr = False , kw_only = True )
1818class UsageBase :
19- input_tokens : Annotated [int , Field (validation_alias = AliasChoices ('input_tokens' , 'request_tokens' ))] = 0
19+ input_tokens : Annotated [
20+ int ,
21+ # `request_tokens` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
22+ Field (validation_alias = AliasChoices ('input_tokens' , 'request_tokens' )),
23+ ] = 0
2024 """Number of input/prompt tokens."""
2125
2226 cache_write_tokens : int = 0
2327 """Number of tokens written to the cache."""
2428 cache_read_tokens : int = 0
2529 """Number of tokens read from the cache."""
2630
27- output_tokens : Annotated [int , Field (validation_alias = AliasChoices ('output_tokens' , 'response_tokens' ))] = 0
31+ output_tokens : Annotated [
32+ int ,
33+ # `response_tokens` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
34+ Field (validation_alias = AliasChoices ('output_tokens' , 'response_tokens' )),
35+ ] = 0
2836 """Number of output/completion tokens."""
2937
3038 input_audio_tokens : int = 0
@@ -34,7 +42,11 @@ class UsageBase:
3442 output_audio_tokens : int = 0
3543 """Number of audio output tokens."""
3644
37- details : Annotated [dict [str , int ], BeforeValidator (lambda d : d or {})] = dataclasses .field (default_factory = dict )
45+ details : Annotated [
46+ dict [str , int ],
47+ # `details` can not be `None` any longer, but we still want to support deserializing model responses stored in a DB before this was changed
48+ BeforeValidator (lambda d : d or {}),
49+ ] = dataclasses .field (default_factory = dict )
3850 """Any extra details returned by the model."""
3951
4052 @property
0 commit comments