Skip to content

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

@ChenChengKuan

Description

@ChenChengKuan

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

Metadata

Metadata

Assignees

Labels

component:apiIssues related to the API, not the SDK.type:bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions