Use client.stream() with iter_lines() / aiter_lines() to process SSE events in real-time.
Async Streaming (Chat Completions)
The .stream() context manager keeps the connection open. The response body is NOT read into memory — it's processed line by line. Always use timeout=None for the read timeout when streaming.
The async streaming pattern
async with client.stream("POST", url, headers=h, json=body) as response: opens the stream. Inside the block, async for line in response.aiter_lines(): yields SSE frames as they arrive. The framing (data: prefix, empty-line separator, [DONE] terminator) is yours to parse.
The single biggest mistake is reaching for response.aread() or response.json() inside the streaming block — both collect the whole body, defeating the streaming. Either iterate or accept that you're not really streaming.