Google Cloud Storage files in buckets not available/accepted by Gemini client via Python SDK

In an effort to get around the slow uploads, I noticed that this documentation says we should be able to pass a file_uri for inference.

However, I’ve tried everything I can think of and cannot get this working.
I have my GCS bucket in the same project.
I have given Storage Legacy Bucket Reader permissions to the same service account that is also credentialed for the genai api.

The error I get is as follows:

google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {‘error’: {‘code’: 400, ‘message’: ‘Invalid or unsupported file uri: gs://list-magic/incomplete.png’, ‘status’: ‘INVALID_ARGUMENT’}}

But I should note that the same error is given if I pass a file to it that doesn’t exist.

Thank you in advice for any pointers.

Hi @Yann_Gagnon,

If you have authenticated with your project_id and location then you can use file_uri. If you are using gemini developer api key then if your GCS bucket url is public, you can use inline data for files <20mb and File API for files >20mb data. Please see this doc.