Using gemini media prompt with storage file via firebase gives cors error

I can only generate textcontent if i pass the media parts as base64, using a storrage path pointing to my firebase storage files gives a cors error. I’ve allowed cors origin all for the specific bucket.

gcloud storage buckets describe gs://my-firebase-bucket.appspot.com --format="default(cors_config)"

cors_config:
- maxAgeSeconds: 3600
  method:
  - GET
  origin:
  - '*'

the file parts im sending:

[
    {
        "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "gs://my-firebase-bucket.appspot.com/videos/test.mp4"
        }
    }
]

The errors i see in the console:

Access to fetch at 'https://firebaseml.googleapis.com/v2beta/projects/my-firebase/locations/us-central1/publishers/google/models/gemini-1.5-flash:generateContent' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
functionBeingCalled.ts:34 


POST https://firebaseml.googleapis.com/v2beta/projects/my-firebase/locations/us-central1/publishers/google/models/gemini-1.5-flash:generateContent net::ERR_FAILED 502 (Bad Gateway)

It doesnt matter if i try from a deployed firebase site or localhost. Does anyone have any idea how to solve this?

What library are you using and can we see the code you’re trying to use that is causing this error? Despite the error, this doesn’t seem like it is really a CORS error - but rather there’s an underlying issue that is causing this. The error suggests it has to do with calling the API.

To use a Google Cloud Storage bucket for the fileUri, you need to do two things:

  • You must be using Vertex AI. You can’t use the AI Studio API. (But I’m not sure which platform “firebaseml” is using.)
  • The bucket must be in the same project you make the calls to the Gemini API from.

Ah okay. I’m using the firebase vertex ai package

Sort of a quick and dirty example below

import { getVertexAI } from "firebase/vertexai-preview";

getGenerativeModel(getVertexAI(firebaseApp), {
    model: "gemini-1.5-flash",
    systemInstruction: systemPrompt
  }).generateContent([parts])

The bucket is setup using firebase, it’s all setup and using firebase so im not sure why it wouldnt work in that case

1 Like