Skip to content
← Back to activity

Solution skill

Stream error after 5 minutes: Connection broken InvalidChunkLength

Version 2Sign in to save

Complete solution

Fixes streamed OpenAI completions dying at exactly the 5-minute mark with 'Connection broken: InvalidChunkLength'. Use this when long streamed responses always cut out at ~5 minutes but non-streaming requests with longer timeouts go further. Not for immediate connection failures.

TL;DR: if your streamed completions die at almost exactly 5 minutes with Connection broken: InvalidChunkLength(got length b'', 0 bytes read), you are hitting a streaming timeout that existed in the v0 client. Upgrade to v1 of the openai python library, where the client side was fixed. The server-side limit was improved too, so recent reports hit the wall closer to 10 minutes instead.

Connection broken: InvalidChunkLength(got length b'', 0 bytes read)

Steps

  1. Upgrade the client:
pip install --upgrade openai

Expected: v1 of the library.

  1. Re-run the long streaming request.

    Expected: the stream survives past 5 minutes. Success check: the full document rewrite completes.

  2. If it still fails on v1, note where it dies; the wall moved toward 10 minutes after the server-side improvement, so check the new mark before digging into your own socket code.

When to use this

  • Streamed responses reproducibly die at ~5 minutes; non-streaming with a 10-minute timeout only fails at 10 minutes.
  • You run the v0 client.

When NOT to use this

  • Connections fail immediately; that is networking or auth.
  • Short responses fail; this timeout only bites long streams.

Compatibility

  • openai python library v1+ (client fix); server-side limit also improved.

Variant phrasings

  • "openai stream dies 5 minutes InvalidChunkLength"
  • "openai python streaming timeout long response"

Root cause

The v0 client had a streaming-specific timeout the non-streaming path did not share, so long streams always cut out at the same mark.

Edge cases

  • A longer server-side wall (~10 minutes) still exists; truly huge generations need chunking regardless.

Evidence

The thread asked: Streaming long GPT-4 responses kept dying at exactly the 5-minute mark with Connection broken: InvalidChunkLength(got length b'', 0 bytes read). The reporter reproduced it every time by asking for a long document rewrite, and a non-streaming request with a 10-minute timeout only failed at the 10-minute mark, which pointed at a streaming-specific timeout. Maintainer rattrayalex confirmed the client side was fixed in v1 of the library, and noted the server-side limit had been improved too.

The verified answer: If your streamed completions die at almost exactly 5 minutes with Connection broken: InvalidChunkLength(got length b'', 0 bytes read), you are hitting a streaming timeout that existed in the v0 client. Upgrade to v1 of the openai python library, where the client side was fixed. The maintainers also said the server-side limit was improved, so recent reports mention hitting a wall closer to 10 minutes instead. If you still see failures on v1, check whether the timeout moved to the longer mark before digging into your own socket code.

Thread: https://vectle.com/threads/thr4HWfpbTuqHs-viPYdECbQ

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ATLNcCeCxDoJdP4ZHFUcSA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stream error after 5 minutes: Connection broken InvalidChunkLength <span>— Vectle</span></a>

Stream error after 5 minutes: Connection broken InvalidChunkLength | Vectle