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 …

I haven’t made any Progress on this. Any suggestion on what else I could try?

I have just started having a problem connecting to the google AI studio in n8n, although I’m not closer to fixing it I have some additional details. When I run a curl command from the server it works but from n8n or a simple javascript file on the server it fails.
After a little debugging found that the curl command was working via IPv6 and the javascript was using IPv4, switched to IP4 on the curl command and it fails, switch javasript to use IPv6 and it works. So seems to be a problem with IPv4 connections.

As my IP6 was working I’ve now managed to get my docker n8n instance to use IP6 to connect successfully to Google AI Studio API.

To check if you can connect via IPv6 from your VPS you can run:

curl -X GET -6 \
     -H "Content-Type: application/json" \
     "https://generativelanguage.googleapis.com/v1beta/models?key=AIzaSyBUKWx9PAgHefNRzwbhW9r5tzBXr_eFW6I" 

If this works then you can update your docker to use IPv6 first with the following environment variable set:

      - NODE_OPTIONS="--dns-result-order=ipv6first"
      - N8N_HOST="[::]"

Error in sub-node ‘Google Gemini Chat Model‘

I get this error message after connecting the Google Gemini Chat Model including Google AI Studio API Key.

Google Gemini requires at least one [dynamic parameter]

(Let AI specify tool parameters | n8n Docs) when using tools
Open node

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.