Three timeout fixes that fail when you check them
A common recipe for Gemini timeouts says: set the SDK timeout to 600, switch to gRPC, and call gemini-3.1-pro. I checked each of these. In the google-genai Python SDK the timeout is counted in milliseconds, so 600 means 0.6 seconds; the package has no gRPC transport; and the model ID gemini-3.1-pro returned 404. What does help is a correct timeout, a proxy that does not cut the connection first, and streaming.
HttpOptions(timeout=...)takes milliseconds. Use600_000for ten minutes.- The model ID in my test was
gemini-3.1-pro-preview;gemini-3.1-progave HTTP 404. - Defaults to check in front of the API: AWS ALB idle timeout 60 s, API Gateway (REST) integration timeout 29 s, nginx
proxy_read_timeout60 s. - Latency for large prompts varied a lot in my runs (the same 42,000-token prompt took 18 s once and under 5 s once), and a very large request got HTTP 503 "high demand".
What I checked, and how
I read the source of two releases of the Python SDK (google-genai 1.39.1 and 2.29.0), ran the SDK's own timeout helpers offline, called the Gemini API with a free-tier key on 9 October 2026 to measure latency and check model IDs, and read the AWS and nginx documentation for the proxy defaults. I could not run anything on Gemini 3.1 Pro, because the free tier has a quota of zero for it (the 429 message says limit: 0 for requests and for input tokens). The latency numbers below therefore come from gemini-3.5-flash, and nothing here is a measurement of Pro.
The timeout unit: 600 is 0.6 seconds
In both SDK releases the field description reads "Timeout for the request in milliseconds", and the default is None, so there is no 60-second SDK default to raise. The SDK code that converts the value says the same: it divides by 1000 before handing it to the HTTP client. I ran the conversion helpers directly:
timeout=600.0 -> client waits 0.6 s, header {'X-Server-Timeout': '1'}
timeout=600000 -> client waits 600.0 s, header {'X-Server-Timeout': '600'}
So a snippet that passes {'timeout': 600.0} and promises ten minutes gives you a client that gives up after 0.6 seconds and tells the server it will wait one second. If you suddenly see timeouts on every large call after "raising" the timeout, check the unit first. The corrected setup:
from google import genai
from google.genai import types
# timeout is in MILLISECONDS: 600_000 = 10 minutes
client = genai.Client(http_options=types.HttpOptions(timeout=600_000))
for chunk in client.models.generate_content_stream(
model="gemini-3.1-pro-preview", # "gemini-3.1-pro" returned HTTP 404
contents=long_prompt,
):
print(chunk.text or "", end="")
I verified that the client accepts these options and that generate_content_stream exists; I did not run this exact call against Pro, for the quota reason above.
There is no gRPC switch
I searched both SDK releases for a gRPC transport. The only mention of gRPC is in the description of an error type; there is no module, option or environment variable that changes the transport. If you read advice to "force gRPC" for the Gemini API in this SDK, there is nothing to set. Long calls are better served by streaming and by correct timeouts along the network path.
Model IDs and the free tier
A model-info request for gemini-3.1-pro returned 404 "Model is not found", while gemini-3.1-pro-preview exists. A generation request to the preview model on a free-tier key returned HTTP 429 with limit: 0 on both the request count and the daily input-token count. So a 429 on this model is not rate limiting that will clear; the free tier simply has no allowance for it. Another model, gemini-2.5-flash, answered "no longer available to new users" in the same session. Check the model list for your key before you debug timeouts.
How long large prompts took
I streamed a request to gemini-3.5-flash built from real README text and noted when the first text arrived. The model also spends tokens on internal reasoning, which counts toward the output cap.
| Prompt size | Output cap | Result |
|---|---|---|
| 8,307 tokens | 120 tokens | First text after 3.1 s; whole call 3.1 s |
| 42,189 tokens | 120 tokens | No visible text (the reasoning used the whole cap); call took 18.1 s |
| 42,189 tokens, same prompt | 800 tokens | First text after 4.8 s; whole call 4.9 s |
| about 125,000 tokens (450,000 characters; estimated from the ratio of the smaller run) | 120, then 800 tokens | First try: HTTP 503 "model is currently experiencing high demand". Second try: HTTP 429, the free-tier quota |
Two points from this. The same 42,000-token prompt took 18 s in one run and under 5 s in another, and the two runs also differed in the output cap, so I cannot say what caused the gap; plan for variation instead of one fixed number. And the largest request did not time out: it failed with a 503 that no timeout setting would have helped. Retrying 503 with backoff belongs in the same fix list as raising timeouts.
Proxies and gateways cut the connection first
The limits in front of the API are often lower than the SDK's. From the vendors' documentation:
| Component | Default | Can you change it? |
|---|---|---|
| AWS Application Load Balancer, connection idle timeout | 60 seconds | Yes, 1 to 4000 seconds. AWS advises sending at least one byte before the timeout elapses; HTTP/2 PING frames do not reset it. |
| AWS API Gateway REST API, integration timeout | 29 seconds (minimum 50 ms) | Yes for Regional and private APIs, which may need a lower account throttle quota; not for edge-optimized APIs |
nginx, proxy_read_timeout and proxy_send_timeout | 60 seconds each | Yes. The read timeout counts between two successive reads, not the whole response. |
Two corrections to common advice follow from this. The 29-second API Gateway limit is a default that can be raised for Regional and private REST APIs, not a hard wall. And because the ALB and nginx timers measure silence, a streamed response that keeps sending data does not hit them the way a silent, buffered call does. nginx has proxy_buffering on by default, so if you stream through it, check that your chunks are not being held back; I did not test that.
What to do
- Set the timeout in milliseconds on the client, and make it longer than the slowest call you expect.
- Use the right model ID and confirm your key has quota for it; a 404 or a 429 with
limit: 0is not a timeout. - Stream long calls so that proxies see traffic, and raise the idle timeouts of every hop to at least the slowest expected first-byte time.
- Retry 503 with backoff, and keep a fallback model for requests that must answer.
- Cache large static context only on a paid tier: on the free tier, creating an explicit cache returned 429 in my prompt-caching test.
What I did not test
I did not call Gemini 3.1 Pro, run requests through a real ALB, API Gateway or nginx, measure the Node.js SDK, or time Vertex AI. The proxy values are quoted from the vendors' documentation as of the date above and may change.
Sources and Further Reading
- google-genai on PyPI — SDK releases 1.39.1 and 2.29.0 inspected
- Edit attributes for your Application Load Balancer — AWS
- Quotas for configuring and running a REST API in API Gateway — AWS
- ngx_http_proxy_module — nginx
- Rate limits — Google AI for Developers
