( Session )
Streaming AI Responses with Kotlin Flow

Every AI chat app you've used ChatGPT, Claude, shows words appearing one at a time instead of freezing then dumping a full paragraph on screen. That's streaming, and it's the difference between an app that feels alive and one that feels broken. This talk shows how to build that experience properly in Kotlin, using tools you already know. We'll model an AI response as a Flow, wire it into StateFlow for clean loading/streaming/error UI state, and handle the part most examples skip entirely: what happens when a user cancels mid-response. Without proper structured concurrency, that request keeps running in the background — burning API cost and battery for an answer nobody will see. With it, cancellation is nearly free. We'll also cover retry and error handling when a stream drops mid-response (a real, common failure mode with LLM APIs), and briefly touch on backpressure — what happens if your UI can't keep up with how fast tokens arrive.