Troubleshooting

Fix Gemini API Timeouts: SDK Units, Model IDs and Proxy Limits

Eren Şimşir· Founder & Chief Technical Editor•
A woman interacts with a robotic hand through a fence under neon lights.
Photo by Yaroslav Shuraev via Pexels

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. Use 600_000 for ten minutes.
  • The model ID in my test was gemini-3.1-pro-preview; gemini-3.1-pro gave 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_timeout 60 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 sizeOutput capResult
8,307 tokens120 tokensFirst text after 3.1 s; whole call 3.1 s
42,189 tokens120 tokensNo visible text (the reasoning used the whole cap); call took 18.1 s
42,189 tokens, same prompt800 tokensFirst 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 tokensFirst 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.

Long-context call time by prompt size and output cap (seconds)Bar chart: an 8,307-token prompt with a 120-token output cap took 3.1 seconds; a 42,189-token prompt with a 120-token cap took 18.1 seconds and returned no visible text; the same 42,189-token prompt with an 800-token cap took 4.9 seconds.Long-context call time by prompt size and outputcap (seconds)8,307 tokens, cap1203.1 s42,189 tokens, cap120 (no text)18.1 s42,189 tokens, cap8004.9 s
Whole-call time from the results table above. With a small output cap the reasoning used the whole budget on the long prompt, so the call was slow and returned no visible text; raising the cap fixed it. One model and one run per row.

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:

ComponentDefaultCan you change it?
AWS Application Load Balancer, connection idle timeout60 secondsYes, 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 timeout29 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_timeout60 seconds eachYes. 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

  1. Set the timeout in milliseconds on the client, and make it longer than the slowest call you expect.
  2. Use the right model ID and confirm your key has quota for it; a 404 or a 429 with limit: 0 is not a timeout.
  3. 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.
  4. Retry 503 with backoff, and keep a fallback model for requests that must answer.
  5. 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

Frequently Asked Questions

What unit does the google-genai SDK use for the timeout?

Milliseconds. In SDK releases 1.39.1 and 2.29.0 the HttpOptions timeout field is described as "Timeout for the request in milliseconds" and the default is None. A value of 600.0 makes the client wait 0.6 seconds; 600000 waits ten minutes.

Does the Gemini Python SDK support gRPC?

Not in the releases I inspected (1.39.1 and 2.29.0): the package has no gRPC transport, option or environment variable. The word appears only in an error-type description. Use streaming and correct timeouts instead.

How long does a large prompt take on the Gemini API?

It varied in my runs on gemini-3.5-flash: about 3 seconds for 8,300 tokens, and between 4.9 and 18.1 seconds for the same 42,000-token prompt. A request of roughly 125,000 tokens (estimated) got HTTP 503 and then 429 instead. I could not test Gemini 3.1 Pro on a free-tier key.

Why do I get a 502 or 504 before my SDK timeout is reached?

A proxy in front of the API is cutting the connection. The documented defaults are 60 seconds for the AWS Application Load Balancer idle timeout, 29 seconds for the API Gateway REST integration timeout, and 60 seconds for nginx proxy_read_timeout. Raise the limit on every hop, and stream so the connection is not silent.

Why does the model gemini-3.1-pro return 404 or 429?

In my test gemini-3.1-pro returned 404 because the available ID is gemini-3.1-pro-preview. On a free-tier key that preview model returned 429 with limit 0 for requests and input tokens, which means the free tier has no allowance for it. That is a quota issue, not a timeout.