Skip to content

Commit 4466056

Browse files
docs(streaming): explain the HTTP/1.1-only drain
1 parent a2753c7 commit 4466056

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎src/openai/_streaming.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def __stream__(self) -> Iterator[_T]:
6969
try:
7070
for sse in iterator:
7171
if sse.data.startswith("[DONE]"):
72+
# HTTP/1.1 needs the remaining body consumed for connection reuse.
73+
# HTTP/2 can close this stream and keep the connection, so draining
74+
# it would add unnecessary latency after [DONE].
7275
if response.http_version == "HTTP/1.1":
7376
drain_response(response)
7477
break
@@ -186,6 +189,9 @@ async def __stream__(self) -> AsyncIterator[_T]:
186189
try:
187190
async for sse in iterator:
188191
if sse.data.startswith("[DONE]"):
192+
# HTTP/1.1 needs the remaining body consumed for connection reuse.
193+
# HTTP/2 can close this stream and keep the connection, so draining
194+
# it would add unnecessary latency after [DONE].
189195
if response.http_version == "HTTP/1.1":
190196
await drain_response_async(response)
191197
break

0 commit comments

Comments
 (0)