Streaming Claude Tokens from Bedrock with Node.js 22: SSE Made Simple A developer has published a guide showing how to stream Claude tokens from Amazon Bedrock to the browser using Node.js 22's native fetch API and Server-Sent Events (SSE). The approach wires a Lambda-backed SSE endpoint that pushes tokens to the client as they are generated, avoiding the perceived latency of waiting for a full completion. The guide emphasizes setting the stream flag to true in the Bedrock request payload and reusing the BedrockRuntimeClient across Lambda invocations. Developers keep asking why LLM responses feel sluggish when they have to wait for the whole answer. With Bedrock’s streaming mode and Node 22’s native fetch, you can push tokens to the browser the moment they’re generated. This guide shows you how to wire a Lambda‑backed SSE endpoint in minutes. When you ask a large language model LLM like Claude a question, the model doesn’t write the whole paragraph in one go. It creates tokens —tiny pieces of text such as a word or punctuation—one after another. Think of a token stream like a faucet: water tokens drips out continuously instead of a bucket dumping all at once. If your application waits for the bucket, the user sees a blank screen for a few seconds, then a sudden flash of the complete answer. That pause hurts perceived performance, especially in chat‑like interfaces where users expect an immediate “typing…” indicator. Streaming lets you: In plain English: Streaming is like watching a movie as it’s filmed, rather than waiting for the whole film to be edited before the lights come up. Bedrock will only send a token‑by‑token stream when you set the stream flag to true in the request payload. Forgetting this flag makes the service behave like a classic HTTP request, returning the entire completion in a single JSON object. The downstream Server‑Sent Events SSE logic then never sees any incremental data, and the browser sits idle. Before you can ask Claude for tokens, you need a client —a small piece of code that knows how to talk to the Bedrock Runtime API. The official AWS SDK for JavaScript provides @aws-sdk/client-bedrock-runtime . Installing it is straightforward: npm install @aws-sdk/client-bedrock-runtime The SDK handles signing the request with your AWS credentials, retrying transient failures, and exposing a clean TypeScript interface. It saves you from manually crafting the Authorization header for every call. js // src/bedrockClient.ts import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime"; / Create a Bedrock client that will be reused across Lambda invocations. Re‑using the client avoids the overhead of creating a new HTTP connection each time. / export const bedrockClient = new BedrockRuntimeClient { // Region where your Bedrock model lives. Change if you deployed to a different region. region: "us-east-1", // Optional: increase timeout if you expect long generations. requestHandler: undefined, // default NodeHttpHandler is fine for most cases } ; Tip: Keep the client in a module‑level variable outside the handler so that AWS re‑uses the underlying TCP socket across cold‑starts. ThrottlingException . Node 22 ships with the fetch API built‑in, just like browsers. This means you can call Bedrock with a streaming request without pulling in a third‑party HTTP library. ReadableStream objects, which work nicely with the SSE format we’ll send to the browser. The body must be a JSON string that tells Bedrock which model to use, what prompt to send, and that we want a stream: { "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0", "prompt": "Explain why streaming matters in a chat UI.", "maxTokens": 512, "temperature": 0.7, "stream": true } In plain English: stream: true is the “turn on the faucet” switch. js // src/handler.ts import { bedrockClient } from "./bedrockClient"; import { InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"; / Calls Claude via Bedrock using Node's native fetch. Returns a ReadableStream of raw bytes that we will transform to SSE later. / async function callClaudeStream prompt: string : Promise