Incorrect Image Token Calculation Results in Overcharging

I am reporting a critical bug in the token calculation for images with the new Gemini 2.0 models. For some image sizes, the number of tokens being charged is 4 to 8 times higher than what is stated in the official documentation.

The documentation specifies:

Gemini 2.0 Flash and Gemini 2.5 Flash/Pro: 258 tokens if both dimensions <= 384 pixels. Larger images are tiled into 768x768 pixel tiles, each costing 258 tokens. Token calculation

Based on this, an image with dimensions of 384x128 should be billed as 258 tokens. However, my API calls using an image of this size are consuming 1032 prompt tokens.

This issue is present in both the Google AI Studio API and Vertex AI.

Affected Models:

  • Gemini 2.0 Flash
  • Gemini 2.0 Flash Lite

Problematic Image Sizes and Observed Token Counts:

  • 384x128 → 1032 tokens
  • 1x128 → 3354 tokens
  • 384x64-> 1806 tokens

This problem resulted in a large number of users being charged far more than they used.

Test Script:
Below is the Python code I used to reproduce the error.

import os
from PIL import Image
from google import genai
from dotenv import load_dotenv

load_dotenv()

api_key = os.environ.get("GOOGLE_API_KEY")
client = genai.Client(api_key=api_key)

model = "gemini-2.0-flash"
image = Image.new("RGB", (384, 128), "black")
token_res = client.models.count_tokens(model=model, contents=image)
count_token = token_res.total_tokens
print(f"Token count for {image.size[0]}x{image.size[1]} image: {count_token}")

res = client.models.generate_content(model=model, contents=image)
total_input_token = res.usage_metadata.prompt_token_count

print(f"Total input tokens: {total_input_token}")
print(res.usage_metadata.to_json_dict())

Output:
The output clearly shows the discrepancy. The count_tokens function returns the correct amount, but the actual charge during generation is incorrect.

Token count for 384x128 image: 259
Total input tokens: 1033
{..., 'prompt_tokens_details': [... ,{'modality': 'IMAGE', 'token_count': 1032}], ...}

Hello,

Thank you for raising this issue. I was able to reproduce it and have escalated the matter to the concerned team.

In the meantime, I believe this issue does not occur with gemini-2.5-flash and gemini-2.5-pro. Could you please try using these models and let me know if they work correctly for you?

1 Like

Hello,

Thank you for your help.

I can confirm that the issue does not occur with gemini-2.5-flash and gemini-2.5-pro. However, due to cost considerations, my project will be using gemini-2.0-flash-lite.

Could you please help me keep track of the status of this issue?

Thanks again for your assistance.

Any updates on this?

In My Case the every image prompt token counted 258 single. no matter what image pixel size is. my topic.

Hello,

Apologies for the delayed response. Could you please try running the gemini-2.5-flash-lite model? It has similar pricing as gemini-2.0-flash-lite , and the issue you are experiencing is resolved when using this model. Kindly test it on your end and let us know if it meets your requirements.

Thank you for your patience.