400 'Invalid or unsupported file uri

Hey, I have been trying to " Provide a list of non function call parts", as per the Python google-genai 1.7.0 documentation, using gemini-2.0-flash, something like:

contents = [
types.Part.from_text(‘What is this image about?’),
types.Part.from_uri(
file_uri: ‘gs://generativeai-downloads/images/scones.jpg’,
mime_type: ‘image/jpeg’,
)
]

but I am getting a 400:

{‘error’: {‘code’: 400, ‘message’: ‘Invalid or unsupported file uri: gs://motorway-condition-centre-vehicle-issues-images/vehicle_images/bd53e001-cc58-43dd-be09-6ecd2ed587a3.jpg’, ‘status’: ‘INVALID_ARGUMENT’}})

I have already checked all obvious potential configs that could cause this issue, like:

  • Incorrect Cloud Storage URI
  • Permissions Issue
  • Incorrect MIME Type
  • VPC Service Controls
  • File Size Limits
  • Invalid characters

What else could be causing this issue?

Hi @dedecun , Welcome to the forum.

Just confirming: Are you initializing the client using API key or OAuth using (Vertex AI) ??

API Key.

client = genai.Client(api_key=Config.GEMINI_API_KEY)

1 Like

You need to initialize the client using OAuth (Vertex AI) in order for the code to work.

client = genai.Client(
    vertexai=True, project='your_project', location='us-central1',
    http_options={'api_version': 'v1'}
)

If you are using the API, you can follow the documentation for vision capabilities.

But if I can make this kind of usage work on AI Studio, using API Keys, why not in this case? Also, I used to start it through Vertex, but I was having other issues in my app (like 409 errors with Thinking Models) that were fixed by changing to API Keys. I don’t understand why some features work starting with API Keys and others with Vertex, this makes things quite difficult to understand and work with, not to say very unproductive.

You are right, there should be clearer documentation on what works with the Gemini API vs Vertex AI. We have noted your point, and agree that better guidance would help improve the developer experience.

Thank you