invokeModelWithBidirectionalStream method

Future<InvokeModelWithBidirectionalStreamResponse> invokeModelWithBidirectionalStream({
  1. required InvokeModelWithBidirectionalStreamInput body,
  2. required String modelId,
})

Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream. The response is returned in a stream that remains open for 8 minutes. A single session can contain multiple prompts and responses from the model. The prompts to the model are provided as audio files and the model's responses are spoken back to the user and transcribed.

It is possible for users to interrupt the model's response with a new prompt, which will halt the response speech. The model will retain contextual awareness of the conversation while pivoting to respond to the new prompt.

May throw AccessDeniedException. May throw InternalServerException. May throw ModelErrorException. May throw ModelNotReadyException. May throw ModelStreamErrorException. May throw ModelTimeoutException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ServiceUnavailableException. May throw ThrottlingException. May throw ValidationException.

Parameter body : The prompt and inference parameters in the format specified in the BidirectionalInputPayloadPart in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to Inference parameters. For more information, see Run inference in the Bedrock User Guide.

Parameter modelId : The model ID or ARN of the model ID to use. Currently, only amazon.nova-sonic-v1:0 is supported.

Implementation

Future<InvokeModelWithBidirectionalStreamResponse>
    invokeModelWithBidirectionalStream({
  required InvokeModelWithBidirectionalStreamInput body,
  required String modelId,
}) async {
  final response = await _protocol.sendRaw(
    payload: body,
    method: 'POST',
    requestUri:
        '/model/${Uri.encodeComponent(modelId)}/invoke-with-bidirectional-stream',
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return InvokeModelWithBidirectionalStreamResponse(
    body: InvokeModelWithBidirectionalStreamOutput.fromJson($json),
  );
}