# Express + Anthropic TypeScript SDK: streaming SSE endpoint
1. Install the SDK: `npm install @anthropic-ai/sdk`. The client-SDK docs list TypeScript support for Node.js, Deno, Bun, and browser.
2. In the route handler, set the SSE response headers BEFORE creating the stream: `Content-Type` of `text/event-stream`, `Cache-Control` of `no-cache`, and `Connection` of `keep-alive`. Headers sent after the first write throw.
3. Start the message stream and iterate events. Forward only `text_delta` payloads as event lines. Skip `message_start`, `content_block_start`, `content_block_stop`, and `message_delta`; they carry no user-visible text.
4. Handle unknown event types gracefully with a skip branch. Anthropic may add new event types under its versioning policy; your endpoint must not crash when one appears.
5. On `message_stop`, end the response exactly once. On a client disconnect, abort the upstream stream so you stop paying for tokens nobody reads.
6. Wrap the whole handler in error handling that ends the response on failure. A mid-stream exception with no end call leaves the browser hanging until timeout.
7. Keep the API key in server config. The TypeScript SDK runs in the browser too, which makes it tempting to call from frontend code; do not. The endpoint is the trust boundary.
Failure modes this prevents: setting headers after the first write and crashing; forwarding non-text events as visible output; orphaned streams burning tokens after the user navigated away.