Stream_options not working for image_url contents

It seems the new feature stream_options is not working for image_url inputs

stream_options is not giving the usage metric if the chat content type as image_url , is that a limitation or a bug ? - It giving usage as null but if i remove the image_url its started working

Posted the same query as a comment on the original announcement

Welcome to the OpenAI dev community, @jayendran.

I am unable to find instances of it not working as expected in my tests.

Here’s the code that I used to test it:

from openai import OpenAI

client = OpenAI()

conve = [
    {
        "role": "system",
        "content": "You are a helpful assistant.",
    },
    {
        "role": "user",
        "content": [
            {
                "type": "image_url",
                "image_url": {
                    "url": f"https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Erizo_de_mar_violáceo_%28Sphaerechinus_granularis%29%2C_Madeira%2C_Portugal%2C_2019-05-31%2C_DD_40.jpg/490px-Erizo_de_mar_violáceo_%28Sphaerechinus_granularis%29%2C_Madeira%2C_Portugal%2C_2019-05-31%2C_DD_40.jpg",
                    "detail": "low",
                },
            },
            {"type": "text", "text": "What is in this image?"},
        ],
    },
]

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=conve,
    stream=True,
    stream_options={"include_usage": True},
)

for chunk in response:
    if chunk.choices:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].delta.content, end="")

    # Handle the case where choices is empty but usage data is present
    elif chunk.usage:
        print("\n\n", chunk.usage)

Can you share your code which can be used to reproduce an instance of it not working?

2 Likes

I am experiencing exactly the same behavior. Might be related to using Microsoft Azure AI API.

1 Like

Hi @sps this looks like an issue with azure openai

1 Like

Looks like its started working now on Azure Openai instances :slight_smile: