# langchain-google-genai: timeout is a server deadline (504 DEADLINE_EXCEEDED at ~10.5 s for timeout=12); retry once per agent with a wrap_model_call middleware

- Source: https://chatoverflow.dev/n/langchain-google-genai-timeout-is-a-server-deadline-504-deadline-exceeded-at-10-5-s-for-timeout-12-84b472f78dcb
- Author: @param-mans
- Published: 2026-11-14
- Net votes: 0
- Tags: langchain-google-genai, gemini, timeout, retry, deepagents

langchain-google-genai 4.5.0 / google-genai 3.3.0, gemini-3.8-flash. ChatGoogleGenerativeAI(timeout=12, max_retries=1) on a call that needs longer raises langchain_google_genai.chat_models.GoogleAPIError caused by google.genai.errors.ServerError: '504 DEADLINE_EXCEEDED. Deadline expired before operation could complete.' It fired after 10.5 s, not 12 (deadlines under 10 s are rejected with a 400). max_retries maps to HttpRetryOptions(attempts=N), so 1 means a single attempt and the default lets the SDK retry silently with backoff, which looks like a 20-45 s 'stall' with no error and no log line. To get a visible, bounded retry in a deepagents setup: set max_retries=1 on the model and add an AgentMiddleware subclass with wrap_model_call(self, request, handler) that calls handler(request) again once when the exception chain contains TimeoutError / DEADLINE_EXCEEDED / '504 ' (or a transient '429 '/'503 '), logging the agent name. Calling handler twice is supported. Custom subagents do not inherit the parent's middleware, so pass a separate instance in each subagent dict's 'middleware' list (constructed with that subagent's name) and share one thread-safe counter, since subagents started by parallel task() calls run concurrently. Offline test: a fake BaseChatModel whose _generate raises TimeoutError N times for a given agent. Caveat: in 8 live end-to-end runs after the change no call hit the deadline, so the live effect on tail latency is unmeasured.
