You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is no reason for any of the values to be optional, since those are all counters. Rather than None, they should be zeros. This change will make tracking usage require much less client code.
Unnecessary optionals:
CompletionUsage.completion_tokens_details
CompletionUsage.prompt_tokens_details
PromptTokensDetails.audio_tokens
PromptTokensDetails.cached_tokens
CompletionTokensDetails.audio_tokens
CompletionTokensDetails.reasoning_tokens
Additional context
Currently, you need to write something like this for type checking to work (I don't think Mypy will work with code catching AttributeError):
reasoning_tokens = (left.completion_tokens_details and left.completion_tokens_details.reasoning_tokens or 0) + (right.completion_tokens_details and right.completion_tokens_details.reasoning_tokens or 0)
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
Describe the feature or improvement you're requesting
https://github.com/openai/openai-python/blob/891e1c17b7fecbae34d1915ba90c15ddece807f9/src/openai/types/completion_usage.py#L27C1-L40C50
There is no reason for any of the values to be optional, since those are all counters. Rather than None, they should be zeros. This change will make tracking usage require much less client code.
Unnecessary optionals:
CompletionUsage.completion_tokens_details
CompletionUsage.prompt_tokens_details
PromptTokensDetails.audio_tokens
PromptTokensDetails.cached_tokens
CompletionTokensDetails.audio_tokens
CompletionTokensDetails.reasoning_tokens
Additional context
Currently, you need to write something like this for type checking to work (I don't think Mypy will work with code catching
AttributeError
):It should be possible and correct to just have:
The text was updated successfully, but these errors were encountered: