generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

Error:400 The request's total referenced files bytes are too large to be read when analyzing large image (>20MB) with File API

Open ChenChengKuan opened this issue 10 months ago • 7 comments

Description of the bug:

Hello I followed the official document of handling large image payload (>20MB) but still got the 400 invalid error with the code:

MODEL_NAME = gemini-2.0-flash-001
client = genai.Client(api_key="My api key)
my_file = client.files.upload(file='some_image.png')

client = genai.Client(api_key="My api key)
response = client.models.generate_content(
    model=MODEL_NAME, 
    contents=[
        'describe the image', 
        my_file
    ]
)

The error message:

ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': "The request's total referenced files bytes are too large to be read", 'status': 'INVALID_ARGUMENT'}}

The file size is around 36MB. What I notice is that it is totally fine with image size >=20MB but below 30MB. It seems to me that 30MB is the limit, which is different from what official doc says that per file size can be as large as 2GB

Things I have checked

  • client.file.list() only contain one file I upload which satisfies 20GB in total and 2GB / file
  • genai python sdk version =1.3.0

Could you help me to resolve this?

Actual vs expected behavior:

Should not get 400 error

Any other information you'd like to share?

I am in the paid API tier not free plan

ChenChengKuan avatar Mar 01 '25 16:03 ChenChengKuan

Hi @ChenChengKuan,

I checked from my end with images >=30mb, it is giving the same error with 2.0-flash models. I think there is some limit/issue with 2.0-flash models.

I checked with 1.5 models and "gemini-2.0-pro-exp-02-05" it's working fine.

According to me, you can change the model as of now.

I will follow up on this (2.0-flash) model with the internal team.

Thanks.

gmKeshari avatar Mar 03 '25 09:03 gmKeshari

Thanks for the report, I think @junyanxu is looking into it.

MarkDaoust avatar Mar 03 '25 22:03 MarkDaoust

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] avatar Mar 18 '25 02:03 github-actions[bot]

I have the same problem but with a 67 GB size PDF and the gemini-1.5-pro model

AbdielPerezB avatar Apr 07 '25 18:04 AbdielPerezB

Any update on this? cant upload any pdf bigger than 30mb

markwitt1 avatar Apr 14 '25 11:04 markwitt1

Please update, if the issue has been resolved, faced the same thing

akashpatel7997 avatar May 20 '25 09:05 akashpatel7997

Hello, same problem here

Guz-TsTech avatar Nov 05 '25 19:11 Guz-TsTech