A short request succeeds, but a long streaming generation times out.
Why this happens
The client’s timeout expired before the server completed the request or the network delivered its response. Long generations and default short timeouts make this more likely.
Answer 1: Increase the request timeout deliberately
import httpx
from openai import OpenAI
client = OpenAI(timeout=httpx.Timeout(60.0))
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Write an essay"}],
stream=True
)
