mimeType parameter with value application/json, which is not supported

Why it works in AI Studio, but locally with pythons genai i got error like
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Unable to submit request because it has a mimeType parameter with value application/json, which is not supported. Update the mimeType and try again. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}}

How it comes ? Same code !

@Anton_Chernov ,

i see that you are trying to analyze or work on a base64 image data , am i correct in assuming that?

if so , “mime_type” should be “image/jpeg”

you could see the usage in the following code.

response = client.models.generate_content(
    model='gemini-2.0-flash',
    contents=[
      types.Part.from_bytes(
        data=base64.b64decode(b64img),
        mime_type='image/jpeg',
      ),
      'please analyze this image and tell me in detail what you observe.'
    ]
  )

please check the examples in the following documentation.

It’s JSON attached not image, and Gemini AI studio with gemini-2.5-flash-preview.. accepts it, as well as it’s working with gemini-2.0-flash with AI studio, which generated this code on the screenshot. But same code locally doesn’t work with gemini-2.0-flash, raises error I described.

@Anton_Chernov,

if you are sending json data , you can directly include it as a part of the contents. please check the below.

contents=[
        base64.b64decode(b64json),
        'please analyze this input json and tell me in detail what you observe.'
    ]

this should be able give you the required response.

let me know if that works. :slight_smile:

Yeah thanks, I know workaround. I also can json.dump it as a string. But why AI studio suggests not correct code. That is the question :exclamation_question_mark:)