60s timeout from python sdk

I am trying to solve a math problem from a pdf file.
I discovered there is a 60s timeout when I call generate_content(), so when gemini needs to think for longer than 60s, it always raise
“httpx.RemoteProtocolError: Server disconnected without sending a response.”.
any one knows how to set a longer timeout? below is my script, thanks.

from google import genai

client = genai.Client(api_key=“api_key”)
pdf = client.files.upload(file=“F5L09_Trigonometry (2D).pdf”)

response = client.models.generate_content(
model= “gemini-2.5-pro-preview-05-06”,
contents= [“Solve question 9 of section 2”,pdf],
)
print(response.text)

------------------------------------------------------update-----------------------------------------------------------------
I tried run another script that dont require uploading a pdf and takes more than 60s to response, and same error exist.

from google.genai import types
from google import genai
model= “gemini-2.5-pro-preview-05-06”

client = genai.Client(api_key=api_key)

response = client.models.generate_content(
model= model,
# contents= [“Solve question 14 of section IV”,pdf],
contents=[
“”"
Consider the sequence $a_n$ defined as follows:
\begin{itemize}
\item $a_1 = 7$
\item For $n>1$, $a_n$ is the number formed by concatenating the digits of $a_{n-1}$ with the digits of $S_{n-1}$, where $S_{n-1}$ is the sum of the first $n-1$ terms of the sequence (i.e., $S_{n-1} = a_1 + a_2 + \dots + a_{n-1}$).
\end{itemize}

        Let $D(x)$ denote the digital root of a positive integer $x$. (The digital root is found by repeatedly summing the digits of a number until a single-digit number is obtained. For example, $D(123) = D(1+2+3) = D(6) = 6$, and $D(992) = D(9+9+2) = D(20) = D(2+0) = 2$).

        The sequence of digital roots $d_n = D(a_n)$ will eventually become periodic.
    """
]

)
print(response.text)

Hi @Lai_Steven, Could you please let me know if you are using Free tire or paid tire API. Thank You.

I am using paid tier api. and the script works fine if it response within 60s, I suspect it is the server side disconnecting.

hello .
Is there a solution to this? I’ve encountered the same problem @Kiran_Sai_Ramineni @Lai_Steven

Hi, I encountered a similar RemoteProtocolError: Server disconnected without sending a response issue when using the google.genai Python library, especially for requests that might take longer than 60 seconds. I saw this discussion and was wondering if you were able to resolve this issue? If so, could you please share the solution? Thank you!

Have you tried genai.client(api_key=xxx, http_options={‘timeout’: 600000})
this can lead to a 10 minutes timeout.

This magical number of 60 seconds seems to be the limit of network inactivity for many cloud worker hosting providers.

You are getting the network connection turned off on you where the script is running.

This link to streaming responses will help:

That approach didn’t work. I’ve already tried it.

I encountered the same issue. the issue is more severe this week (7th June 2025), it was better last week

tried timeout in both client and generate_content, still cant fix it.

Updating the model to gemini - 2.5 - pro - preview - 06 - 05 might be helpful.

I got the same issue here, by using “gemini-2.5-flash-preview-05-20”.
Setting longer http timeout doesn’t work either.

Finally, i found out it is actually issue from vpn. Issue solved after switching to another vpn provider.