Strange problems connecting to Google AI Studio

I am having problems connecting to Google AI Studio via n8n. I encounter a variety of different issues depending on how I attempt to access it. I host n8n on a Hetzner server, located in Germany. I am also physically located in Germany.

I have no issues connecting to and accessing Google AI Studio (specifically, Gemini Flash) directly. I have a curl command that I run locally with my API key, and it functions correctly.

However, if I use an HTTP node in n8n and select ‘import from curl’, I get the following error:

User location is not supported for the API use.
Error details

 From HTTP Request
Error code

400

Full message

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

{ "body": { "contents": [ { "parts": [ { "text": "Explain how AI works" } ] } ] }, "headers": { "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7" }, "method": "POST", "uri": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent", "gzip": true, "rejectUnauthorized": true, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "qs": { "key": "AIzaSyAKhDtp5285bVprtjqGwr0G9dFBx9108Ps" }, "encoding": null, "json": false, "useStream": true }
 Other info
Item Index

0

Node type

n8n-nodes-base.httpRequest

Node version

4.2 (Latest)

n8n version

1.75.2 (Self Hosted)

Time

27/01/2025, 12:18:30

Stack trace

NodeApiError: Bad request - please check your parameters at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:525:33) at processTicksAndRejections (node:internal/process/task_queues:95:5) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:632:19) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:890:51 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1224:20`Preformatted text`
type or paste code here

This is very weird… ‘User location is not supported for the API use.’ I am not using a location parameter, and I am located in Germany. Moreover, the server is also hosted in Germany. I have verified that Germany is a supported location.

I previously encountered some other issues that I can no longer reproduce. I was told that my API key was not working, but the project ID in the error message did not match the project associated with the API key, nor any of my project IDs in general. I revoked the API keys and changed some other things; now I am not getting that error anymore.

I would really appreciate some help, or a direction, that I can focus my efforts on. Thanks.

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

I had the API key in the logs. I revoked it.

Okay if i run the same curl on my server it also works. It just does not work in n8n.

I checked the ip location of my domain (US) and subdomain (Germany). Both should work with gemini.

I have the same problem:

Error in sub-node ‘Google Gemini Chat Model‘

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse: [400 Bad Request] User location is not supported for the API use.

My server is also hosted on Hetzner but in Finland.

Still haven’t found a solution to this …