Gemini-2.5-flash api cannot process video input

image

On the website, I can get the response from the Gemini-2.5-flash model. But when I use the API service, this error appears.

My request code is as follows:

def call_gemini_api(video_file_name, prompt: str, api_key: str):
    client = genai.Client(api_key=api_key)

    video_bytes = open(video_file_name, 'rb').read()

    response = client.models.generate_content(
        # model='models/gemini-2.0-flash',
        model="gemini-2.5-flash-preview-04-17",
        contents=types.Content(
            parts=[
                types.Part(
                    inline_data=types.Blob(data=video_bytes, mime_type='video/mp4')
                ),
                types.Part(text=prompt)
            ]
        )
    )

    return response

Same issue with gemini-2.5-flash-preview.
Works if using gemini-2.0-flash.

Hi, there seems to be an issue when we try to pass video data inline in 2.5-flash-preview. Have you tried using the file API? It works as expected.
Below is the sample code.

myfile = client.files.upload(file="sample.mp4")
response = client.models.generate_content(
    model="gemini-2.5-flash-preview-04-17", contents=[myfile, "Summarize this video."]
)

print(response.text)

I have tried your method and the error is :
google.genai.errors.ClientError: 400 FAILED_PRECONDITION. {‘error’: {‘code’: 400, ‘message’: ‘The File q91mn19efz1u is not in an ACTIVE state and usage is not allowed.’, ‘status’: ‘FAILED_PRECONDITION’}}

Seems like you are trying to process the video file while it is in processing state, please ensure the video file is active before starting the processing

video_file = client.files.upload(file="video.mp4")
video_file.state.name

This is my code:

client = genai.Client(api_key=api_key)

myfile = client.files.upload(file="ideos_resampled-00115180-Scene-071.mp4")
response = client.models.generate_content(
        model="gemini-2.5-flash-preview-04-17", contents=[myfile, "Summarize this video. Then create a quiz with an answer key based on the information in this video."]
    )

Thank you so much for your reply!

You can run below code:

client = genai.Client(api_key=api_key)
myfile = client.files.upload(file="ideos_resampled-00115180-Scene-071.mp4")

while myfile.state == "PROCESSING":
      print('Waiting for video to be processed.')
      time.sleep(5)
      video_file = client.files.get(name=myfile.name)

response = client.models.generate_content(
        model="gemini-2.5-flash-preview-04-17", contents=[myfile, "Summarize this video. Then create a quiz with an answer key based on the information in this video."]
    )

It works!! Thank you so much !!