Skip to content

Which timeout fires first when an AI model thinks for five minutes?

Unity Horizon7 min read

Not the SDK's. The Anthropic SDKs wait 600 seconds, Node's built-in fetch stops at 300, and an AWS NAT gateway resets an idle connection at 350.

The shortest default in the chain fires first, and it is never the one in the SDK. The Anthropic Python and TypeScript SDKs wait 600 seconds for a non-streaming reply, which is the most generous number in the stack and the one least likely to decide anything. Node's built-in fetch stops waiting for the response headers at 300. An AWS NAT gateway resets an idle connection at 350. nginx gives up at 60. Checked by Unity Horizon on 24 November 2026.

How long does one model call take at full effort?

Long enough to reach most of those numbers. Artificial Analysis measures Claude Opus 5.5 on Anthropic's own API and publishes the wait before the first answer token at each of its five effort levels. Read on 24 November 2026: 5.04 seconds at low, 13.33 at medium, 19.29 at high, 66.58 at xhigh, 325.12 at max.

A non-streaming Messages request sends nothing back until the message is finished. No headers, no partial body, no acknowledgement that the model is working on it. Put a 2,000-token answer at the 116 tokens a second the same page reports on top of the thinking, and a max-effort call holds a connection open for about 342 seconds without a byte on the wire.

The model is still thinking. The connection has already been reaped.

We measured the effort level against the token speed in Does a faster AI model make your agent finish sooner?. This piece is about what that wait runs into on the way out.

Which default fires first?

Whichever is smallest, which is rarely the one you configured. Put the same call behind nginx and the answer is 60 seconds, a tenth of the SDK's own deadline.

Layer Default deadline on one request Yours to change
nginx proxy_read_timeout 60s yes
AWS Application Load Balancer idle timeout 60s yes, idle_timeout.timeout_seconds
Node's built-in fetch headersTimeout 300s only through a custom dispatcher
Vercel function duration 300s on every plan, 800s maximum on Pro per function
Google Cloud Run request timeout 300s, 3,600s maximum yes
AWS NAT gateway idle timeout 350s no
Anthropic Python and TypeScript SDKs 600s read, 5s connect yes
LiteLLM request_timeout 6,000s yes

Anthropic names the hazard in prose and leaves out the number. Its errors page says that "some networks might drop idle connections after a variable period of time, which can cause the request to fail or time out without receiving a response from Anthropic". The variable period is 350 seconds on a default AWS private subnet, and the gateway "returns an RST packet to any resources behind the NAT gateway that attempt to continue the connection (it does not send a FIN packet)". Twenty-five seconds of headroom over a max-effort call, and that figure was measured on a short prompt rather than on an agent transcript.

What happens when the shortest default fires?

The request dies without a status code and the work carries on without it. We ran that on 24 November 2026: one local HTTP server holding a response for 310 seconds before it sends any headers, then returning 200, with four clients waiting on it at the same time under Node 22.23.5. Twenty lines, six minutes to repeat.

Client Result
fetch, nothing configured failed at 300.8s, TypeError: fetch failed, cause UND_ERR_HEADERS_TIMEOUT
fetch with AbortSignal.timeout(600_000) failed at 300.8s, same error
node:http request, no timeout set HTTP 200 at 310.0s
fetch, server sending a ping every 60s headers at 60.0s, body complete at 360.0s

Read the second row twice. A 600-second deadline is exactly what the Anthropic TypeScript SDK sets on every request, and it never got the chance to fire. The dispatcher underneath checks its own headersTimeout first, and 300 is the smaller number.

The last two rows are the fix and the reason it works. Node's older HTTP client has no header deadline, so the same request comes back 200 at 310 seconds. The streamed case was never idle: a ping every 60 seconds carried it to 360, well past the limit that killed the first two.

What does the client do after the timeout?

It sends the whole thing again, twice. In the Python SDK a timeout surfaces as APITimeoutError, which subclasses APIConnectionError, and the client retries every connection error, twice by default. The TypeScript SDK puts the consequence in the doc comment on its own timeout option: "Note that request timeouts are retried by default, so in a worst-case scenario you may wait much longer than this timeout before the promise succeeds or fails."

Three attempts at a 300-second cut is fifteen minutes of wall clock to produce one exception, plus backoff. Nothing tells the API that the client has gone, so the same answer gets generated three times and thrown away three times.

On a step that reads, that is tokens. On a step that writes, it is the problem we costed in How do you stop an AI agent from doing the same thing twice?, where nothing between the model and the tool deduplicates a side effect that already landed.

Why does the SDK refuse to send some requests at all?

It estimates the duration from max_tokens, at a rate it never states out loud. Both SDKs run the same arithmetic: one hour times max_tokens divided by 128,000. If that comes out above ten minutes the call never leaves the process, which puts the refusal at any non-streaming request with max_tokens over 21,333. The error reads "Streaming is required for operations that may take longer than 10 minutes."

Back the arithmetic out and the implied generation rate is 35.6 output tokens a second. Artificial Analysis measures 116 on the same model. The guard is three times pessimistic about typing and silent about thinking, which is where the five minutes went, so a 4,096-token request at max effort passes the check and then breaks every deadline in the table above.

The clients disagree about how long to wait. Each row below was read on 24 November 2026 on that project's default branch.

Client, with nothing configured Deadline on a non-streaming Messages call
anthropic Python and TypeScript 600s, and a refusal above max_tokens 21,333
langchain-anthropic none at all
LiteLLM 6,000s
Any JavaScript client riding Node's fetch 300s to the headers

The langchain-anthropic row is deliberate, and its own comment says so: "None is a meaningful value for Anthropic client and treated differently than not specifying the param at all." Passing None also means the client's timeout no longer matches the SDK default, which is the condition the 21,333-token guard is wrapped in, so that check never runs either. A call with no deadline and no guard leaves the decision to the transport, and the transport is the first table.

Who pays for this, and who never sees it?

Work with nobody in front of it pays nothing. A nightly queue, a reconciliation, a batch of invoices read before the office opens, a filing run at two in the morning, an export that has until Monday: hand those to the Message Batches API and poll for results, and no idle timer is ever armed. We built OFFSET, which files declarations directly to the ΑΑΔΕ portal, and a run that finishes before the accountant arrives does not care which of these numbers is the smallest.

The bill lands on the work that sits inside somebody's request. A model call behind a load balancer configured in 2023 by someone who has since left. A chat endpoint on a serverless function with a 300-second cap. An agent step at xhigh effort on a stack whose proxy was never told that a reply can take a minute. Those teams get a 504, and a user who presses the button again.

A ten-minute model call rests on one open TCP connection, a kernel keepalive probe, whatever default your proxy shipped with, and a retry policy nobody on the team wrote.

What do you change on Monday?

Stream, first. Anthropic's advice is to "consider using the streaming Messages API or Message Batches API for long-running requests, especially those over 10 minutes", and the SDKs will consume the stream and hand back the same final Message object a non-streaming call returns, so the shape of your code does not change. Headers arrive at the start of the wait instead of the end, and every idle timer in the chain sees traffic.

Then check the keepalive. The Python SDK's default httpx client sets SO_KEEPALIVE with a 60-second idle and a 60-second probe interval, which is what keeps a NAT gateway from reaping a quiet connection at 350 seconds. Pass your own HTTP client and you can lose that without noticing, because nothing fails until a request runs long.

Last, write down every number between your process and the API. Raise the ones you own.

Our 310-second server is a local process told to sleep, not a model under load. The test says what the transport does and nothing about what inference does. We have also not logged how often our own agent steps die on a timeout and come back as a retry, so that rate is not a number we hold.

If you are scoping an agent whose steps think for minutes at a time, our agentic AI systems page sets out how we scope one. What is the shortest deadline between your agent and the model, and who chose it?

Common questions

Why does a long AI model call fail after 300 seconds?

Because Node's built-in fetch stops waiting for the response headers at 300 seconds. The default comes from undici, which sets both headersTimeout and bodyTimeout to 300,000 ms, and a non-streaming model call sends no headers until the whole message is finished. The error is a TypeError with the cause HeadersTimeoutError and the code UND_ERR_HEADERS_TIMEOUT.

What is the default timeout on the Anthropic SDK?

Ten minutes. Both the Python and TypeScript SDKs set a 600 second read timeout with a 5 second connect timeout. On a non-streaming Messages call they also estimate the duration from max_tokens and refuse to send the request at all above 21,333 tokens, with the message that streaming is required for operations that may take longer than 10 minutes.

Does streaming stop an AI API request from timing out?

It moves the first bytes to the beginning of the wait instead of the end, which is what idle timers measure. A streamed response sends headers immediately and then event data, so every idle timer between your process and the API sees traffic on the connection. Anthropic recommends streaming or the Message Batches API for anything over 10 minutes.

Why does an AWS NAT gateway drop a long AI API request?

A connection through a NAT gateway that is idle for 350 seconds or more times out, and the gateway returns an RST packet rather than a FIN. The limit is not configurable. AWS recommends sending traffic over the connection or enabling TCP keepalive with a value below 350 seconds.

How many times does the Anthropic SDK retry a timed-out request?

Twice, for three attempts in total. A timeout surfaces as APITimeoutError. That class subclasses APIConnectionError, and the client retries every connection error it sees. The TypeScript SDK's own doc comment warns that request timeouts are retried by default, so in a worst case you wait much longer than the timeout you set.