Streaming LLM Responses in Django + React: The Full Implementation A developer detailed a full-stack implementation of streaming LLM responses in Django and React, using Server-Sent Events (SSE) instead of WebSockets for one-directional communication. The approach includes a Django StreamingHttpResponse generator that yields tokens from the Anthropic API, with critical headers like X-Accel-Buffering: no to prevent Nginx buffering. The client-side uses the EventSource API in React to consume the stream, improving user experience by showing responses incrementally rather than waiting for the full output. The first time we added an AI feature to a client's Django app, we did it the naive way: POST request, wait, get a response, render it. It worked. It also felt broken. Users stared at a spinner for 8 seconds, then got a wall of text. They stopped using it. Not because the AI was wrong — it wasn't — but because waiting for the full response before showing anything felt laggy in a way that ChatGPT had trained them out of tolerating. Streaming solves this. It's not just a UX nicety — users start reading before the response finishes, they feel like something is happening, and they're more likely to catch when the AI goes off the rails early and stop it. We've implemented streaming across a handful of production Django+React applications now. Here's the full stack: server-side, client-side, and the edge cases that'll catch you if you skip the boring infrastructure bits. WebSockets are overkill for LLM streaming. The communication is one-directional — the server sends chunks, the client reads them. Server-Sent Events SSE is the right primitive here: it's HTTP, it works through proxies, and Django supports it without any extra infrastructure. The core view uses Django's StreamingHttpResponse with a generator that yields tokens as they arrive from the LLM API: python import json import anthropic from django.http import StreamingHttpResponse from django.views.decorators.csrf import csrf exempt from django.views.decorators.http import require POST client = anthropic.Anthropic def stream llm response prompt: str, system: str = "" : """Generator that yields SSE-formatted chunks from Claude.""" with client.messages.stream model="claude-opus-4-5", max tokens=1024, system=system, messages= {"role": "user", "content": prompt} , as stream: for text chunk in stream.text stream: SSE format: data: