I’m having this problem with the community version of n8n. When installing self-hosted, and n8n needs to go through a proxy, I get this error: It doesn’t connect to the Google Gemini API. How can I fix it?

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent: fetch failed

“fetch failed” behind a proxy usually isn’t a proxy misconfiguration. It’s that the request never went through the proxy at all.

The Gemini/LangChain nodes use Node’s built-in fetch (undici), and undici does not read HTTP_PROXY / HTTPS_PROXY environment variables. The HTTP Request node uses a different client that does honour them, which is why on the same instance that node often works while the AI nodes fail. So setting the proxy env vars looks right and changes nothing for Gemini.

What I’d check, in order:

  1. Prove where it breaks. Inside the container: docker exec -it n8n sh, then

  2. node -e “fetch(‘https://generativelanguage.googleapis.com’).then(r=>console.log(r.status)).catch(e=>console.log(‘ERR’, e.cause||e))”

  3. If that fails the same way, the problem is at the Node runtime level, not in n8n’s config.

  4. Make undici use the proxy. Newer Node versions expose NODE_USE_ENV_PROXY=1 for exactly this (with HTTPS_PROXY set). Check your image’s Node version with node -v. On older Node it doesn’t exist, and env vars alone will not work.

  5. If your proxy does TLS interception (most corporate ones do), this is a certificate failure hiding behind a generic “fetch failed”. Mount the proxy’s root CA into the container and set NODE_EXTRA_CA_CERTS=/path/to/ca.crt. The e.cause in step 1 will show it.

  6. Workaround if you’re blocked today: skip the Gemini node and call the API with an HTTP Request node instead, which respects the proxy. Uglier, but it runs now.

Paste the output of step 1 (especially e.cause) and it should be obvious which of these it is.

1 Like