Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Stream Claude Responses from Amazon Bedrock with Node.js 22 and SSE

Bedrock streams structured events to Node.js; your server must translate selected Claude text deltas into browser-facing SSE and handle failures at both layers.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To stream Claude output from Amazon Bedrock to a browser, consume Bedrock’s structured event stream in your Node.js server, then translate text deltas into Server-Sent Events (SSE). These are two separate transports: AWS’s JavaScript example documents the Bedrock side, while the server-to-browser SSE layer is application code you must implement and validate for your deployment.

How the two streaming layers fit together

Your server makes a streaming request to Bedrock using the AWS SDK. Bedrock returns structured events, not a plain sequence of text tokens. The server can select text deltas from those events and send them to the browser as SSE messages. The browser-facing stream is therefore a translation layer; it is not Bedrock’s event stream passed through unchanged.

As an Amazon Associate I earn from qualifying purchases.

Layer What it carries What to verify
Bedrock to Node.js Structured events from ConverseStream, including text deltas and lifecycle or other content events. Confirm that the selected model supports streaming in the region you will use. AWS recommends checking GetFoundationModel and its responseStreamingSupported value. AWS ConverseStream API reference
Node.js to browser SSE messages that your application creates from events it chooses to expose. Implement and test the HTTP response framing, headers, disconnect handling, and any proxy or hosting behavior for your Node.js and browser setup.

Consume Claude’s Bedrock stream with the JavaScript SDK

AWS’s JavaScript SDK v3 example imports BedrockRuntimeClient and ConverseStreamCommand from @aws-sdk/client-bedrock-runtime, sends the command with client.send(), and reads response.stream using asynchronous iteration. The following illustrates that documented upstream pattern; it is not a complete Node.js HTTP server or browser-ready SSE implementation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { BedrockRuntimeClient, ConverseStreamCommand } from "@aws-sdk/client-bedrock-runtime";

const client = new BedrockRuntimeClient({ region: "us-east-1" });

const command = new ConverseStreamCommand({
  modelId: "anthropic.claude-3-haiku-20240307-v1:0",
  messages: [
    {
      role: "user",
      content: [{ text: "Explain how SSE works in one paragraph." }],
    },
  ],
  inferenceConfig: {
    maxTokens: 512,
    temperature: 0.5,
    topP: 0.9,
  },
});

try {
  const response = await client.send(command);

  for await (const item of response.stream) {
    const text = item.contentBlockDelta?.delta?.text;
    if (text !== undefined) {
      // Pass this text to your application's downstream SSE layer.
      process.stdout.write(text);
    }
  }
} catch (error) {
  // Handle request-time and stream-consumption failures here.
  console.error("Bedrock ConverseStream failed:", error);
}

The model ID and region in this sample are examples, not universal defaults. Availability and streaming support depend on the model and region you choose. The example’s maxTokens, temperature, and topP are also sample inference settings, not requirements or recommended values for every application. See AWS’s JavaScript SDK v3 Bedrock Runtime examples and ConverseStream API reference.

Handle events by type, not as plain text

A Bedrock response stream can contain message-start, content-block, message-stop, and metadata events. Content blocks can include start, delta, and stop events; a delta may carry text, reasoning, or partial tool-use JSON. The code above extracts only the text field from a content-block delta. That is suitable only when your application intends to expose text and does not need to process other event types.

  • Text deltas: Select contentBlockDelta.delta.text when present and pass it to your chosen downstream representation.
  • Tool use: A content block may identify tool use and stream partial JSON. Do not display those fragments as ordinary prose or assume each fragment is a complete JSON value.
  • Reasoning and other data: Deltas may carry non-text content. Decide explicitly what your application should do with each event shape.
  • Lifecycle and metadata: Message and content-block boundaries, stops, and metadata are part of the structured stream; they are not user-facing text tokens.

AWS describes the event sequence and content-block behavior in its Converse API inference guide. Build event handling around the shapes your application supports rather than assuming every yielded item contains displayable text.

Map selected deltas to SSE in your Node.js application

The SDK example establishes how to read Bedrock events; it does not specify how to frame an HTTP response for browser EventSource clients. Treat SSE as a separate server implementation. For each selected text delta, your server must encode and write an SSE message according to the current Node.js and browser documentation, and it must finish or signal the client appropriately when the Bedrock stream ends or fails.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before deploying, validate the details for your stack: response headers and event framing, behavior when the client disconnects, and whether a reverse proxy or hosting platform buffers the response. Do not assume that receiving chunks from Bedrock guarantees they will arrive incrementally in the browser. The code above deliberately writes to standard output and should not be mistaken for a tested SSE route or browser client.

Handle failures at request time and during streaming

Failure can occur while sending the command or after the stream has begun. AWS documents response-stream errors including internal server errors, model stream errors, model timeouts, service unavailability, throttling, and validation errors. See the ResponseStream API reference.

  • Wrap both client.send(command) and asynchronous stream iteration in error handling, as the example does.
  • If an upstream error happens after you have started the downstream response, stop producing normal content and communicate an application-appropriate failure to the client. Do not leave the browser waiting for a stream that can no longer complete.
  • Decide how your server responds when a browser disconnects, including whether and how to stop upstream work. Validate cancellation behavior with the SDK and server code you deploy; the cited Bedrock examples do not define your HTTP disconnect policy.
  • Do not promise automatic recovery or retry behavior unless your application implements and tests it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check model and tooling support before shipping

Use ConverseStream for models that support Bedrock’s message API, and verify streaming support for the specific model and region rather than inferring it from another model’s example. AWS also notes that the AWS CLI does not support Bedrock streaming operations such as ConverseStream; use an SDK or another supported integration for this streaming workflow. AWS ConverseStream API reference

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.