Course menuAIP-C01

Exams / AIP-C01 / Study guide / Streaming responses (ConverseStream, WebSockets, response streaming)

Streaming responses (ConverseStream, WebSockets, response streaming): AIP-C01 study notes and practice questions

What to know about Streaming responses (ConverseStream, WebSockets, response streaming) for the AIP-C01 exam, from the Implementation and Integration domain (26% of the exam guide), then 1 free question to test it. Part of the AIP-C01 study guide.

Last verified against current AWS documentation ·How we write our questions

What to know for the exam

AIP-C01 scenarios ask how to get tokens to a user quickly, which transport to choose, and how filtering and stop reasons behave while a response is still arriving.

Streaming APIs

ConverseStream returns events as the model generates, using the same request shape as Converse. InvokeModelWithResponseStream streams model-specific bodies. Read the stream incrementally, append text deltas to the screen, and wait for the final message event. Check its stop reason. A max_tokens stop means the answer was cut off, so raise the limit or continue the request. A guardrail_intervened stop means the content was blocked.

Transports to the browser

  • API Gateway WebSocket API keeps a two-way connection. Routes send each user message to Lambda, which streams tokens back through the connection. Use a Lambda REQUEST authorizer on the connect route to check identity. This is the usual choice for a chat UI.
  • Lambda response streaming through a function URL sends partial output over HTTP as it is produced. It fits one-way text from one function to a client.
  • REST API response streaming sends a Lambda or HTTP proxy integration’s output to the client as it is produced, when the integration’s response transfer mode is set to stream. Streamed responses can run past the 29-second integration timeout. It is one-way, so prefer WebSocket when the scenario needs two-way messages.

Guardrails on streams

Guardrails can filter streamed output in two modes. In synchronous mode, the default, each chunk is evaluated before it is sent, so unsafe text never reaches the user, at the cost of some added latency. In asynchronous mode, chunks are sent while evaluation runs in parallel, which lowers latency but allows a brief window where unsafe text may appear before an intervention. Asynchronous mode does not support masking sensitive information. Choose synchronous when the answer must never show blocked content, such as regulated financial or medical advice.

How to choose

Scenario wording Choose
“Show tokens as they arrive in a web chat” ConverseStream over a WebSocket API
“Two-way chat with authentication on connect” API Gateway WebSocket API with Lambda authorizer
“One-way text from a Lambda function to a browser” Lambda response streaming through a function URL
“No unsafe text may ever reach the user” Guardrails synchronous streaming mode
“Lowest time to first token, small risk accepted” Guardrails asynchronous streaming mode
“One request shape across many models” Converse or ConverseStream

Common traps

  • A standard REST call that waits for the full answer when the scenario asks for tokens as they arrive.
  • Treating a streamed answer as complete when the stop reason is max_tokens.
  • Asynchronous guardrail mode for an answer that must never display blocked content.
  • A custom WebSocket server on EC2 when API Gateway WebSocket APIs manage connections for you.
  • Assuming the streamed text is validated after completion. Filtering happens during the stream, so the mode you chose decides what the user sees.

See also: latency and API patterns.

Try the 1 practice question

A telehealth company runs a symptom-checker chat app. A web front end calls a backend Lambda function in the same Region as the model, and the backend calls a foundation model on Amazon Bedrock. Full answers take about 25 seconds, and users are abandoning the chat before the answer appears.

The team wants the first words visible within about one second, with the same model and no increase in total cost per conversation. The answers must still be generated with the same model settings.

The team's developers are comfortable changing the backend and the front end.

Which change meets these requirements?

Choose one answer.

  1. A. Call ConverseStream instead of Converse, and forward each text chunk from the backend to the browser over a streaming connection as soon as it arrives.
  2. B. Keep the Converse call, but split each question into five smaller prompts and send them one after another, so that each shorter answer returns quickly.
  3. C. Switch to batch inference, have the backend write each request to Amazon S3, and have the front end poll the bucket every second for the result file.
  4. D. Call InvokeModel with the largest allowed output length, so that the model returns the full answer in one response with fewer round trips.
Show the answer and explanation

Answer: A

  • A. Right: ConverseStream returns output as the model generates it, so the first words reach the user in about a second. The model, its settings and the token count stay the same, so the cost per conversation does not change. Learn more: ConverseStream API reference (opens in a new tab)
  • B. Wrong: Sequential calls add their latencies together, so the full answer takes at least as long. The first visible text would also come only after the first call finishes, and the answers would change.
  • C. Wrong: Batch inference runs offline and produces results after the job completes, so it cannot show text during a chat. Polling a bucket every second adds delay and request cost.
  • D. Wrong: A single full response still waits for the model to finish, so the user sees nothing for about 25 seconds. Fewer round trips does not change the time to the first word.

Explanation

ConverseStream returns the model's output as it is generated, so the backend can forward each chunk to the browser and the first words appear within about a second. Keeping the same model and settings leaves cost unchanged. Sequential prompts, batch jobs and a single full response each keep the user waiting for the complete answer.

Study

Want more on Streaming responses (ConverseStream, WebSockets, response streaming)? The 5 full-length practice sets have 5 more Streaming responses (ConverseStream, WebSockets, response streaming) questions, 375 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets

Study Streaming responses (ConverseStream, WebSockets, response streaming)

More Implementation and Integration topics