Skip to content
Agent Month

How to fix: request timeout on large or streaming responses

Last verified: June 2026· long streaming generations

Where this shows up

long streaming generations

How it shows up

The same root cause surfaces in a few different ways. If any of these match, you're in the right place.

  • Short prompts succeed and long ones fail — the boundary tracks output length, not input.
  • The request fails at a suspiciously round number of seconds (30, 60, 120), which points at a fixed timeout rather than the model.
  • The failure is a client-side or proxy timeout, not an error from the provider — you never receive a response body.
  • It works locally but times out behind a load balancer, CDN, or API gateway.
  • A streaming request dies mid-response after a period of silence, typically while the model is reasoning before emitting tokens.

Diagnose it first

Confirm which cause you actually have before changing anything — most wasted time here comes from fixing the wrong one.

CheckWhat the result tells you
Establish whether the timeout is client-side, proxy, or provider.A provider timeout returns a structured error body. A client or proxy timeout returns a transport error with no body — that distinction tells you which timeout to raise.
Time a failing request and compare it to your configured timeout.Failing consistently at the same round number means a fixed limit is cutting the request off. Varying failure times point at the model or network instead.
Check the timeout units in your SDK config.Some SDKs take milliseconds and others seconds. A value of 60 meaning 60ms rather than 60s produces immediate, confusing timeouts on every non-trivial request.
Test the same request with streaming enabled.If streaming succeeds where a blocking call failed, the cause is time-to-last-token exceeding a limit, not a broken request.
Look at every hop between your client and the provider.Load balancers, reverse proxies, and API gateways impose their own idle and total-request timeouts that are usually lower than the one you configured in the SDK.

The fix

  1. 1Switch to streaming for any request that may produce long output (e.g. max_tokens above ~16K).
  2. 2Use the SDK’s stream helper and collect the final message rather than awaiting one big response.
  3. 3Confirm your client timeout units — some SDKs use milliseconds, others seconds — and raise the timeout if needed.
  4. 4For very long agentic turns, stream progress to the user so the connection stays active and the UX reflects work in progress.

Provider-specific behaviour

The error means roughly the same thing everywhere, but each provider signals it differently.

Reasoning models
Models that reason before answering can be silent for a long stretch before the first token appears. An idle-timeout policy measuring time-between-bytes will kill these connections even though the request is healthy — the connection is idle by design during reasoning.
Proxies and load balancers
Default idle timeouts on common reverse proxies and cloud load balancers are frequently around 60 seconds, well below a long generation. Raising the SDK timeout alone changes nothing, because the connection is severed upstream of your code.
Serverless platforms
Serverless functions have a hard maximum execution duration that you cannot exceed regardless of client configuration. Long generations need either streaming with an appropriate response mode, or a background job that the client polls.
Batch endpoints
Where latency is not user-facing, provider batch APIs sidestep request timeouts entirely by design — work is submitted and collected asynchronously rather than held open on a connection.

What doesn't work

Common fixes for this error that look right and aren't.

  • Raising the SDK timeout and nothing else.

    If a proxy or load balancer between you and the provider has a lower limit, it terminates the connection first. The SDK setting only binds when it is the smallest timeout in the chain.

  • Retrying the timed-out request unchanged.

    The same request takes the same time and hits the same limit, so it fails identically — while you pay for the tokens generated on every attempt before it was cut off.

  • Lowering max_tokens to force the response under the limit.

    This does prevent the timeout, but by truncating output mid-answer. You have traded a visible error for silent, hard-to-detect quality loss.

Prevent it

Default to streaming for anything with large output, and design timeouts and progress UX around minutes-long turns on frontier models.

Common variations and related errors

You'll usually hit this same root cause under a few different names. Same fix.

  • "request timeout"
  • "ETIMEDOUT"
  • "upstream timeout"
  • "gateway timeout (504)"
  • "context deadline exceeded"
  • fetch failed: timeout

Code: drop-in retry helper

A minimal typescript helper that handles the most common version of this error. Copy, paste, adjust the policy to your traffic.

// Stream long generations instead of waiting for the full response.
import OpenAI from 'openai';
const client = new OpenAI();

const stream = await client.responses.create({
  model: 'gpt-4o',
  input: prompt,
  max_output_tokens: 16000,
  stream: true,
});
for await (const event of stream) {
  if (event.type === 'response.output_text.delta') {
    process.stdout.write(event.delta);
  }
}

Frequently asked questions

What causes “request timeout on large or streaming responses”?

A non-streaming request with a high `max_tokens` exceeds the SDK/HTTP timeout before the full response returns.

How do I prevent “request timeout on large or streaming responses” from recurring?

Default to streaming for anything with large output, and design timeouts and progress UX around minutes-long turns on frontier models.

Does streaming actually make the model faster?

No — total generation time is unchanged. Streaming changes which timeout applies: instead of waiting for time-to-last-token on a blocking request, you receive bytes continuously, so connections governed by idle timeouts stay alive and users see output from the first token. The work takes just as long; it stops being invisible.

Why does my streaming request still time out?

Usually one of two causes. Either a reasoning model is silent long enough before its first token to trip an idle timeout, or something in the chain is buffering the response — a proxy that does not flush incrementally converts your stream back into a single blocking response, reintroducing the exact timeout you were avoiding.

What timeout should I set for LLM requests?

Set it per route from measured behaviour rather than picking one global number. Take the p99 latency for that route, add meaningful headroom, and make sure every hop in the path allows at least that long. Routes with very different output lengths should not share a timeout — one value will always be too tight for one of them and too loose for the other.