Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cannot access Google's Gemini API from a Cloudflare Worker

In a Cloudflare Pages Function / Worker, we have tried accessing Google's Gemini API using both direct requests to:

https://generativelanguage.googleapis.com/...

and through the Cloudflare AI gateway:

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/...

Both methods above result in the following error being returned from the Google Gemini API:

{
  "error": {
    "code": 400,
    "message": "User location is not supported for the API use.",
    "status": "FAILED_PRECONDITION"
  }
}

Upon investigation, this error is supposedly returned when the user is not in a supported location listed here:

https://ai.google.dev/gemini-api/docs/available-regions

However, we ARE in a supported location (Melbourne, Australia). When we access the Gemini API from our local dev env (even if we access it via the Cloudflare AI Gateway), the Gemini API works correctly.

Anyone know what is going on?

0 REPLIES 0