openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Major types are not exposed in openai.types ChatCompletion, Response, ResponseUsage

Open ievgennaida opened this issue 1 year ago • 2 comments

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

ievgennaida avatar Oct 05 '25 16:10 ievgennaida

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

nomiveritas avatar Oct 15 '25 06:10 nomiveritas

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.

marcuswood-oai avatar Sep 06 '26 20:09 marcuswood-oai