Streaming Model Responses to Clients
This lesson covers the Bedrock streaming APIs and how to deliver streams to clients through AWS services, since users judge responsiveness by when the first words appear.
Learning outcomes
After completing this lesson, you will be able to:
- Consume ConverseStream events.
- Deliver streams through WebSocket APIs, Lambda response streaming and other options.
- Address guardrails and other considerations when streaming.
Bedrock streaming APIs
ConverseStream and InvokeModelWithResponseStream return an event stream instead of a single response. ConverseStream emits messageStart, contentBlockStart, contentBlockDelta events containing text fragments (or tool input fragments), contentBlockStop, messageStop with the stop reason, and a metadata event with token usage and latency. Total generation time is unchanged, but time to first token is typically under a second.
r = brt.converse_stream(modelId=model_id, messages=messages, inferenceConfig={"maxTokens": 800})
for event in r["stream"]:
if "contentBlockDelta" in event:
send_to_client(event["contentBlockDelta"]["delta"].get("text", ""))
elif "messageStop" in event:
stop_reason = event["messageStop"]["stopReason"]
elif "metadata" in event:
usage = event["metadata"]["usage"]The following diagram compares when output becomes available with each API.

Delivering streams to clients
An API Gateway WebSocket API keeps a persistent two-way connection. The client sends a message to a route, a Lambda function (invoked asynchronously so it is not limited by the integration timeout) calls ConverseStream and pushes each fragment back with the @connections PostToConnection API. This suits chat with multiple turns and server-initiated messages.
For one-way streaming over HTTP, server-sent events (SSE) or chunked transfer encoding send fragments as the response body is written. Lambda response streaming through a function URL with the RESPONSE_STREAM invoke mode streams from a function, and API Gateway REST APIs support response streaming for Lambda and HTTP integrations. Containers on ECS behind an Application Load Balancer can also stream SSE. AWS AppSync subscriptions push updates to web and mobile clients over WebSockets, which the Amplify AI kit uses for conversation routes.
The following diagram shows a response streamed over a WebSocket API.

Delivering streamed tokens
Streaming considerations
Streaming improves perceived latency but complicates several features. Guardrails must evaluate output that is still being generated. In synchronous mode, each chunk is checked before it is sent, which adds a little latency per chunk but ensures that nothing blocked reaches the user. In asynchronous mode, chunks are sent immediately and checked in parallel, which keeps latency low but means some content may reach the user before an intervention stops the stream.
Clients must also handle partial output, users cancelling a response mid-way and dropped connections that need to be resumed or retried. Structured output such as JSON gains little from being streamed to end users, because it is valid only when complete; it is usually generated without streaming, or streamed only to a component that waits for the end. The following table compares the delivery options.
| Option | Direction | Best for |
|---|---|---|
| API Gateway WebSocket API | Two-way, persistent | Multi-turn chat, server push |
| Lambda function URL response streaming | One-way HTTP stream | Simple token streaming from Lambda |
| API Gateway REST response streaming | One-way HTTP stream | Managed API with auth and throttling |
| SSE from containers behind ALB | One-way HTTP stream | Long-running streaming services |
| AWS AppSync subscriptions | Server to client | Web and mobile apps; Amplify AI kit |
Streaming trade-offs
Slow chat
Users abandon a chat assistant because answers appear only after 12 to 15 seconds, even though the answers are good.
Generation time cannot easily be cut without reducing quality, but perceived latency can. Switching to ConverseStream and delivering fragments over an API Gateway WebSocket API (or Lambda response streaming) shows the first words in under a second while the rest streams in.
Which API Gateway API type supports two-way chat, with responses pushed to the client?
Show answer
A WebSocket API. The backend sends tokens to the client with PostToConnection.
Exam Tips
Remember for the exam
- ConverseStream and InvokeModelWithResponseStream cut time to first token.
- Two-way chat: API Gateway WebSocket API with PostToConnection.
- One-way HTTP streaming: Lambda response streaming, REST API streaming or SSE.
- Streaming guardrails can be synchronous or asynchronous.