Stream
Setstream: true to get server-sent events in OpenAI’s chat.completion.chunk format, ending with data: [DONE].
: keep-alive) every 15 seconds so proxies keep the connection open. SDKs ignore them. With stream_options.include_usage, the last chunk has an empty choices and the token counts.
If the request fails after the stream has started, the last event is an error in the same shape as other errors, with no [DONE] after it.
Without streaming
A plain request waits for the whole draft. If it is not ready within 30 seconds (a long draft, or a GPU that is still starting), the response starts with200 and sends spaces until the JSON body is ready. JSON parsers skip the leading whitespace. Because the status is already sent, a failure after that point comes back as a 200 whose body is an error object. Stream when that matters to you.
Set your client’s timeout to at least 10 minutes. The OpenAI SDKs default to 10 minutes.