Major types are not exposed in openai.types ChatCompletion, Response, ResponseUsage
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [x] This is an issue with the Python library
Describe the bug
I cannot use strict typing when library is used because not all types are avaliable in the typing.
Examples:
openai.types.CompletionUsage -> Exists
openai.types.ChatCompletion
openai.types.Response
openai.types.ResponseUsage
As a workaround next code can be used but it's not optimal:
resp.class.name == "ChatCompletion":
To Reproduce
import openai.types.ChatCompletion has no type in IDE
Code snippets
import openai.types.ChatCompletion
func test(a:openai.types.ChatCompletion ):
pass
OS
win
Python version
3.11
Library version
openai 2.1.0
The code is not wrong, but the library export is incomplete. Possible fixes:
Use a specific import (from openai.types.chat import ChatCompletion)
Or update to the latest version (pip install --upgrade openai), because the type exports are gradually being expanded.
from openai.types.chat import ChatCompletion
def test(a: ChatCompletion): pass
Thanks for raising this! These types are available in their resource namespaces: from openai.types.chat import ChatCompletion and from openai.types.responses import Response, ResponseUsage. I verified these imports; no class-name workaround is needed. Closing as answered.