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
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?