google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://www.npmjs.com/package/@google/generative-ai
Apache License 2.0
740 stars 161 forks source link

Get 400 Error, but only when deployed on firebase functions. Works in localhost - Same code #239

Open AndreJLouw opened 2 months ago

AndreJLouw commented 2 months ago

Description of the bug:

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent: [400 Bad Request] User location is not supported for the API use. at handleResponseNotOk (/workspace/node_modules/@google/generative-ai/dist/index.js:403:11)

Actual vs expected behavior:

Completion of request

Any other information you'd like to share?

This worked before, and suddenly just stopped. The API key is on the paid account.

Firebase location: us-central1

gitton commented 2 months ago

Getting same error

devberkay commented 2 months ago

Same setup and same problem.

ruuuruiya commented 2 months ago

Same error here, us-central1

BernardasJuzumas commented 2 months ago

same. Firebase function, deployed in us-central1. Tried redeploying to eu-west - same. It worked well several hrs ago. Any change in api?

romainwurtz commented 2 months ago

Same issue on AppEngine with us-west2

ak--47 commented 2 months ago

same us-central1 [400 Bad Request] User location is not supported for the API use. ... running inside cloud function (gen 2)

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [400 Bad Request] User location is not supported for the API use.
    at handleResponseNotOk (file:///workspace/node_modules/@google/generative-ai/dist/index.mjs:401:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeRequest (file:///workspace/node_modules/@google/generative-ai/dist/index.mjs:374:9)
    at async generateContent (file:///workspace/node_modules/@google/generative-ai/dist/index.mjs:813:22)
GanderwaD commented 2 months ago

same problem

robertedjones commented 2 months ago

Same here, @hsubox76 any insight on what the problem is?

egisz commented 2 months ago

Same here, us-central1, functions v2. Switched function to us-west1 - works. But this is not solution if functions are called from app :(

BernardasJuzumas commented 2 months ago

Found another discussion here: https://discuss.ai.google.dev/t/generate-object-error-user-location-is-not-supported-for-the-api-use/37440/21 Could possibly be related to gemini api geoblocking ips of firebase/gcp cloud function calls that originate from "us-central1". The only real solution here is to deploy to several regions simultaneously and implement a failover if one region fails.

romainwurtz commented 2 months ago

Issue fixed! https://discuss.ai.google.dev/t/generate-object-error-user-location-is-not-supported-for-the-api-use/37440/37