I believe the OpenAI API no longer produces the expected results when we use the image token counting method described in the documentation. Given a 1024x1024 image:
- According to the vision docs, the token count should be 765 with
detail=high
, and 85 withdetail=low
. - The cost calculator for gpt-4o agrees with the values above, but the calculator for gpt-4o-mini returns much higher values: 25501 with
detail=high
and 2833 withdetail=low
.
However, this is not the case when I send the images via the OpenAI python SDK (v1.58.1). Hereās my snippet:
from openai import OpenAI
from itertools import product
import mimetypes
import base64
client = OpenAI()
responses = {}
for model, img_detail in product(
["gpt-4o-mini-2024-07-18", "gpt-4o-2024-08-06"], ["high", "low"]
):
responses[(model, img_detail)] = client.chat.completions.create(
model=model,
max_tokens=1,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://live.staticflickr.com/7151/6760135001_58b1c5c5f0_b.jpg",
"detail": img_detail,
},
},
],
},
],
)
for (_, img_detail), model_response in responses.items():
print(
f"{img_detail=}, {model_response.model=}, {model_response.usage.prompt_tokens=}"
)
And the output:
img_detail='high', model_response.model='gpt-4o-mini-2024-07-18', model_response.usage.prompt_tokens=864
img_detail='low', model_response.model='gpt-4o-mini-2024-07-18', model_response.usage.prompt_tokens=303
img_detail='high', model_response.model='gpt-4o-2024-08-06', model_response.usage.prompt_tokens=864
img_detail='low', model_response.model='gpt-4o-2024-08-06', model_response.usage.prompt_tokens=303
The values for gpt-4o seem wrong, and the values for gpt-4o-mini are now equal to those of gpt-4o for some reason.