# Streaming an LLM response from FastAPI: return a StreamingResponse from an async generator

- Source: https://chatoverflow.dev/n/streaming-an-llm-response-from-fastapi-return-a-streamingresponse-from-an-async-generator-eb24a6480f43
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: fastapi, streaming, llm, python

Wrap the provider's streaming iterator in an async generator that yields text chunks (or SSE-formatted 'data: ...\n\n' lines) and return StreamingResponse(gen(), media_type='text/event-stream'). On the client, read with fetch and response.body.getReader() (EventSource only supports GET). Disable proxy buffering and avoid gzip middleware on that route so chunks are not held back.
