Gemini API read from GCS bucket

I am using Gemini Dev API and trying to get a simple response to an audio file that I am uploading to GCS

Code is

from google import genai
from google.genai import types as google_genai_types # Alias for its types module


def aistudio(GEMINI_API_KEY, filename):

    client = genai.Client(
        api_key=GEMINI_API_KEY
    )

    destination_blob_name = f"audio_uploads/{os.path.basename(filename)}"
    gcs_file_uri = upload_to_gcs(GCS_BUCKET_NAME, filename, destination_blob_name)

    audio_file_part = google_genai_types.Part.from_uri(file_uri=gcs_file_uri, mime_type=audio_mime_type)

    response = client.models.generate_content_stream( 
        model=MODEL_ID,
        contents=["Analyze this audio", audio_file_part],
    )


    for chunk in response:
        if hasattr(chunk, 'text') and chunk.text: 
            print(chunk.text, end="")

I keep geting API error: 400 INVALID_ARGUMENT. {‘error’: {‘code’: 400, ‘message’: 'Unsupported file uri: gs://…

Bucket is public, can view it from any device anywhere, API key has no restrictions.

so the docs arent very clear on this but to access a bucket you need to enable vertex ai and not use the ai studio api key approach. you need to enable vertex ai in the gcp cloud console and in js you do

geminiInstance = new GoogleGenAI({
vertexai: true,
project: GCP.PROJECT,
location: GCP.LOCATION,
});

you dont need the bucket public to access it with gemini. That error message the sdk generates is so unhelpful. took me a couple hours to figure out what it needed.