Thanks but this doesnt work for react native (expo) as you can’t define region headers like these, it ignores it
create a backend service (as a proxy) and deploy it in US
I have also started to get these errors recently as well:
{
"name": "Error",
"message": "[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent: fetch failed",
"stack": "TypeError: fetch failed
at node:internal/deps/undici/undici:13502:13
at async makeRequest (/usr/src/app/node_modules/@google/generative-ai/dist/index.js:397:20)
at async generateContent (/usr/src/app/node_modules/@google/generative-ai/dist/index.js:867:22)
at async ChatSession.sendMessage (/usr/src/app/node_modules/@google/generative-ai/dist/index.js:1205:9)"
}
The strange thing is that they happen randomly. I am sure I am not hitting the rate limits or any other networking restrictions.
What worked for me—I’ve wrapped Gemini’s calls (like sendMessage
and generateContent
) with this simple withRetry
function: withRetry.js · GitHub
I mean this solved the problem, right? But, I do not like how the recent development of Gemini goes in terms of quality.
As of now, I have already got 3 layers of these duct tape patches to make simple API calls work.
Can’t believe they just removed the model in the EU, without any notification and explanation. We’re using this API on our production environment, since there’s nothing better and it’s very useful for our customers.
Luckily for me, I use Vercel and with some simple proxy-magic / preferedRegion settings, I managed to get it to work. It’s far from ideal and feels like a timebomb to go off again. It’s the Perfect example why open source matters. This behavior is not acceptable, especially for a ‘developer friendly’ player like Google. They just removed the entire API, without explanation for the entire EU and somehow think that’s ok? What a joke.
This decision made it not a good practice to offer Google API’s within our production environment if they can just decide to remove acces without any notice.
Models available specifically in Vertex AI (production)
NEXT_PUBLIC_VERTEX_AVAILABLE_MODELS=gemini-2.0-flash-live-preview-04-09
they disabled it for EU and UK “Modified by moderator”