gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

[API Error: exception TypeError: fetch failed sending request]

Open King-skrs opened this issue 1 year ago • 16 comments

What happened?

│ Debug Console (ctrl+o to close) │ │ │ │ ... first 163 lines hidden ... │ │ address: '216.239.32.223', │ │ port: 443 │ │ }, │ │ Error: connect ETIMEDOUT 216.239.36.223:443 │ │ at createConnectionError (node:net:1652:14) │ │ at afterConnectMultiple (node:net:1682:16) { │ │ errno: -110, │ │ code: 'ETIMEDOUT', │ │ syscall: 'connect', │ │ address: '216.239.36.223', │ │ port: 443 │ │ } │ │ ] │ │ }

What did you expect to happen?

Fix it

Client information

About Gemini CLI │ │ │ │ CLI Version 0.1.9 │ │ Git Commit 8adc586 │ │ Model gemini-2.5-pro │ │ Sandbox gemini-cli-sandbox │ │ OS linux │ │ Auth Method gemini-api-key

Login information

API key

Anything else we need to know?

No response

King-skrs avatar Jul 07 '25 05:07 King-skrs

Looks like network issue. Can you give more context about this ? how to reproduce ?

Seydulla avatar Jul 07 '25 07:07 Seydulla

I logged in and had the first conversation, and then it prompted "✕ [API Error: exception TypeError: fetch failed sending request]"

[Windows 11] [nodejs 20.19.3] [Login method: APIKey]

ruijayfeng avatar Jul 07 '25 13:07 ruijayfeng

I am having the same issue.

│ Debug Console (ctrl+o to close) │ │ │ │ ℹ Authenticated via "gemini-api-key". │ │ ✖ Error flushing log events: AggregateError [ETIMEDOUT]: │ │ at internalConnectMultiple (node:net:1134:18) │ │ at afterConnectMultiple (node:net:1715:7) { │ │ code: 'ETIMEDOUT', │ │ [errors]: [ │ │ Error: connect ETIMEDOUT 216.239.34.223:443 │ │ at createConnectionError (node:net:1678:14) │ │ at Timeout.internalConnectMultipleTimeout (node:net:1737:38) │ │ at listOnTimeout (node:internal/timers:610:11) │ │ at process.processTimers (node:internal/timers:543:7) { │ │ errno: -60, │ │ code: 'ETIMEDOUT', │ │ syscall: 'connect', │ │ address: '216.239.34.223', │ │ port: 443 │ │ }, │ │ Error: connect ETIMEDOUT 216.239.32.223:443 │ │ at createConnectionError (node:net:1678:14) │ │ at Timeout.internalConnectMultipleTimeout (node:net:1737:38) │ │ at listOnTimeout (node:internal/timers:610:11) │ │ at process.processTimers (node:internal/timers:543:7) { │ │ errno: -60, │ │ code: 'ETIMEDOUT', │ │ syscall: 'connect', │ │ address: '216.239.32.223', │ │ port: 443 │ │ }, │ │ Error: connect ETIMEDOUT 216.239.38.223:443 │ │ at createConnectionError (node:net:1678:14) │ │ at Timeout.internalConnectMultipleTimeout (node:net:1737:38) │ │ at listOnTimeout (node:internal/timers:610:11) │ │ at process.processTimers (node:internal/timers:543:7) { │ │ errno: -60, │ │ code: 'ETIMEDOUT', │ │ syscall: 'connect', │ │ address: '216.239.38.223', │ │ port: 443 │ │ }, │ │ Error: connect ETIMEDOUT 216.239.36.223:443 │ │ at createConnectionError (node:net:1678:14) │ │ at afterConnectMultiple (node:net:1708:16) { │ │ errno: -60, │ │ code: 'ETIMEDOUT', │ │ syscall: 'connect', │ │ address: '216.239.36.223', │ │ port: 443 │ │ } │ │ ] │ │ } │

s0l0l0b0 avatar Jul 08 '25 04:07 s0l0l0b0

is this persisting issue for all of you? are you behind a network where google services might be blocked? (country level, school, firewall ....). What is the output of this: ping 216.239.36.223

Seydulla avatar Jul 08 '25 08:07 Seydulla

Environment variables set https_proxy and http_proxy to solve network problems, but new problems have arisen: ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Debug Console (ctrl+o to close) │ │ │ │ ⚠ Warning: Could not read directory /root: EACCES: permission denied, scandir '/root' │ │ ℹ Authenticated via "gemini-api-key". │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯

King-skrs avatar Jul 08 '25 10:07 King-skrs

in which folder you are currently at? And what is your prompt? @King-skrs

Seydulla avatar Jul 08 '25 10:07 Seydulla

It worked, I used docker exec -u root -it [your container ID or name] /bin/bash

King-skrs avatar Jul 08 '25 12:07 King-skrs

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY, apiVersion: "v1alpha", }); const config = { responseMimeType: "text/plain", temperature: 0.1, }; const model = "gemini-2.5-flash"; const contents = [ { role: "user", parts: [ { text: hi, }, ], }, ];

async function main() { const response = await ai.models.generateContent({ model, config, contents, }); console.log(response.text); }

main();

Hi all, I'm trying to run this code but it gives me error as below mcp-server-main/node_modules/@google/genai/dist/node/index.mjs:13059 throw new Error(exception ${e} sending request); ^

Error: exception TypeError: fetch failed sending request at mcp-server-main/node_modules/@google/genai/dist/node/index.mjs:13059:19 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Models.generateContent (mcp-server-main/node_modules/@google/genai/dist/node/index.mjs:14220:24) at async main (mcp-server-main/client.js:31:20)

Node.js v22.17.0 Please help me to fix this issue

gitsumitsingh avatar Jul 12 '25 06:07 gitsumitsingh

Same after upgrade to 0.1.14

escwxyz avatar Jul 26 '25 05:07 escwxyz

Found possible duplicate issues:

  • #1549: (#0.9376657009124756)
  • #4487: (#0.9045245320953293)

gsquared94 avatar Jul 30 '25 04:07 gsquared94

Hello. I also encountered the same problem, but I was able to solve it, so I'd like to share the details.

Specs

Windows 11 WSL2 Ubuntu 22.04.3 LTS gemini-cli 0.1.18

Cause

The PROXY_HTTP environment variable was set, and gemini-cli was trying to access via PROXY_HTTP.

Solution

unset HTTP_PROXY
unset http_proxy

ethiwoo avatar Aug 07 '25 05:08 ethiwoo

I'm using windows11, powershell and connect to network by proxy. I solve it by set the proxy enviroment. first close gemini cli, then set proxy, then start gemini

set the proxy

$env:http_proxy = "http://xxx.xxx.xxx.xxx:8080" $env:https_proxy = "http://xxx.xxx.xxx.xxx:8080"

unset the proxy $env:http_proxy = $null $env:https_proxy = $null

yangjianlin-c avatar Aug 10 '25 03:08 yangjianlin-c

I'm using windows11, powershell and connect to network by proxy. I solve it by set the proxy enviroment. first close gemini cli, then set proxy, then start gemini

set the proxy

$env:http_proxy = "http://xxx.xxx.xxx.xxx:8080" $env:https_proxy = "http://xxx.xxx.xxx.xxx:8080"

unset the proxy $env:http_proxy = $null $env:https_proxy = $null

I am having the same issue. Can use the ~/.gemini/.env file to persist variables, Seepersisting-environment-variables. This solved my problem, the file content is as follows:

GEMINI_API_KEY="API-KEY"
HTTP_PROXY="http://xxx.xxx.xxx.xxx:8080/"
http_proxy="http://xxx.xxx.xxx.xxx:8080/"
HTTPS_PROXY="http://xxx.xxx.xxx.xxx:8080/"
https_proxy="http://xxx.xxx.xxx.xxx:8080/"

AzureZee avatar Oct 28 '25 12:10 AzureZee

Hello! As part of our effort to keep our backlog manageable and focus on the most active issues, we are tidying up older reports.

It looks like this issue hasn't been active for a while, so we are closing it for now. However, if you are still experiencing this bug on the latest stable build, please feel free to comment on this issue or create a new one with updated details.

Thank you for your contribution!

gemini-cli[bot] avatar Dec 03 '25 21:12 gemini-cli[bot]

On Windows 10, I used the approach provided by @yangjianlin-c and worked. But set it in Gemini env file as mentioned by @AzureZee did not work.

hantsy avatar Mar 22 '26 05:03 hantsy