Streaming LLM tokens to a browser is easy to get 80% right and surprisingly easy to get the last 20% wrong. The naive version works on your machine and falls apart under a flaky connection or a fast model. Here is the production-grade setup I use, including the part most tutorials skip: what happens when the client cannot keep up with the stream.

The server: a ReadableStream over the SDK stream

In a Next.js route handler, you return a ReadableStream that pipes Claude's stream events out as Server-Sent Events:

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();