InvokeModelWithResponseStream
Source:
src/AWS/Bedrock/InvokeModelWithResponseStream.ts
Runtime binding for bedrock-runtime:InvokeModelWithResponseStream — the
streaming variant of InvokeModel. The response arrives as an event
Stream of chunk events carrying model-specific payload bytes.
The binding grants the function bedrock:InvokeModelWithResponseStream
(the IAM action streaming operations authorize against) scoped to exactly
the bound models. A model reference may be a foundation-model id, a
cross-region inference profile id (e.g. us.amazon.nova-micro-v1:0), or a
full Bedrock ARN.
Prefer ConverseStream for conversational models — it is
model-agnostic and its events are typed.
Model access is an account entitlement — enable the model in the Bedrock
console (Model access) before invoking, otherwise calls fail with
AccessDeniedException.
Streaming a Model Response
Section titled “Streaming a Model Response”// initconst invokeModelStream = yield* Bedrock.InvokeModelWithResponseStream( "us.amazon.nova-micro-v1:0",);
// runtime — body is the raw Nova messages-v1 payloadconst result = yield* invokeModelStream({ contentType: "application/json", body: JSON.stringify({ messages: [{ role: "user", content: [{ text: "Say hello." }] }], inferenceConfig: { maxTokens: 64 }, }),});const events = yield* Stream.runCollect(result.body);// each chunk's bytes is a model-specific JSON event