Unable to use gpt-4o with stream enabled as True

Jude Samson, Samuel 20 Reputation points
2025-01-27T15:02:32.1566667+00:00

Iam using the following code snippet

deployment_name = "gpt-4o"

# Function to stream OpenAI response
def generate_stream(prompt):
    response = client.completions.create(
        model=deployment_name,
        prompt=prompt,
        temperature=1,
        max_tokens=200,
        top_p=0.5,
        frequency_penalty=0,
        presence_penalty=0,
        stream=True
    )

I am getting the following error :

raise self._make_status_error_from_response(err.response) from None

openai.BadRequestError: Error code: 400 - {'error': {'code': 'OperationNotSupported', 'message': 'The completion operation does not work with the specified model, gpt-4o. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'}}

127.0.0.1 - - [27/Jan/2025 20:26:31] "GET /stream?prompt=what%20is%202+2 HTTP/1.1" 200 -

Any thoughts if I am doing this wrong, please correct me if I am wrong, does gpt-4o support streaming?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saideep Anchuri 9,425 Reputation points Microsoft External Staff Moderator
    2025-01-28T04:34:00.41+00:00

    Hi Jude Samson, Samuel

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    I understand that you are encountering an issue, your syntax of using chat completion seems wrong. It should be client.chat.completions,Instead of client.completetion for 1.X.X version and client.chatcompletion for 0.x.x version.

    please refer below documentation: chat-completion-models

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    Thank You.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jude Samson, Samuel 20 Reputation points
    2025-01-28T07:36:35.9266667+00:00

    Thanks @Saideep Anchuri
    this worked

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.