---
title: "Discussion on \"How to Stream LLM Responses With FastAPI and SSE\" | Hashnode"
description: "Discussion on \"How to Stream LLM Responses With FastAPI and SSE\". A FastAPI SSE endpoint, a Next.js reader, a Stop button that really stops, and proxy buffering fixes."
url: "https://hashnode.com/posts/how-to-stream-llm-responses-with-fastapi-and-sse/6affd345e044a3d2701896a1"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to Stream LLM Responses With FastAPI and SSE](https://boilershelf.hashnode.dev/how-to-stream-llm-responses-with-fastapi-and-sse?utm_source=hashnode&utm_medium=feed)

A FastAPI SSE endpoint, a Next.js reader, a Stop button that really stops, and proxy buffering fixes.

Nov 20 · 6 min read · boilershelf.hashnode.dev  
Read the article

-   [#fastapi](https://hashnode.com/tag/fastapi)
-   [#python](https://hashnode.com/tag/python)
-   [#nextjs](https://hashnode.com/tag/nextjs)
-   [#llm](https://hashnode.com/tag/llm)
-   [#ai](https://hashnode.com/tag/ai)

## Written by

[BoilerShelf](https://hashnode.com/@boilershelf)

@boilershelf

  
[View profile](https://hashnode.com/@boilershelf)

Source code kits for RAG, document AI and AI SaaS.

BoilerShelf sells source code kits for RAG chatbots, document AI, AI agents and AI SaaS. One-time payment, full source code, commercial license.

## Responses 2

Markdown supported · ⌘↵ to post

[AI Developer](https://hashnode.com/@lycore)

[Nov 20](https://hashnode.com/posts/how-to-stream-llm-responses-with-fastapi-and-sse/6affd345e044a3d2701896a1/comment/6afff171c92f649a8016a3f0)

One edge worth testing on the Stop path: with SSE the server usually only learns the client is gone when a write fails or a disconnect poll fires, so a stop during a long quiet stretch (slow first token, tool call) may keep the upstream provider call alive until the next heartbeat. Do you rely on the keepalive interval to surface the disconnect, or poll for it separately? Also, since you emit named events, adding an id per token event would let the client resume with Last-Event-ID after a dropped connection instead of restarting the generation.

[BoilerShelf](https://hashnode.com/@boilershelf)

[Nov 24](https://hashnode.com/posts/how-to-stream-llm-responses-with-fastapi-and-sse/6affd345e044a3d2701896a1/comment/6afff171c92f649a8016a3f0#reply-6b05021502705fa7e50fd931)

[AI Developer](https://hashnode.com/@lycore "AI Developer") Thanks for flagging this! The example relies on the response stack’s cancellation handling, with no separate disconnect polling. Quiet-period cancellation needs testing through the deployed proxy. Agreed on resume support—event IDs would also need server-side replay and explicit reconnect logic for this fetch client.
