Unexpected keyword argument 'stream_options'

Name: openai
Version: 1.52.1
Summary: The official Python library for the openai API
Home-page:
Author:
Author-email: OpenAI support@openai.com
License:
Location: /usr/local/lib/python3.10/dist-packages
Requires: anyio, distro, httpx, jiter, pydantic, sniffio, tqdm, typing-extensions
Required-by: litellm, lmms_eval

mycode:
response = self.__client.chat.completions.create(
model=self.__model_name,
messages=oai_messages,
temperature=temperature,
top_p=top_p,
stream=True,
stream_options={“include_usage”: True},
max_tokens=max_tokens,
)

then
File “/usr/local/lib/python3.10/dist-packages/openai/_utils/_utils.py”, line 272, in wrapper
msg = f"Missing required argument: {quote(missing[0])}"
TypeError: Completions.create() got an unexpected keyword argument ‘stream_options’

1 Like

This simply means that the argument “stream_options” is not an expected parameter to pass.

Try removing it from your completion creation.

So your code would be as follows:

response = self.__client.chat.completions.create(
model=self.__model_name,
messages=oai_messages,
temperature=temperature,
top_p=top_p,
stream=True,
max_tokens=max_tokens,
)

Good luck!

That simply means that the validation, introduced at version 1.26 and performed by the actual API SDK version being employed, is not available in your version number actually in use as you expect.

Add to the start of your script to see the source of the problem:

from openai import __version__ as oai_version
if int(oai_version.split(".")[0])<1 or (
  int(oai_version.split(".")[0])<2 and int(oai_version.split(".")[1])<26
  ):
    raise ValueError(f"OpenAI version {oai_version} too low for streamed usage report")
2 Likes

https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options

“stream_options” is valid in document

it could be due to the problem that @arata mentioned.

try printing your version of the openai library.

if it is too low, you can always upgrade it. :blush:

Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

from openai import version as oai_version
oai_version
‘1.52.1’

thank you, i know the reason: i failed to update openai sdk

2 Likes

Feel free to mark one of the messages as the solution so that if another user reads this post, he gets a quick answer on the fix. :smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.